My suggestion is to create a custom command by adding the following function in your .bashrc:
# Recursive UNZIP
# - covers only the firs level of the recursion;
# - works only with one input file
unzipr () {
# Get the users input
TARGET_ZIP_FILE="${1}"
# Get the list of sub archive zip files
ZIP_LIST="$(unzip -l "$TARGET_ZIP_FILE" | awk 'NR > 1 && $NF ~ /zip/ { print $NF }')"
# Output the list of sub archive zip files
if [ ! -z "${ZIP_LIST}" ]; then
echo 'List of Sub Archives:'
for ZIP in $ZIP_LIST; do echo -e " - $ZIP"; done; echo
else
echo "Sub Archives Not Found."
fi
# Extract and unzip the files
for ZIP in $ZIP_LIST; do
# Ask the user for his/her preferences
echo -n "Do you want to extract and unzip \"$ZIP\" [Y|n]: "
read preference
# Extract the file according to the users preferences
if [ -z "${preference}" ] || [[ "${preference}" =~ ^(y|Y).* ]]; then
unzip "$TARGET_ZIP_FILE" "$ZIP"
unzip "$ZIP"
rm "$ZIP"
echo
fi
done
}
Add these lines to the bottom of ~/.bashrc, then do source ~/.bashrc and you will have a command called unzipr. Here is how it works:
Or if the archive itself contains a folder example which you want to extract to the current directory, but with a different name, you must manually rename it to examplefold afterwards:
Best Answer
My suggestion is to create a custom command by adding the following function in your
.bashrc
:Add these lines to the bottom of
~/.bashrc
, then dosource ~/.bashrc
and you will have a command calledunzipr
. Here is how it works: