我有 348 个 zip 文件,我想在其中一个 zip 文件中找到一个文件,unzip -l它不能使用通配符吗?
如何列出所有.zip文件的内容以及grep包含在 zip 中的所有文件的合并列表?
Kon*_*lph 17
zipinfo在这里使用是一个很好的解决方案。但是,一般来说,每当您想将命令应用于文件列表并且该命令不接受文件列表时,您都可以使用for循环:
for file in *.zip; do
unzip -l "$file"
done \
| grep "\.zip\|setup"
Run Code Online (Sandbox Code Playgroud)
如果您要搜索的文件中包含空格,例如: your file,则在 grep 正则表达式中,您需要使用反斜杠来转义每个空格,例如grep "\.zip\|your\ file".
Anw*_*war 12
您可以使用zipinfo. 它包含在默认的 Ubuntu 安装中。查看手册页了解更多信息。
例如,要setup在当前目录的一堆 zip 文件中查找模式,请使用以下命令:
find ./ -iname *zip 2> /dev/null -print0 | xargs -0 zipinfo | grep setup
Run Code Online (Sandbox Code Playgroud)
要列出 zip 存档中的文件,您可以使用以下命令。
unzip -l
Run Code Online (Sandbox Code Playgroud)
要 grep 压缩存档,您应该使用为处理该类型的存档格式而构建的压缩存档实用程序。
对于 zip 档案:
zipgrep --help
usage: zipgrep [egrep_options] pattern zipfile [members...]
Uses unzip and egrep to search the zip members for a string or pattern.
Run Code Online (Sandbox Code Playgroud)
对于 tar 档案:
zgrep --help
Usage: /bin/zgrep [OPTION]... [-e] PATTERN [FILE]...
Look for instances of PATTERN in the input FILEs, using their
uncompressed contents if they are compressed.
OPTIONs are the same as for 'grep'.
Run Code Online (Sandbox Code Playgroud)
还有一些其他工具也可以处理档案。您可以将输出通过管道输入 grep 来做同样的事情。
zcat
zcat my.archive.zip | grep "some text"
Run Code Online (Sandbox Code Playgroud)
或者您可以使用这些工具的搜索功能
zless
zmore
Run Code Online (Sandbox Code Playgroud)