How do I zip up multiple files on command line?
Use file <
redirection
zip files.zip -@ < zip.lst
Or you could skip the list and just glob
zip files.zip *.txt *.jpg
thanks steeldriver
Historical Answer
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.
Eventually, I discovered the right answer, but it was posted to the wrong question.
A couple points of clarity:
- The manual isn't referring to a literal list as in a file, but rather literally to listing the files out on the console.
- 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 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"
Understanding this, we are now armed with a variety of ways to accomplish the goal.
Firstly 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
adding: file1.txt (stored 0%)
adding: file2.txt (stored 0%)
adding: file3.txt (stored 0%)
adding: file.jpg (stored 0%)
adding: test.jpg (stored 0%)
Seeing that adding: ...
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
Archive: files.zip
Length Date Time Name
--------- ---------- ----- ----
0 2016-05-24 14:54 file1.txt
0 2016-05-24 14:54 file2.txt
0 2016-05-24 14:54 file3.txt
0 2016-05-24 15:00 file.jpg
0 2016-05-24 14:59 test.jpg
--------- -------
0 5 files
SWEET! But who wants to create a onetime-use list anyway? That's an awful round-about way of solving this particular scenario. It would be better to get a list from ls
and pipe that to zip:
ls | zip -@ files.zip
adding: file1.txt (stored 0%)
adding: file2.txt (stored 0%)
adding: file3.txt (stored 0%)
adding: file.jpg (stored 0%)
adding: test.jpg (stored 0%)
Fabulous! Now let's create filters with the awesome power of grep
to just zip up the jpg's for instance:
ls | grep .jpg | zip -@ images.zip
adding: file.jpg (stored 0%)
adding: test.jpg (stored 0%)
Or just files beginning with "file"
ls | grep file. | zip -@ files.zip
adding: file1.txt (stored 0%)
adding: file2.txt (stored 0%)
adding: file3.txt (stored 0%)
adding: file.jpg (stored 0%)
the most simple command with max compression level
zip -9 -r filename.zip /path/to/dir singlefile.jpg