在 zip 文件中,我还有一个 zip 文件
我想要一个命令来一次性提取所有内容。
答案1
我的建议是通过在您的中添加以下函数来创建自定义命令.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
}
将这些行添加到 底部~/.bashrc
,然后执行source ~/.bashrc
,您将得到一个名为 的命令。它的工作原理如下:unzipr