Zip Archive With Limited Number of Files
You can use GNU parallel to do that as it can limit the number of elements to a job as well as provide a job number (for a unique zip archive name):
$ touch $(seq 20)
$ find . ! -name "*.zip" -type f -print0 | parallel -0 -N 5 zip arch{#} {}
adding: 1 (stored 0%)
adding: 10 (stored 0%)
adding: 11 (stored 0%)
adding: 12 (stored 0%)
adding: 13 (stored 0%)
adding: 14 (stored 0%)
adding: 15 (stored 0%)
adding: 16 (stored 0%)
adding: 17 (stored 0%)
adding: 18 (stored 0%)
adding: 19 (stored 0%)
adding: 2 (stored 0%)
adding: 20 (stored 0%)
adding: 3 (stored 0%)
adding: 4 (stored 0%)
adding: 5 (stored 0%)
adding: 6 (stored 0%)
adding: 7 (stored 0%)
adding: 8 (stored 0%)
adding: 9 (stored 0%)
$ ls
1 11 13 15 17 19 20 4 6 8 arch1.zip arch3.zip
10 12 14 16 18 2 3 5 7 9 arch2.zip arch4.zip
The option -N 5
limits the number of files to 5 per archive and is presented to zip
in place of {}
The {#}
(verbatim, not to be replaced by you during the invocation), is replaced by the job number, resulting in arch1.zip
, arch2.zip
etc.
The -print0
option to find
and -0
option to parallel
in tandem make sure that filenames with special characters are correctly handled.