我有一个ZIP文件目录(在Windows机器上创建的)。我可以手动解压缩他们使用unzip文件名,但我怎么能解压缩所有的ZIP文件在当前文件夹通过shell?
使用Ubuntu Linux服务器。
我有一个ZIP文件目录(在Windows机器上创建的)。我可以手动解压缩他们使用unzip文件名,但我怎么能解压缩所有的ZIP文件在当前文件夹通过shell?
使用Ubuntu Linux服务器。
当前回答
这是Pedro Lobito回答的一个变体,使用如何递归地遍历目录以删除具有某些扩展名的文件:
shopt -s globstar
root_directory="."
for zip_file_name in **/*.{zip,sublime\-package}; do
directory_name=`echo $zip_file_name | sed 's/\.\(zip\|sublime\-package\)$//'`
printf "Unpacking zip file \`$root_directory/$zip_file_name\`...\n"
if [ -f "$root_directory/$zip_file_name" ]; then
mkdir -p "$root_directory/$directory_name"
unzip -o -q "$root_directory/$zip_file_name" -d "$directory_name"
# Some files have the executable flag and were not being deleted because of it.
# chmod -x "$root_directory/$zip_file_name"
# rm -f "$root_directory/$zip_file_name"
fi
done
其他回答
解压缩所有。zip文件,并将内容存储在与。zip文件同名的新文件夹中:
find . -name '*.zip' -exec sh -c 'unzip -d "${1%.*}" "$1"' _ {} \;
这是@phatmanace的回答的延伸,并解决了@RishabhAgrahari的评论:
这将在当前目录中提取所有的zip文件,如果我想在各自的子文件夹中提取zip文件(目前在子文件夹中)怎么办?
这在bash中工作,根据这个链接:
解压缩\ * . zip
对于'ls *.zip'文件;解压缩"${file}" -d "${file:0:-4}";完成
要解压缩目录中的所有文件,只需在终端中键入以下命令:
unzip '*.zip'
下面是一个没有使用ls的一行程序,它为文件创建了带有zip名称的文件夹。它适用于当前目录中的任何zip。
for z in *.zip; do unzip "$z" -d "${z%".zip"}"; done
你可以把它添加到你的。bashrc
alias unzip_all='for z in *.zip; do unzip "$z" -d "${z%".zip"}"; done'
灵感源自:
方法#2:在https://www.cyberciti.biz/faq/linux-unix-shell-unzipping-many-zip-files/中使用Shell For循环(长版本)从Linux命令行解压多个文件