рüф*_*ффп 57 command-line zip filenames
在我的 bash 命令行中,当我使用时,unzip -l test.zip
我得到如下输出:
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
810000 05-07-2014 15:09 file1.txt
810000 05-07-2014 15:09 file2.txt
810000 05-07-2014 15:09 file3.txt
--------- -------
2430000 3 files
Run Code Online (Sandbox Code Playgroud)
但我只对包含文件详细信息的行感兴趣。
我尝试使用 grep 进行过滤,如下所示:
unzip -l test.zip | grep -v Length | grep -v "\-\-\-\-" | g -v Archive | grep -v " files"
但是它很长并且容易出错(例如,此列表中的文件名 Archive 将被删除)
unzip -l 是否还有其他选项(我检查了 unzip 手册页但没有找到任何选项)或其他工具来执行此操作?
对我来说重要的是不要真正解压缩存档,而只是查看里面有什么文件。
Sté*_*las 78
zipinfo -1 file.zip
Run Code Online (Sandbox Code Playgroud)
或者:
unzip -Z1 file.zip
Run Code Online (Sandbox Code Playgroud)
将只列出文件。
如果您仍然需要每个文件名的额外信息,您可以执行以下操作:
unzip -Zl file.zip | sed '1,2d;$d'
Run Code Online (Sandbox Code Playgroud)
或者:
unzip -l file.zip | sed '1,3d;$d' | sed '$d'
Run Code Online (Sandbox Code Playgroud)
或者(假设 GNU head
):
unzip -l file.zip | tail -n +4 | head -n -2
Run Code Online (Sandbox Code Playgroud)
或者你可以使用libarchive
's bsdtar
:
$ bsdtar tf test.zip
file1.txt
file2.txt
file3.txt
$ bsdtar tvf test.zip
-rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file1.txt
-rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file2.txt
-rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file3.txt
$ bsdtar tvvf test.zip
-rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file1.txt
-rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file2.txt
-rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file3.txt
Archive Format: ZIP 2.0 (deflation), Compression: none
Run Code Online (Sandbox Code Playgroud)