Trying all morning, but can't figure it out. Maybe you know.
I'd like to compress many directories into zip files, so that each directory is its own zip file. And if there are more than 1000 files in that folder, then make them into multiple zip files with 1000 files per piece.
When archiving, is it possible to set the maximum number of files and split them accordingly. I'm trying to compress many files into manageable chunks, so that each could be worked with independently.
Solutions I now have:
# make each folder into its own archive
for i in */; do zip -r "${i%/}.zip" "$i"; done
# make archives of 500 files per piece
find . ! -name '*.zip' -type f | xargs -n 500 | awk '{system("zip myarch"NR".zip "$0)}'
Sources: Zip Archive With Limited Number of Files and command to zip multiple directories into individual zip files
What I'm missing is how to make it so that the files from the find stay limited to that subdirectory that they were found in. If there are 500 files in there, it should put only these 500 files in that directory, if there are 2,400 files in there, it should make 3 archives, first two 1,000 files a piece, and last only 400 files.
Something along these lines should work, I think. But something is still wrong.
#for all subfolders, find all files, take them in 500 name chunks, and zip them up into numbered archives.
for i in */; do find "${i%/}" -type f | xargs -n 500| awk '{system("zip ${i%/}"NR".zip "$0)}'; done
Help appreciated, thanks!
Update. This bash script should work I'd think, but I don't understand why the zip files still go acro
#!/bin/bash
for i in */; do
printf $i
find "${i%/}" -type f | xargs -n 500 | awk '{system("zip marych${i%/}"NR".zip "$0)}';
Update2:
Fixed it. Some quotation mark issues were the problem:
for i in */; do find "${i%/}" -type f| xargs -n 500 | awk '{system("zip '${i%/}'"NR".zip "$0)}'; done
done