< Previous | Contents | Next >
bzip2
The bzip2 program, by Julian Seward, is similar to gzip, but uses a different compres- sion algorithm that achieves higher levels of compression at the cost of compression speed. In most regards, it works in the same fashion as gzip. A file compressed with bzip2 is denoted with the extension .bz2:
[me@linuxbox ~]$ ls -l /etc > foo.txt
[me@linuxbox ~]$ ls -l foo.txt
-rw-r--r-- 1 me me 15738 2016-10-17 13:51 foo.txt [me@linuxbox ~]$ bzip2 foo.txt
[me@linuxbox ~]$ ls -l foo.txt.bz2
-rw-r--r-- 1 me me 2792 2016-10-17 13:51 foo.txt.bz2 [me@linuxbox ~]$ bunzip2 foo.txt.bz2
[me@linuxbox ~]$ ls -l /etc > foo.txt
[me@linuxbox ~]$ ls -l foo.txt
-rw-r--r-- 1 me me 15738 2016-10-17 13:51 foo.txt [me@linuxbox ~]$ bzip2 foo.txt
[me@linuxbox ~]$ ls -l foo.txt.bz2
-rw-r--r-- 1 me me 2792 2016-10-17 13:51 foo.txt.bz2 [me@linuxbox ~]$ bunzip2 foo.txt.bz2
As we can see, bzip2 can be used the same way as gzip. All the options (except for
-r) that we discussed for gzip are also supported in bzip2. Note, however, that the compression level option (-number) has a somewhat different meaning to bzip2. bzip2 comes with bunzip2 and bzcat for decompressing files.
bzip2 also comes with the bzip2recover program, which will try to recover dam- aged .bz2 files.
Don’t Be Compressive Compulsive
I occasionally see people attempting to compress a file, that has already been compressed with an effective compression algorithm, by doing something like this:
$ gzip picture.jpg
Don’t do it. You’re probably just wasting time and space! If you apply compres- sion to a file that is already compressed, you will actually end up with a larger file. This is because all compression techniques involve some overhead that is added to the file to describe the compression. If you try to compress a file that al- ready contains no redundant information, the compression will not result in any savings to offset the additional overhead.