4

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=()       

fixed=5
for i in `seq 10 1 200`; do
    for j in `seq $((i+fixed)) 1 200`; do
        arr+=("${i}_${j}.xxx")
    done
done

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

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... – Henno Brandsma Mar 24 at 13:51
6

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

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.