Linux 解压缩目录中的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2374772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unzip All Files In A Directory
提问by Lennie De Villiers
I have a directory of ZIP files (created on a Windows machine). I can manually unzip them using unzip filename
, but how can I unzip all the ZIP files in the current folder via the shell?
我有一个 ZIP 文件目录(在 Windows 机器上创建)。我可以使用 手动解压缩它们unzip filename
,但是如何通过 shell 解压缩当前文件夹中的所有 ZIP 文件?
Using Ubuntu Linux Server.
使用 Ubuntu Linux 服务器。
回答by Dominik
for i in `ls *.zip`; do unzip $i; done
回答by phatmanace
unzip *.zip, or if they are in subfolders, then something like
解压缩 *.zip,或者如果它们在子文件夹中,则类似于
find . -name "*.zip" -exec unzip {} \;
回答by ghostdog74
Just put in some quotes to escape the wildcard:
只需输入一些引号即可转义通配符:
unzip "*.zip"
回答by kampu
aunpack -e *.zip
, with atool
installed.
Has the advantage that it deals intelligently with errors, and always unpacks into subdirectories unless the zip contains only one file . Thus, there is no danger of polluting the current directory with masses of files, as there is with unzip
on a zip with no directory structure.
aunpack -e *.zip
,与atool
安装。优点是它可以智能地处理错误,并且总是解压缩到子目录中,除非 zip 只包含一个文件。因此,不会有大量文件污染当前目录的危险,就像unzip
没有目录结构的 zip文件一样。
回答by Ankit Malhotra
Use this:
用这个:
for file in `ls *.Zip`; do
unzip ${file} -d ${unzip_dir_loc}
done
回答by CONvid19
The following bash script extracts all zip files in the current directory into new dirs with the filename of the zip file.
以下 bash 脚本使用 zip 文件的文件名将当前目录中的所有 zip 文件提取到新目录中。
ex, the following files:
例如,以下文件:
myfile1.zip
myfile2.zip
will be extracted to:
将被提取到:
./myfile1/files...
./myfile2/files...
Shell script:
外壳脚本:
#!/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
回答by Mohit Singh
Use
用
sudo apt-get install unzip
unzip file.zip -d path_to_destination_folder
to unzip a folder in linux
在linux中解压文件夹
回答by Jahid
for i in *.zip; do
newdir="${i:0:-4}" && mkdir "$newdir"
unzip "$i" -d "$newdir"
done
This will unzip all the zip archives into new folders named with the filenames of the zip archives.
这会将所有 zip 存档解压缩到以 zip 存档的文件名命名的新文件夹中。
a.zip
b.zip
c.zip
will be unzipped into a
b
c
folders respectively.
a.zip
b.zip
c.zip
将分别解压到a
b
c
文件夹中。
回答by Anurag Dalia
for file in 'ls *.zip'; do unzip "${file}" -d "${file:0:-4}"; done
for file in 'ls *.zip'; do unzip "${file}" -d "${file:0:-4}"; done