我有一个 ZIP 文件的目录 (在 Windows 机器上创建)。我可以使用unzip filename
手动解压缩它们,但是如何通过 shell 解压缩当前文件夹中的所有 ZIP 文件?
使用 Ubuntu Linux Server。

这在 bash 中工作,根据this link:
解压缩\ *.zip
只是把一些报价来逃避通配符:
unzip "*.zip"

下面的 shell 脚本将当前目录中的所有 zip 文件提取到具有 zip 文件文件名的新目录中,即:
以下文件:
myfile1.zip
myfile2.zip
将提取到:
./myfile1/files...
./myfile2/files...
Shell 脚本:
#!/bin/sh
for zip in *.zip
do
dirname=`echo $zip | sed 's/\.zip$//'`
if mkdir "$dirname"
then
if cd "$dirname"
then
unzip ../"$zip"
cd ..
# rm -f $zip # Uncomment to delete the original zip file
else
echo "Could not unpack $zip - cd failed"
fi
else
echo "Could not unpack $zip - mkdir failed"
fi
done
Source Gist
用法:
cd /dir/with/zips
wget -O - https://www.toptal.com/developers/hastebin/suveuxo.bash | bash

解压缩 *.zip,或者如果它们在子文件夹中,则类似
find . -name "*.zip" -exec unzip {} \;
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(29条)