![如何从终端进行递归解压缩?](https://linux22.com/image/1154297/%E5%A6%82%E4%BD%95%E4%BB%8E%E7%BB%88%E7%AB%AF%E8%BF%9B%E8%A1%8C%E9%80%92%E5%BD%92%E8%A7%A3%E5%8E%8B%E7%BC%A9%EF%BC%9F.png)
在 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