Today I needed to list some files in a .tar.gz files, and after checking the man page of the tar command, I decided to write this post for any one who may be asking. How to read the contents of a tar file?
Here is how.
tar -tf file.tar
This will list on the screen all files on the archive file.tar, you may want to use less, to page the output.
tar -tf file.tar | less
To list the files if the .tar file is gzipped.
tar -ztf file.tar.gz
tar -ztf file.tar.gz | less
To list the files if the .tar file is bzipped.
tar -jtf file.tar.bz2
tar -jtf file.tar.bz2 | less
You can also use grep to find a specific file in the archive.