8

I created a file with diff files diff-files.txt it has 6000+ file paths in it. Now I want want to create a zip based on those files.

I know I can zip multiple files with:

zip diffedfiles.zip file1 folder1 -r

But that won't work with 6000+ files. Is there a way to zip it based on the content of diff-files.txt?

zip diffedfiles.zip {diff-files.txt} -r

Something like this?

janw
  • 262
  • 1
  • 3
  • 10

3 Answers3

16

On Linux you can use the -@ option:

-@ 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

will store the files listed one per line on stdin in foo.zip.

So in your case you should be able to do:

cat diff-files.txt | zip -@ diffedfiles.zip
unlink
  • 690
  • 7
  • 12
  • Ancient post but this exact method works like a charm in windows (even in 2020) with the Info-Zip console tool: ftp://ftp.info-zip.org/pub/infozip/win32/zip300xn-x64.zip – ClownCoder Jul 03 '20 at 22:42
3

Got it:

zip diffedfiles.zip $(cat diff-files.txt) -r
janw
  • 262
  • 1
  • 3
  • 10
2

There are two methods that work on all platforms:

1.

zip output.zip -r . -i@filelist.txt

2.

zip -@ - < filelist.txt > output.zip

These methods are not affected by command-line length limits.

vsz
  • 21
  • 4