[英]How can I list the files in a zip archive without decompressing it?
How can I get the equivalent of an ls
of a .zip file (not gzip), without decompressing it, from the command shell?如何在不解压缩的情况下从命令 shell 获得相当于 .zip 文件(不是 gzip)的
ls
? That is, how can I list the different files compressed within my .zip archive?也就是说,如何列出 .zip 存档中压缩的不同文件?
Perreal's answer is right, but I recommend installing atool (look for it in your distribution's package manager). Perreal 的回答是正确的,但我建议安装atool (在您的发行版的包管理器中查找)。 Then, for any kind of archive file, bzip2, gzip, tar... you have just one command to remember :
然后,对于任何类型的存档文件,bzip2、gzip、tar...您只需记住一个命令:
als archive_name
The less
utility is capable of peeking into a zip
archive. less
实用程序能够查看zip
存档。
Less comes bundled with Unix and there is no need to install als. Less 与 Unix 捆绑在一起,无需安装 als。 The output is scrollable (paged) and does not log things to the terminal (unlike unzip -l mentioned in the other answer).
输出是可滚动的(分页)并且不会将内容记录到终端(与其他答案中提到的 unzip -l 不同)。
As per https://superuser.com/a/216675/249975 ,根据https://superuser.com/a/216675/249975 ,
So simply use less filename.zip
所以只需使用
less filename.zip
To view the contents of a zipped file without unzip by using this command使用此命令查看不解压的压缩文件的内容
unzip -l file.zip
Gor tar files we can use我们可以使用的 Gor tar 文件
zcat <archived-file>
zipinfo -1 filename.zip
It returns only filenames, and no more, example (response):它只返回文件名,不再返回示例(响应):
listing.html
my_data.csv
super.txt
Use lesspipe
in Debian/Ubuntu, it also can list many other archive types:在 Debian/Ubuntu 中使用
lesspipe
,它还可以列出许多其他归档类型:
*.arj *.tar.bz2 *.bz *.bz2 *.deb, *.udeb *.doc *.gif, *.jpeg, *.jpg, *.pcd, *.png, *.tga, *.tiff, *.tif *.iso, *.raw, *.bin *.lha, *.lzh *.pdf *.rar, *.r[0-9][0-9] *.rpm *.tar.gz, *.tgz, *.tar.z, *.tar.dz *.gz, *.z, *.dz *.tar *.jar, *.war, *.xpi, *.zip *.zoo
Usage:用法:
lesspipe file.zip
You can also use "zmore archive_name".您也可以使用“zmore archive_name”。 It will list archive and it content.
它将列出存档及其内容。
I'll add in the following option, as I found it was by far the most convenient approach for my purposes (exploring contents of a 2GB tar, with tens of thousands of files and directories).我将添加以下选项,因为我发现这是迄今为止最方便的方法(探索具有数万个文件和目录的 2GB tar 的内容)。
Using archivemount
was the most useful method for me.使用
archivemount
对我来说是最有用的方法。
This is performed as follows:这是按如下方式执行的:
mkdir mount-point
archivemount archive.tar.gz mountpoint
cd mount-point
umount mount-point
Explanation解释
You need to create an empty folder as your mount point.您需要创建一个空文件夹作为挂载点。 Easiest is to just create that folder within the folder where you have the archive file, as per above example.
最简单的方法是在您拥有存档文件的文件夹中创建该文件夹,如上例所示。 Although you can create it anywhere you like.
虽然你可以在任何你喜欢的地方创建它。 Just change
mount-point
in the command accordingly.只需相应地更改命令中的
mount-point
。
Once you cd
into the mount-point
folder, you'll have a normal Linux folder and file tree to explore with any commands that you'd otherwise use to explore, find, cat, edit, ls, etc., folders and files in Linux. cd
进入mount-point
文件夹后,您将拥有一个普通的 Linux 文件夹和文件树,可以使用任何其他命令来探索,否则将用于探索、查找、cat、编辑、ls 等,其中的文件夹和文件Linux。 Very handy.非常便利。
Use umount
to unmount the archive once you are done完成后使用
umount
卸载存档
Note, you may need to first install archivemount
.请注意,您可能需要先安装
archivemount
。 Eg, sudo apt install archivemount
.例如,
sudo apt install archivemount
。
I basically wanted an easy way to investigate the contents of a large tar file.我基本上想要一种简单的方法来调查大型 tar 文件的内容。 Just having a massive text output (tens of thousands of lines) of the folder and file names wasn't particularly useful for me.
仅具有文件夹和文件名的大量文本输出(数万行)对我来说并不是特别有用。 Even after figuring out ways to pipe that content through other post-processors.
即使在想出通过其他后处理器传输该内容的方法之后。
You can use this method with zip files, tar files, and those compressed with gzip, bzip, or compress.您可以将此方法用于 zip 文件、tar 文件以及使用 gzip、bzip 或 compress 压缩的文件。
Full details on archivemount
are here .关于
archivemount
完整细节在这里。
A good write-up on it is here .一篇关于它的好文章在这里。
This quote (from that article) summarises how flexible this tool is:这个引用(来自那篇文章)总结了这个工具的灵活性:
[Because archivemount via FUSE] exposes its filesystems through the Linux kernel, you can use any application to load and save files directly into such mounted archives.
[因为存档挂载通过 FUSE] 通过 Linux 内核公开其文件系统,您可以使用任何应用程序将文件直接加载和保存到此类挂载的存档中。 This lets you use your favourite text editor, image viewer, or music player on files that are still inside an archive file.
这使您可以对仍在存档文件中的文件使用您最喜欢的文本编辑器、图像查看器或音乐播放器。 Going one step further, because archivemount also supports write access for some archive formats, you can edit a text file directly from inside an archive too.
更进一步,因为 archivemount 还支持对某些存档格式的写访问,您也可以直接从存档内部编辑文本文件。
Try using zless if you would like to browse a single zipped file.如果您想浏览单个压缩文件,请尝试使用 zless。 This may be less useful when the zip contains multiple files.
当 zip 包含多个文件时,这可能不太有用。
Per the description from the man page:根据手册页的描述:
Zless is a filter which allows examination of compressed or plain text files one screenful at a time on a soft-copy terminal.
Zless 是一种过滤器,它允许在软拷贝终端上一次一屏地检查压缩或纯文本文件。 It is the equivalent of setting the environment variable LESSOPEN to '|gzip -cdfq -- %s', and the environment variable LESSMETACHARS to '<new‐line>;*?"()<>[|&^`#$%=~', and then running less. However, enough people seem to think that having the command zless available is important to be worth providing it.
它相当于将环境变量 LESSOPEN 设置为 '|gzip -cdfq -- %s',并将环境变量 LESSMETACHARS 设置为 '<new-line>;*?"()<>[|&^`#$% =~',然后运行更少。然而,似乎有足够多的人认为拥有 zless 命令对于值得提供它很重要。
Some other handy "z" utilities are zcat and zmore (mentioned in previous answers), zdiff and zgrep.其他一些方便的“z”实用程序是 zcat 和 zmore(在前面的答案中提到过)、zdiff 和 zgrep。
Regarding answering the original question, how to view the contents of a zip, I prefer zipinfo followed by unzip -l.关于回答原始问题,如何查看 zip 的内容,我更喜欢 zipinfo,然后是 unzip -l。
To list/view the contents of a compressed file on a Linux host without uncompressing it (and where GZIP is installed), use the "zcat" command.要在 Linux 主机上列出/查看压缩文件的内容而不解压缩它(以及安装 GZIP 的位置),请使用“zcat”命令。
zcat compressedfilename |more zcat 压缩文件名 |more
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.