Friday, January 17, 2014

HOWTO list the contents of a tar, tar.gz or tar.bz2 file

"tar" is an archiving program designed to store and extract files from an archive file known as a tarfile. However, sometimes you need to list the contents of a tar or tar.gz file on screen before extracting all the files.

1. List the contents of a tar file:
ximena@anneke:~$ tar -tvf file.tar

2. List the contents of a tar.gz file:
ximena@anneke:~$ tar -ztvf file.tar.gz

3. List the contents of a tar.bz2 file
ximena@anneke:~$ tar -jtvf file.tar.bz2

Where:   
t: List the contents of an archive.
v: Verbose list files processed.
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