How can I list the files in a zip archive without decompressing it?

LinuxBashShellUnixZip

Linux 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

reference

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 ';*?"()<>[|&^`#$%=~', and then running less. However, enough people seem to think that having the command zless available is important to be worth providing it.

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioneinpoklumView Question on Stackoverflow
Solution 1 - LinuxperrealView Answer on Stackoverflow
Solution 2 - LinuxcomputingfreakView Answer on Stackoverflow
Solution 3 - LinuxMiklos AubertView Answer on Stackoverflow
Solution 4 - LinuxJaveed ShakeelView Answer on Stackoverflow
Solution 5 - LinuxmzalazarView Answer on Stackoverflow
Solution 6 - LinuxpapalagiView Answer on Stackoverflow
Solution 7 - LinuxinspirednzView Answer on Stackoverflow
Solution 8 - LinuxXavier S.View Answer on Stackoverflow
Solution 9 - LinuxDoyle BView Answer on Stackoverflow
Solution 10 - Linuxuser7531546View Answer on Stackoverflow