25

I need to compress 80.000 files into multiple zip files. This is the command I use:

zip -s 200M photos_test/*

However I get the following error:

-bash: /usr/bin/zip: Argument list too long

What can I do to solve the issue, beside manually splitting the folder files ?

thanks

shgnInc
  • 445
aneuryzm
  • 2,185

4 Answers4

19

If you want the whole directory, you could simply use the -r switch:

zip -r -s 200M myzip photos_test

That will include all subdirectories of photos_test though.

Mat
  • 8,353
15

The problem seems to be the expansion of the "*". Use folder name or ".":

If you want to include the root folder within the zip:

zip -r my.zip folder_with_80k_files

If you don´t want to include the root folder inside the zip:

cd folder_with_80k_files
zip -r my.zip .
stoffen
  • 251
6
find photos_test/ -mindepth 1 -maxdepth 1 | zip -@ -s 200M
4

ls photos_test | zip -s 200M -@ photos

  • -@ will cause zip to read a list of files from stdin
  • | will pipe an output of ls into the input of zip command

man zip:

USE
⋮
   -@ 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.

Under Unix, this option can be used to powerful effect in conjunction with the find (1) command. For example, to archive all the C source files in the current directory and its subdirectories:

      find . -name "*.[ch]" -print | zip source -@

(note that the pattern must be quoted to keep the shell from expanding it). ⋮

Mr. Tao
  • 528