我有一个ZIP文件目录(在Windows机器上创建的)。我可以手动解压缩他们使用unzip文件名,但我怎么能解压缩所有的ZIP文件在当前文件夹通过shell?
使用Ubuntu Linux服务器。
我有一个ZIP文件目录(在Windows机器上创建的)。我可以手动解压缩他们使用unzip文件名,但我怎么能解压缩所有的ZIP文件在当前文件夹通过shell?
使用Ubuntu Linux服务器。
当前回答
对于'ls *.zip'文件;解压缩"${file}" -d "${file:0:-4}";完成
其他回答
unpack -e *.zip,安装atool。 具有智能地处理错误的优点,并且总是解包到子目录中,除非zip只包含一个文件。因此,不存在使用大量文件污染当前目录的危险,而在没有目录结构的zip文件上进行unzip则存在这种危险。
Use
sudo apt-get install unzip
unzip file.zip -d path_to_destination_folder
在Linux中解压缩一个文件夹
下面是一个没有使用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命令行解压多个文件
for i in *.zip; do
newdir="${i:0:-4}" && mkdir "$newdir"
unzip "$i" -d "$newdir"
done
这将把所有zip归档解压缩到以zip归档的文件名命名的新文件夹中。
a.zip b.zip c.zip将分别解压缩到b. c文件夹中。
下面的shell脚本将当前目录中的所有zip文件提取到新的dirs中,并以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
源要点
用法:
cd /dir/with/zips
wget -O - https://www.toptal.com/developers/hastebin/suvefuxuxo.bash | bash