l--*_*''' 5 linux bash ubuntu grep sed
我有一个包含zip文件的完整目录结构.我想要:
我尝试过
1.我知道我可以很容易地递归列出文件:
find myLostfile -type f
Run Code Online (Sandbox Code Playgroud)
2.我知道我可以在zip档案中列出文件:
unzip -ls myfilename.zip
Run Code Online (Sandbox Code Playgroud)
如何在zip文件的目录结构中找到特定文件?
您可以使用循环方法省略使用find for single-level(或bash 4中的递归globstar)搜索.zip文件for:
for i in *.zip; do grep -iq "mylostfile" < <( unzip -l $i ) && echo $i; done
Run Code Online (Sandbox Code Playgroud)
在bash 4中进行递归搜索:
shopt -s globstar
for i in **/*.zip; do grep -iq "mylostfile" < <( unzip -l $i ) && echo $i; done
Run Code Online (Sandbox Code Playgroud)
您可以xargs用来处理find的输出,也可以执行以下操作:
find . -type f -name '*zip' -exec sh -c 'unzip -l "{}" | grep -q myLostfile' \; -print
Run Code Online (Sandbox Code Playgroud)
它将开始搜索.匹配的文件,*zip然后unzip -ls在每个文件上运行并搜索文件名。如果找到该文件名,它将打印与之匹配的zip文件的名称。
| 归档时间: |
|
| 查看次数: |
8590 次 |
| 最近记录: |