1/22/2024 0 Comments Ls grep add all jpg file to txt| zip files.Linux/Unix FAQ: Can you share some Linux find command examples? Or just files beginning with "file" ls | grep file. It would be better to get a list from ls and pipe that to zip: ls | zip files.zipįabulous! Now let's create filters with the awesome power of grep to just zip up the jpg's for instance: ls | grep. SWEET! But who wants to create a onetime-use list anyway? That's an awful round-about way of solving this particular scenario. for each file is certainly a good sign, but we've had our hopes up before, so let's just confirm: unzip -l files.zip Understanding this, we are now armed with a variety of ways to accomplish the goal.įirstly using the file list we created, we can read out the list with cat and redirect the output with a pipe as standard input to zip: cat zip.lst | zip files.zip The list of files is omitted in the example because it's using the switch, which demonstrates it "takes the list of input files from standard input instead of from the command line".It's understandable that someone might be misled into thinking that foo referred to the file list, but it's actually intended to represent the name of the output zip file.The manual isn't referring to a literal list as in a file, but rather literally to listing the files out on the console.I'm glad it's OK to answer my own question because I wanted to chronicle my turmoil in hopes that others following behind in my trail of tears could be spared by searching some key words.Įventually, I discovered the right answer, but it was posted to the wrong question. Or you could skip the list and just glob zip files.zip *.txt *.jpg Use file < redirection zip files.zip < zip.lst Finally I tried again with but got the same result.īTW, I know I can use the GUI and do it with my mouse, but I need to script this, and in general I'm faster on the CLI when I know what I'm doing. No! Well, actually that makes sense from standard usage because it just zipped up the one list file I gave it. īut wait before we celebrate, let's confirm the contents of the zip file first: unzip -l files.zip And since the list obviously isn't a zip file, we get the invalid file structure error, and now it's clear why it said "probably not a zip file." So then I tried: zip files.zip zip.lstĮureka! I can see the zip file was created and my folder now contains this. But since that's the name of my list, one might think that it would simply overwrite it, but no, it was in fact trying to update it. This error'd because by default it was trying to create a zip file called zip.lst. Luckily, I found a comment on an answer to a nearly unrelated question that led me to realize that I needed to explicitly name the zip file. If a file list is specified as I try it without and that at least processes it right away without having to press Ctrl+ D but I'm left with the same error. What!? How is my simple list not a "valid file structure"? Back to the manual for more information, and I take a closer look at: Zip error: Zip file structure invalid (zip.lst) Zip warning: (if you are trying to read a damaged archive try -F) Zip warning: remember to use binary mode when you transferred it?) After some searching, I realized that I needed to terminate input by pressing Ctrl+ Dīut now I get this error: zip warning: missing end signature-probably not a zip file (did you And I can keep pushing Enter and it just keeps making more blank lines without seemingly executing the command. So I created zip.lst which looks like this: cat zip.lstīut it didn't do anything except create a blank line on the console. If a file list is specified as, zip takes the list of input filesįrom standard input instead of from the command line. I see from man zip that it allows me to use a file file lists. Īssuming I have zip installed: sudo apt-get install zip Let's say I have a folder of files that I would like to compress into one zip file that I can share with my terrible Windows friends (otherwise I'd just use tar and be done with it). Forgive this most basic question, but I couldn't find a direct answer or simple example on stack exchange.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |