einpoklum
einpoklum

Reputation: 131970

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? That is, how can I list the different files compressed within my .zip archive?

Upvotes: 107

Views: 152191

Answers (11)

Stavr00
Stavr00

Reputation: 3314

Answer, using just the latest version of Zip (3.0) to list filenames only:

> zip -sf zip300xn.zip
Archive contains:
  Contents
  LICENSE
  README
  README.CR
  WHATSNEW
  WHERE
  zip30.ann
  zip.txt
  zipcloak.txt
  zipnote.txt
  zipsplit.txt
  zip.exe
  zipnote.exe
  zipsplit.exe
  zipcloak.exe
Total 15 entries (770278 bytes)

Upvotes: 1

Javeed Shakeel
Javeed Shakeel

Reputation: 3427

To view the contents of a zipped file without unzip by using this command

unzip -l file.zip

For tar files, we can use

zcat <archived-file>

Upvotes: 16

Doyle B
Doyle B

Reputation: 174

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 '<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.

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.

Upvotes: 0

computingfreak
computingfreak

Reputation: 5129

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

Upvotes: 26

inspirednz
inspirednz

Reputation: 5077

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.

Upvotes: 2

perreal
perreal

Reputation: 98058

Use unzip with -l option:

unzip -l file.zip

Upvotes: 161

mzalazar
mzalazar

Reputation: 6586

zipinfo -1 filename.zip

It returns only filenames, and no more, example (response):

listing.html
my_data.csv
super.txt

Upvotes: 9

user7531546
user7531546

Reputation: 1

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

Upvotes: -1

Miklos Aubert
Miklos Aubert

Reputation: 4575

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

Upvotes: 19

papalagi
papalagi

Reputation: 770

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

Upvotes: 6

Xavier S.
Xavier S.

Reputation: 1167

You can also use "zmore archive_name". It will list archive and it content.

Upvotes: 2

Related Questions