首页 > 解决方案 > bash unzip 保留部分目录结构

问题描述

客户从客户的 OUTPUT 目录提交带有目录结构的大型(1.5gigs,>10,000 个文件)zip 文件。
我想将 bash 解压缩到我的 INPUT 目录,同时保留它们的目录结构,但不是整个目录结构。

例如,如果他们的 zip 文件包含以下文件:

/home/base/data/output/able/file1.xml
/home/base/data/output/able/file2.xml
/home/base/data/output/able/file3.xml
/home/base/data/output/baker/file1.xml
/home/base/data/output/baker/file2.xml
/home/base/data/output/baker/file3.xml
/home/base/data/output/charlie/file1.xml
/home/base/data/output/charlie/file2.xml
/home/base/data/output/charlie/file3.xml
(this goes on for thousands of files in about a dozen unique directories)

我想将它们解压缩到我的 INPUT 目录,如下所示:

../input/able/file1.xml
../input/able/file2.xml
../input/able/file3.xml
../input/baker/file1.xml
../input/baker/file2.xml
../input/baker/file3.xml
../input/charlie/file1.xml
../input/charlie/file2.xml
../input/charlie/file3.xml

到目前为止,我尝试过:

unzip BIGFILE.zip   /output/   input   --(*) before and after /output/

able/baker/charlie它确实解压缩了具有等目录结构的所有 xml 文件。
但是,它还解压缩了整个文件结构之前/output

../input/home/base/data/output/able/file1.xml
../input/home/base/data/output/able/file2.xml
../input/home/base/data/output/able/file3.xml
../input/home/base/data/output/baker/file1.xml
../input/home/base/data/output/baker/file2.xml
../input/home/base/data/output/baker/file3.xml
../input/home/base/data/output/charlie/file1.xml
../input/home/base/data/output/charlie/file2.xml
../input/home/base/data/output/charile/file3.xml

可能无法在一个衬里中完成,但还没有找到任何脚本可以在部分目录中读取几千个文件,然后将它们解压缩到特定目录。
有什么想法吗?

标签: bashunzip

解决方案


推荐阅读