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):
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | tar/bzip2 |
Time | 2m |
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
Where,
- 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/ld.so.cache
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:
Archive Manager displays the archive contents in the main window as a file list with the following columns:
- Name: The name of a file or folder in the archive.
- 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.
- Type: The type of the file. For a folder, the value in the Type field is Folder.
- Date modified: The date on which the file was last modified. For a folder, the Date modified field is blank.
- 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) command man page.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 1 comment... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
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.
regards
harpreet