I'm trying to zip a certain large number of files by creating an array of them. Then I tried to run the zip command but met with "Argument list too long" error.

declare -a arr=()       

for i in `seq 10 1 200`; do
    for j in `seq $((i+fixed)) 1 200`; do

new_arr=$(printf ",%s" "${arr[@]}")

zip all_data.zip {$new_arr}
  • As an alternative: you can create an empty zip file at the beginning and add a file to that zip file, instead of making an array first and adding them all at once. Might save you a loop, unless you have need for the array for other reasons... Mar 24 '19 at 13:51

extract from man zip ( linux version )

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

example from the same man page

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

So steps will be :

  1. build a list off all files to be archive , format must one file name by line

  2. run zip command

    cat BIG_FILENAME_LIST.txt | zip thebigziparchive -@

  • I need the same functionality, but for the "ignore" list. Is there a way to do this with the "-x" option? Dec 11 '19 at 23:27

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.