如何从 Unix 命令行递归解压缩目录及其子目录中的档案? [英] How do you recursively unzip archives in a directory and its subdirectories from the Unix command-line?

查看:44
本文介绍了如何从 Unix 命令行递归解压缩目录及其子目录中的档案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

unzip 命令没有递归解压缩档案的选项.

如果我有以下目录结构和档案:

<前>/妈妈/爱心.zip/坏血病/海狗.zip/坏血病/治愈/酸橙.zip

我想将所有档案解压缩到与每个档案同名的目录中:

<前>/妈妈/爱心/1.txt/妈妈/爱心.zip/坏血病/海狗/2.txt/坏血病/海狗.zip/坏血病/治愈/酸橙/3.txt/坏血病/治愈/酸橙.zip

我会发出什么命令?

重要的是,这不会因包含空格的文件名而窒息.

解决方案

如果你想把文件解压到相应的文件夹你可以试试这个

查找.-name "*.zip" |读取文件名时;do unzip -o -d "`dirname "$filename"`" "$filename";完毕;

适用于可以处理高 I/O 的系统的多处理版本:

查找.-name "*.zip" |xargs -P 5 -I fileName sh -c 'unzip -o -d "$(dirname "fileName")/$(basename -s .zip "fileName")" "fileName"'

The unzip command doesn't have an option for recursively unzipping archives.

If I have the following directory structure and archives:

/Mother/Loving.zip
/Scurvy/Sea Dogs.zip
/Scurvy/Cures/Limes.zip

And I want to unzip all of the archives into directories with the same name as each archive:

/Mother/Loving/1.txt
/Mother/Loving.zip
/Scurvy/Sea Dogs/2.txt
/Scurvy/Sea Dogs.zip
/Scurvy/Cures/Limes/3.txt
/Scurvy/Cures/Limes.zip

What command or commands would I issue?

It's important that this doesn't choke on filenames that have spaces in them.

解决方案

If you want to extract the files to the respective folder you can try this

find . -name "*.zip" | while read filename; do unzip -o -d "`dirname "$filename"`" "$filename"; done;

A multi-processed version for systems that can handle high I/O:

find . -name "*.zip" | xargs -P 5 -I fileName sh -c 'unzip -o -d "$(dirname "fileName")/$(basename -s .zip "fileName")" "fileName"'

这篇关于如何从 Unix 命令行递归解压缩目录及其子目录中的档案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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