为zip文件夹创建并提取它 [英] create folder for zip file and extract to it

查看:189
本文介绍了为zip文件夹创建并提取它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我选择一个zip文件并右键单击提取这里用ZIP文件名创建zip文件的全部内容的文件夹被提取到它。

If I choose a zip file and right click "extract here" a folder with the zip filename is created and the entire content of the zip file is extracted into it.

不过,我想通过shell转换多个zip文件。
但是,当我做

However, I would like to convert several zip files via shell. But when I do

unzip filename.zip

文件夹文件名未创建,但所有的文件解压缩到当前目录。

the folder "filename" is not created but all the files are extracted into the current directory.

我已经看过了参数,但没有这样的参数。
我也试过

I have looked at the parameters but there is no such parameter. I also tried

for zipfile in \*.zip; do mkdir $zipfile; unzip $zipfile -d $zipfile/; done

不过的2 $ zip文件和4 $ zip文件的 .zip文件扩展必须与SED被删除。
如果我做

but the .zip extension of the 2. $zipfile and 4. $zipfile have to be removed with sed. If I do

for zipfile in \*.zip; do mkdir sed 's/\.zip//i' $zipfile; unzip $zipfile -d sed 's/\.zip//i' $zipfile/; done 

这是行不通的。

我如何更换的 .zip文件扩展 $压缩文件是否正确?

How do I replace the .zip extension of $zipfile properly?

难道还有比shell脚本更简单的方法?

Is there an easier way than a shell script?

推荐答案

解压file.zip -d XXX 将文件解压缩到目录XXX,XXX和是否会被创建它不存在。您可以检查手册页了解详情。

unzip file.zip -d xxx will extract files to directory xxx, and xxx will be created if it is not there. You can check the man page for details.

下的awk行应该做的工作:

The awk line below should do the job:

ls *.zip|awk -F'.zip' '{print "unzip "$0" -d "$1}'|sh

看到测试下方,

注意我删除 | SH 末,因为我的拉链是假的档案;我只是想在这里显示生成的命令行。

note that I removed |sh at the end, since my zips are fake archives; I just want to show the generated command line here.

kent$  ls -l
total 0
-rw-r--r-- 1 kent kent 0 Nov 12 23:10 001.zip
-rw-r--r-- 1 kent kent 0 Nov 12 23:10 002.zip
-rw-r--r-- 1 kent kent 0 Nov 12 23:10 003.zip
-rw-r--r-- 1 kent kent 0 Nov 12 23:10 004.zip
-rw-r--r-- 1 kent kent 0 Nov 12 23:10 005.zip
-rw-r--r-- 1 kent kent 0 Nov 12 23:10 006.zip
-rw-r--r-- 1 kent kent 0 Nov 12 23:10 007.zip

kent$  ls *.zip|awk -F'.zip' '{print "unzip "$0" -d "$1}'
unzip 001.zip -d 001
unzip 002.zip -d 002
unzip 003.zip -d 003
unzip 004.zip -d 004
unzip 005.zip -d 005
unzip 006.zip -d 006
unzip 007.zip -d 007

这篇关于为zip文件夹创建并提取它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆