Linux Command Line: bzip2/bunzip2
The bzip2/bunzip2 compression utility is part of the bzip family created by Julian Seward in 1996. Version 1 of bzip did not arrive to the public until some four years later. Because bzip2/bunzip2 manages to compress more than standard compression tools (such as gzip and zip), it does work a bit slower. The speed difference is negligible when working on smaller files, but when having to compress larger files, such as a kernel, there will be a noticeable difference. The trade off is having a much smaller compressed file in the end.
The bzip2 and bunzip2 tackle two different tasks. The bzip2 tool handles compression and the bunzip2 tool handles decompression. Because of this, the basic usage is very simple:
To compress a file the command would look like: bzip2 filename
Where filename is the actual file name to be compressed. The resulting compressed file will look like filename.bz2.
To decompress a file the command would look like: bunzip2 filename.bz2
Where filename.bz2 is the actual file name to decompress. The resulting decompressed file will be filename.
The bzip2 tools are not archiving tools. In order to compress a directory, the directory must be archived first. If you have a large directory, say TEMP, and you want more compression than gzip gives you, you will have to use the tar archiving tool to first archive the directory. Once the directory is archived it can be compressed with gzip2. So both commands for this would look like:
tar cf TEMP.tar TEMP
The resulting file would be TEMP.tar.bz2
Both bzip2 and bunzip2 have arguments that can be passed at the command line. One argument specifies block size to help ease memory usage during compression/decompression. This idea is outdated because computers have evolved well beyond anything used when bzip2 was created. So unless memory usage is a real problem, these arguments aren’t really necessary.
When you need serious compression and ease of use, you need to look beyond the standard gzip and zip to bzip2.
This post is part of the series: Simplify Linux application installation and archiving
If you are new to Linux than you might be baffled as to how to handle two important tasks: Application installation and directory archiving. Never fear, Bright Hub is hear. In this series of articles you will learn how to master the tools to help you tackle these tasks.