List The Contents Of a tar.bz2 Tarball File

Posted on in Categories , , , last updated December 5, 2013

How do I list the contents of a tar.bz2 file under Linux or UNIX-linke operating systems using a shell prompt?

The bzip2 command compresses most files effectively than traditional gzip/zip tool but is slower. In this manner it is fairly similar to other recent-generation compression algorithms. Unlike other formats such as RAR or ZIP (but similar to gzip), bzip2 is only a data compressor, not an archiver. bzip2 compresses files using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. You need the following utilities (both are installed by default on Unix-like operating systems):

a) tar command

b) bzip2 command

Open the Terminal and type the following commands.

List the contents of a tar.bz2 file on Linux/Unix

To list the contents of a tar.bz2 file use GNU/tar command as follows:
tar -jtvf {file-name.tar.bz2}
tar -jtvf file-name.tar.bz2 | less
tar --bzip2 --list --verbose --file={file-name.tar.bz2}

Sample outputs:

-rw-r--r-- root/root       100 2011-09-05 03:18 etc/modprobe.d/bonding.conf
drwxr-xr-x root/root         0 2013-10-13 00:33 etc/sensors.d/
-rw-r--r-- root/root         0 2010-05-26 23:02 etc/sensors.d/.placeholder
drwxr-sr-x root/bind         0 2013-08-26 21:17 etc/bind/
-rw-r----- bind/bind        77 2013-08-26 21:17 etc/bind/rndc.key
-rw-r--r-- root/bind       890 2013-08-26 21:17 etc/bind/named.conf.options
-rw-r--r-- root/root      3048 2013-07-27 14:16 etc/bind/db.root

If filename is backup.tar.bz2, enter:
$ tar -jtvf backup.tar.bz2
To search for a particular filename called data.txt, enter:
$ tar -jtvf backup.tar.bz2 | grep -i data.txt

  • t: List the contents of an archive.
  • v: Verbosely list files processed (display detailed information)
  • j: Filter the archive through bzip2 so that we can open compressed (decompress) .gz tar file
  • f filename: Use archive file called filename

List the Contents of tar.bz2 file using bzip2 and pipes

The basic syntax is:
bzip2 -cd files-name-here.bz2 | tar tvf -
Sample outputs:

drwxr-xr-x root/root         0 2013-11-25 00:39 etc/
drwxr-xr-x root/root         0 2013-06-13 01:38 etc/cron.weekly/
-rwxr-xr-x root/root       907 2012-06-19 04:21 etc/cron.weekly/man-db
-rw-r--r-- root/root       102 2010-12-19 06:06 etc/cron.weekly/.placeholder
drwxr-xr-x root/root         0 2013-06-13 01:38 etc/vim/
-rw-r--r-- root/root       662 2013-02-10 07:58 etc/vim/vimrc.tiny
-rw-r--r-- root/root      2191 2010-07-12 07:48 etc/vim/vimrc
-rw-r--r-- root/root     19398 2012-05-14 04:41 etc/services
-rw-r--r-- root/root     32732 2013-11-25 00:39 etc/

GUI tools

Most modern GUI manager such as KDE or Gnome has inbuilt support for displaying and extracting tar.bz2 files.

GUI Archive Manager application

You can use the Archive Manager application to create, view, modify, or unpack an archive. An archive is a file that acts as a container for other files. An archive can contain many files, folders, and subfolders, usually in compressed form. Archive Manager provides only a graphical interface, and relies on command-line utilities such as tar, gzip, and bzip2 for archive operations.

Just double click on .tar.bz2 file to view its contents:

Fig.01: Linux / UNIX Archive Manager
Fig.01: Linux / UNIX Archive Manager

Archive Manager displays the archive contents in the main window as a file list with the following columns:

  1. Name: The name of a file or folder in the archive.
  2. Size: The size of the file when the file is extracted from the archive. For a folder, the Size field is blank. For information on how to display the size of the compressed file.
  3. Type: The type of the file. For a folder, the value in the Type field is Folder.
  4. Date modified: The date on which the file was last modified. For a folder, the Date modified field is blank.
  5. Location: The path to the file within the archive. This column is visible only when the window is in file view, when in folder view the location of the files is displayed in the Location text box of the folderbar.

For more information see tar(1).

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

1 comment

  1. Hi,
    I need to calculate the size of each block contained in the bz2 file from the hex dump of the .bz2 file. This should be possible by going through first couple of lines of the hex dump.


Leave a Comment