gpt4 book ai didi

linux - 在 zip 文件的递归目录中查找文件

转载 作者:IT王子 更新时间:2023-10-29 01:08:28 25 4
gpt4 key购买 nike

我有一个包含 zip 文件的完整目录结构。我愿意:

  1. 递归遍历整个目录结构,获取所有 zip 文件
  2. 我想在其中一个 zip 文件中找到一个特定文件“*myLostFile.ext”。

我尝试过的
1. 我知道我可以很容易地递归列出文件:

find myLostfile -type f

2。我知道我可以列出 zip 存档中的文件:

unzip -ls myfilename.zip

如何在 zip 文件的目录结构中查找特定文件?

最佳答案

您可以使用 for 省略对 .zip 文件的单级查找(或在 bash 4 中使用 globstar 递归)搜索循环方法:

for i in *.zip; do grep -iq "mylostfile" < <( unzip -l $i ) && echo $i; done

对于 bash 4 中的递归搜索:

shopt -s globstar
for i in **/*.zip; do grep -iq "mylostfile" < <( unzip -l $i ) && echo $i; done

关于linux - 在 zip 文件的递归目录中查找文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30127764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com