Q. How do I list the contents of a tar or tar.gz file?
A. GNU/tar is an archiving program designed to store and extract files from an archive file known as a tarfile. You can create a tar file or compressed tar file tar. However sometime you need to list the contents of a tar or tar.gz file on screen before extracting the all files.
Task: List the contents of a tar file
Use the following command:
$ tar -tvf file.tar
Task: List the contents of a tar.gz file
Use the following command:
$ tar -ztvf file.tar.gz
Task: List the contents of a tar.bz2 file
Use the following command:
$ tar -jtvf file.tar.bz2
Where,
- t: List the contents of an archive
- v: Verbosely list files processed (display detailed information)
- z: Filter the archive through gzip so that we can open compressed (decompress) .gz tar file
- j: Filter archive through bzip2, use to decompress .bz2 files.
- f filename: Use archive file called filename
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 14 comments… read them below or add one }
Thanks a lot Vivek…This article is very useful for me….
Perfect!
I don’t know why I always forget this!
Also the ‘j’ trick is killer! I always just try to use ‘z’, and then give up when bzip won’t play. Now I just need to remember … use j in stead of z when bzip.
great and thx..
thanks!
Rule of Thumb -
{
Use ‘z’ while compressing/decompressing/listing the file with GZIP.
Use ‘j’ while compressing/decompressing/listing the file with BZIP2.
}
- with tar command.
Thanks
Amit Verma
The exact thing I was looking for, worked like a charm! :)
Good Work!!!
Thanks!!!
keep it up!!!
;)
Thanks for the helpful contests
Thanks a lot for this post guys …:)
Keep it up …
thanks. I’m too lazy to read the man page.
$ tar -tvf file.tar works for all three file formats.
$ unzip -l works for zip files
Thanks it works fine however do you know if there is a faster way maybe? I have a 6GB gzip file and it takes ages to list the contents. For smaller files it is ok but for big files it is a pain.
man pages are too long, thanks vivek.
@Stefan, u cud try
now i assume u may be looking for a certain file in that big gzip, so
and u can now check for multiple names without the initial wait of listing the big gz’s files.
I know this coz i have just done it thanks to reading this blog.thx again Vivek.
I’m trying to find and display, but this isn’t working for me..
find -name “.gz” | tar -tvf {};