Forgive this most basic question, but I couldn't find a direct answer or simple example on stack exchange.
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). It looks like this:
. ├── file1.txt ├── file2.txt ├── file3.txt ├── file.jpg └── test.jpg
Assuming I have
sudo apt-get install zip
I see from
man zip that it allows me to use a file list:
-@ file lists. If a file list is specified as -@ [Not on MacOS], zip takes the list of input files from standard input instead of from the command line. For example,
zip -@ foo
So I created
zip.lst which looks like this:
cat zip.lst file1.txt file2.txt file3.txt file.jpg test.jpg
And now I tried:
zip -@ zip.lst
But it didn't do anything except create a blank line on the console. And I can keep pushing Enter and it just keeps making more blank lines without seemingly executing the command. After some searching, I realized that I needed to terminate input by pressing Ctrl+D
But now I get this error:
zip warning: missing end signature--probably not a zip file (did you zip warning: remember to use binary mode when you transferred it?) zip warning: (if you are trying to read a damaged archive try -F) zip error: Zip file structure invalid (zip.lst)
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:
If a file list is specified as -@...
So 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.
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. This error'd because by default it was trying to create a zip file called
zip.lst. 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. 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 adding: zip.lst (deflated 35%)
Eureka! I can see the zip file was created and my folder now contains this:
. ├── file1.txt ├── file2.txt ├── file3.txt ├── file.jpg ├── files.zip ├── test.jpg └── zip.lst
But wait before we celebrate, let's confirm the contents of the zip file first:
unzip -l files.zip Archive: files.zip Length Date Time Name --------- ---------- ----- ---- 48 2016-05-24 15:30 zip.lst --------- ------- 48 1 file
No! Well, actually that makes sense from standard usage because it just zipped up the one list file I gave it. Finally I tried again with
-@ but got the same result.
What am I doing wrong?
BTW, 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.