Unix:Recursively unzipping .zip file in respective folder

微笑、不失礼 提交于 2019-12-11 01:57:52

问题


I have a number of zipped files say a.zip b.zip etc in a folder. I would like to unzip those and put into a respective directory like a,b.Can you suggest me some unix script for it.?


回答1:


Should not be much hard (untested!):

#!/bin/bash

for zip in *.zip ; do
    dir=${zip%.zip}
    mkdir "$dir"
    unzip -rd "$dir" "$zip"
done



回答2:


You can use unzip utility in unix, as follows:

    #!/bin/bash

    for f in *.zip
    do
        echo "unzipping $f"
        unzip $f -d ${f%.*}
    done

Running this script in directory will unzip all the zip files in it as you wanted, say a.zip, b.zip will be unzipped to directories a and b respectively.




回答3:


This previous post has helped me to achieve this same function; I even created a script to help me remember on my computer:

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

Similarly, you can create an alias to execute a bash function:

$ alias munzip='for f in *.zip; do unzip -d "${f%*.zip}" "$f"; done'

and for a dry-run, to test it beforehand:

$ alias testmunzip='for f in *.zip; do echo unzip -d "${f%*.zip}" "$f"; done'

Just thought it might help to keep this related info on one page, in case someone else is looking for the same effects.



来源:https://stackoverflow.com/questions/11628538/unixrecursively-unzipping-zip-file-in-respective-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!