I have a script that zip files from a folder. I want to make sure that the zipped file is not more than 10 MB. If the size is more than 10MB, it should create another ZIP file.
Is there any command (or other method )that can be used for this?
bashgziplinux
I have a script that zip files from a folder. I want to make sure that the zipped file is not more than 10 MB. If the size is more than 10MB, it should create another ZIP file.
Is there any command (or other method )that can be used for this?
Best Answer
You can use the "split archive" functionality of "zip" itself using the "--split-size" option.
From "zip" manpage ("
man zip
"):So, to create a split zip archive, you could do the following (the "
-r
" is the "recursive" switch to include subdirectories of the directory):$ zip -r -s 10m archive.zip directory/
To unzip the file, the "
zip
" manpage explains that you should use the "-s 0`" switch:So, you first "unsplit" the ZIP file using the "-s 0" switch:
$ zip -s 0 archive.zip --out unsplit.zip
... and then you unzip the unsplit file:
$ unzip unsplit.zip