我有一个ZIP文件目录(在Windows机器上创建的)。我可以手动解压缩他们使用unzip文件名,但我怎么能解压缩所有的ZIP文件在当前文件夹通过shell?

使用Ubuntu Linux服务器。


当前回答

解压缩所有。zip文件,并将内容存储在与。zip文件同名的新文件夹中:

find . -name '*.zip' -exec sh -c 'unzip -d "${1%.*}" "$1"' _ {} \;

这是@phatmanace的回答的延伸,并解决了@RishabhAgrahari的评论:

这将在当前目录中提取所有的zip文件,如果我想在各自的子文件夹中提取zip文件(目前在子文件夹中)怎么办?

其他回答

要解压缩目录中的所有文件,只需在终端中键入以下命令:

unzip '*.zip'

如果你所说的“当前目录”是指zip文件所在的目录,那么我将使用以下命令:

find . -name '*.zip' -execdir unzip {} \; 

节选自find的手册页

-execdir command ;
-execdir command {} +

Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find. This a much more secure method for invoking commands, as it avoids race conditions during resolution of the paths to the matched files. As with the -exec option, the '+' form of -execdir will build a command line to process more than one matched file, but any given invocation of command will only list files that exist in the same subdirectory. If you use this option, you must ensure that your $PATH environment variable does not reference the current directory; otherwise, an attacker can run any commands they like by leaving an appropriately-named file in a directory in which you will run -execdir.

for i in `ls *.zip`; do unzip $i; done
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文件夹中。

用这个:

for file in `ls *.Zip`; do
unzip ${file} -d ${unzip_dir_loc}
done