How to view/list the files in an archive(tar or zip) without extracting/decompressing it

Many a times, its better to view what's in the archive before extracting it. Sometimes the stuff compressed together is useless and extracting it might be just a waste of time and energy. Here we will consider both tar and zipped files and will list out the files bundled inside without fully extracting it.

For graphical environments, one can easily view the files inside by using an archive manager, eg.  file-roller in GNOME.

For Consoles

For tar files, we can use the "-t" option to state the contents of the file. This options applies to both zip and bzip formats.

[shredder12]$ tar -tf file.tar
or
[shredder12]$ tar -tf file.tar.gz
or
[shredder12]$ tar -tf file.tar.bz2

In case of files archived using gzip, we can use the "-l" option of unzip command.

[shredder12]$ unzip -l file.zip

2 Comments

astralia (not verified)
November 9th, 2010 09:33 pm
In my opinion, the easiest way to show tar content is opening that files with vim :) It lists everything!
November 10th, 2010 10:43 am

Thanks astralia. I never even tried opening an archived file with vim thinking that it would just show garbage values because of its random binary content. Vim is indeed smart :).

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.