Core solution
Using bash
, you can just loop over the zip files instead of using a glob. This allows to prevent the Argument list too long error for rm, cp, mv commands and continue even if one file fail.
dir="/path/to/zip-dir"
cd "$dir"
for zf in *.zip
do
unzip "$zf"
done
Testing before doing
You can add an extra test, in the for
loop, to check if the file exists and has a size greater than zero before unzipping:
if [[ -s "$zf" ]];
then
unzip "$zf" # greater exist & size>0
else
printf "file doesn't exists or null-size: %s\n" "$zf"
fi
a shorter version will be: [[ -s "$zf" ]] && unzip "$zf"
(unzip only if exists and >0).
Reference
- see
man bash
(look for-s
orCONDITIONAL EXPRESSIONS
section). - Question Argument list too long error for rm, cp, mv commands