How can I list the files in a zip archive without decompressing it?
LinuxBashShellUnixZipLinux Problem Overview
How can I get the equivalent of an ls
of a .zip file (not gzip), without decompressing it, from the command shell? That is, how can I list the different files compressed within my .zip archive?
Linux Solutions
Solution 1 - Linux
Use unzip with -l
option:
unzip -l file.zip
Solution 2 - Linux
The less
utility is capable of peeking into a zip
archive.
Less comes bundled with Unix and there is no need to install als. The output is scrollable (paged) and does not log things to the terminal (unlike unzip -l mentioned in the other answer).
As per https://superuser.com/a/216675/249975,
So simply use less filename.zip
Solution 3 - Linux
Perreal's answer is right, but I recommend installing atool (look for it in your distribution's package manager). Then, for any kind of archive file, bzip2, gzip, tar... you have just one command to remember :
als archive_name
Solution 4 - Linux
To view the contents of a zipped file without unzip by using this command
unzip -l file.zip
Gor tar files we can use
zcat <archived-file>
Solution 5 - Linux
zipinfo -1 filename.zip
It returns only filenames, and no more, example (response):
listing.html
my_data.csv
super.txt
Solution 6 - Linux
Use lesspipe
in Debian/Ubuntu, it also can list many other archive types:
> *.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
Solution 7 - Linux
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).
Using archivemount
was the most useful method for me.
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.
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. Very handy.
Use umount
to unmount the archive once you are done
Note, you may need to first install archivemount
. E.g, sudo apt install archivemount
.
Why I found this so useful
I basically wanted an easy way to investigate the contents of a large tar file. 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.
Full details on archivemount
are here.
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. 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.
Solution 8 - Linux
You can also use "zmore archive_name". It will list archive and it content.
Solution 9 - Linux
Try using zless if you would like to browse a single zipped file. This may be less useful when the zip contains multiple files.
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. It is the equivalent of setting the environment variable LESSOPEN to '|gzip -cdfq -- %s', and the environment variable LESSMETACHARS to '
Some other handy "z" utilities are zcat and zmore (mentioned in previous answers), zdiff and zgrep.
Regarding answering the original question, how to view the contents of a zip, I prefer zipinfo followed by unzip -l.
Solution 10 - Linux
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.
zcat compressedfilename |more