Let's say you have a tar archive named example.tar.
example.tar
The tar command with the -t or --list and -f or --file optiions can be used to view the contents of the tar achive. In this example, the tar archive contains two files, foo.txt and bar.txt.
tar -tf example.tar
tmp/sample
tmp/sample/foo.txt
tmp/sample/bar.txt
The -v or --verbose option can be used to include the file attributes.
tar -tvf example.tar
drwxr-x--- root root 4096 2011-08-24 21:38 tmp/sample
-rw-rw-r-- root root 2699 2011-08-24 21:39 tmp/sample/foo.txt
-rw-rw-r-- root root 1784 2012-01-12 05:21 tmp/sample/bar.txt
Search for a specific file
An individual file can be included on the command line. If the tar archive contains the file, the following will be displayed.
tar -tf example.tar tmp/sample/foo.txt
tmp/sample/foo.txt
If the tar archive does not contain the file, the following will be displayed.
tar -tf example.tar tmp/sample/bogus.txt
tar: tmp/sample/bogus.txt: Not found in archive
Compression
If the tar archive is gzip compressed, the -z option must be included.
tar -ztf example.tar.gz
If the tar archive is bzip2 compressed, the -j option must be included.
tar -jtf example.tar.bz2
Or, pigz could be used.
tar --use-compress-program=pigz -tf example.tar.pigz
Did you find this article helpful?
If so, consider buying me a coffee over at