# 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
}
我的建议是通过在您的 中添加以下函数来创建自定义命令
.bashrc
:将这些行添加到的底部
~/.bashrc
,然后执行source ~/.bashrc
,您将有一个名为. 下面是它的工作原理:unzipr