For example my folder name is Test.zip
Test.zip includes various zip folders like te1.zip, te2.zip , te3.zip even te1.zip include various zip folders.
So i need to unzip in linux at once.
Could you please let me know how to do this.
For example my folder name is Test.zip
Test.zip includes various zip folders like te1.zip, te2.zip , te3.zip even te1.zip include various zip folders.
So i need to unzip in linux at once.
Could you please let me know how to do this.
Short script something like this should do the job (please note, that you need to have a backup of your original file, as the script needs to remove it in order to process everything recursively).
while [ "$(find . -type f -name '*.zip' | wc -l)" -gt 0 ];
do
find -type f -name '*.zip' -exec mkdir '{}'_dir \; \
-exec unzip -d '{}'_dir -- '{}' \; \
-exec rm -- '{}' \;
done
On some systems it might be possible to use -delete instead of -exec rm -- '{}' \;.
This is a great candidate for a recursive script.
Save this as a script (e.g. my_unzip.sh) Will not work if you paste to command line as-is:
#!/usr/bin/env bash
: ${1:?Please supply a file} # ${1} is the zip being fed to the script -- a little user-friendliness never went amiss
DIR="${1%.zip}" # this is where the current zip will be unzipped
mkdir -p "${DIR}" || exit 1 # might fail if it's a file already
unzip -n -d "${DIR}" "${1}" # unzip current zip to target directory
find "${DIR}" -type f -name '*.zip' -print0 | xargs -0 -n1 "${0}" # scan the target directory for more zips and recursively call this script (via ${0})
Make it executable
chmod +x my_unzip.sh
And run it with your zip file as a parameter:
my_unzip.sh /some/path/yourfile.zip
Preserves your original file, comments inline to explain what's happening.
Cowardly, in that it never tries to overwrite that already exists. This behaviour can be changed by updating unzip command to remove -n, to get prompted, or change it to -o to force overwriting.