Linux

Adding attachments to emails have been done since time immemorial.
Uploading files to File servers have been done since forever.

How do you share files to co-workers, clients and friends? Sure, there’s Dropbox, SkyDrive and Google Drive nowadays but this shouldn’t change the practice of compressing files meant to be shared.

The bzip2 Utility is a handy tool available in Unix that lets you compress files. It compresses files into one file and adds the .bzip2 extension to it.

bzip2 Example

In our example, we have a file with the file size of 3.6 Megabytes.

teejay:bzip_sample teejay$ ls -lh
total 7568
-rw-r--r--@ 1 teejay  staff   3.6M Aug  9 20:43 slide18.psd

A quick bzip2 magic and we will have a smaller file.

teejay:bzip_sample teejay$ bzip2 slide18.psd 
teejay:bzip_sample teejay$ ls -lh
total 3368
-rw-r--r--@ 1 teejay  staff   1.6M Aug  9 20:43 slide18.psd.bz2

An incredible 44% decrease in filesize.

Extraction from a bzip2 file

A bzip2 file is of course unusable in its compressed form. Fortunately, it’s just as easy as the compression part.

teejay:bzip_sample teejay$ bunzip2 slide18.psd.bz2 
teejay:bzip_sample teejay$ ls -lh
total 7568
-rw-r--r--@ 1 teejay  staff   3.6M Aug  9 20:43 slide18.psd

Further Resources