Nov 10, 2018

How to list the contents of a tar or tar.gz or tar.bz2 file from command line in Linux

To list the contents of a tar file

Use the following command:
$ tar -tvf file.tar

To list the contents of a tar.gz file

Use the following command:
$ tar -ztvf file.tar.gz

To list the contents of a tar.bz2 file

Use the following command:
$ tar -jtvf file.tar.bz2

  • 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

See also:

How to view the content in a zip archive without decompress from command line in linux