bzip2

bzip2(1) is an alternative compression program installed on Slackware Linux. It uses a different compression algorithm from gzip, which results in some advantages and some disadvantages. The main advantage for bzip2 is the compressed file size. bzip2 will almost always compress better than gzip. In some instances, this can result in dramatically smaller files. This can be a great advantage for people on slower modem connections.

The disadvantage to bzip2 is that it is more CPU intensive than gzip. This means that bzipping a file will generally take longer and will use more of the CPU than gzipping the file would. When considering which compression program to use, you must weigh this speed vs. compressed size and determine which is more important.

The usage of bzip2 is very similar to gzip, so not much time will be spent discussing that. Simply call bzip2 with a filename to compress it:

   $ bzip2 infile

The resulting output file will usually be smaller than the input file, and will be called infile.bz2. As with gzip, the input file will no longer exist, since bzip2 replaces the input file with a compressed copy.

You can also use a numeric command line argument to tweak compression rates and speed as with gzip. The following example shows how to achieve maximum compression with bzip2 with considerable CPU usage:

   $ bzip2 -9 infile

There are two commands to decompress files ending in a .bz2 extension, just as with gzip. You can use bzip2 or bunzip2(1) to decompress bzipped files. Using bzip2 requires using a command line argument:

   $ bzip2 -d infile.bz2

This will decompress the bzipped file and replace it with the decompressed copy. This resulting file will also have been stripped of the .bz2 extension. Similarly, you can use bunzip2 to decompress the file:

   $ bunzip2 infile.bz2

You'll get the same behavior either way, thanks again to a symbolic link. Checking out /bin/bunzip2 shows that it is simply a symbolic link to /bin/bzip2. This uses the same trick that gzip did. You'll find that calling a program using several different names to achieve different behaviors is a favorite trick of Linux programmers.

   $ cd /bin
   $ ls -l bunzip2
   lrwxrwxrwx   1 root  root      5 Feb  2 09:45 /bunzip2 -> bzip2