Fix ‘Argument List Too Long’ When Zipping Large Files

bash

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}

Best Answer

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

Related Question