For example,

zip -r output.zip file1 file2 file3

I need to put the file list "file1 file2 file3" into a text file "input_list.txt", then use the command like:

zip -r output.zip -input input_list.txt

After zip -help, the only relative information it gave is this:

-@ read names from stdin

So I tried:

'cat input_list.txt'>'zip -r -@ output.zip'

But it doesn't work.


Yes you can compress multiples files listed in a list text file
As you understood, the -@ option reads the source files names from stdin
So, simply redirect the list to the zip program stdin

zip output.zip -@ < files.list

note that -r is required if the files.list contains directories

  • Do you know why files.list should put each file in a line, instead of split them with space? – jw_ Sep 16 '19 at 2:09
  • @jw_ filenames can contain spaces – cmak.fr Sep 16 '19 at 7:24
  • But generally it is quoted to escape spaces. For example, rsp files in compilation command line are all single line that contains all the source file names splitted by space. – jw_ Sep 16 '19 at 8:04
  • @jw_ no quotes needed here – cmak.fr Sep 16 '19 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.