Which Is the Best Compression Tool for Linux?

Take a Look at Zip, Gzip, and bzip2

ZIP FILE CONCEPT

  cnythz / Getty Images 

When it comes to finding file compression tools in Linux, you are bound to encounter zip, gzip and bzip2. Which one is the best compression tool for you depends in part on what you are planning to compress. A series of tests put these three tools through their paces to see which one is best. 

Best Tool for Compressing Windows Documents

The first test uses each compression tool on a single file type to determine how each tool handles the file in question. This series of tests ran on a Windows document in the Microsoft DOCX format.

Using the default settings, the results are:

Tool File Size
Initial Filesize 12202 bytes
zip 9685
gzip 9537
bzip2 10109

Using the maximum compression settings on the same file delivered similar results. Using the maximum compression didn't deliver better results than using the default settings.

Tool File Size
Initial Filesize 12202 bytes
zip 9677
gzip 9530
bzip2 10109

Running this same test on two other files, one containing text only and one containing text, images, and formatting, delivered the same result: The maximum compression settings didn't make much difference in the results. 

In all three tests, gzip comes out on top in all categories and bzip2 is the least effective.

Best Tool for Compressing Images

The next test shows the results of compressing images in PNG, JPG, Bitmap, and GIF formats. In theory, JPG files are already compressed and therefore may not compress at all and could, in theory, make the file bigger. The test results illustrated that compressing the JPB format images had little effect.

PNG File

Tool File Size
Initial Filesize 345265
zip 345399
gzip 345247
bzip2 346484

JPEG File

Tool File Size
Initial Filesize 44340
zip 44165
gzip 44015
bzip2 44281

Bitmap File

Tool File Size
Initial Filesize 3113334
zip 495028
gzip 494883
bzip2 397569

GIF File

Tool File Size
Initial Filesize 6164
zip 5772
gzip 5627
bzip2 6051

In all cases, gzip came out on top again except for the humble bitmap. On the bitmap image, the bzip2 compression produced a tiny file in comparison to the original and the other compression formats.

Best Tool for Compressing Audio Files

The most common audio format is MP3, which has already been compressed, so the tools did not make much difference in the size of the two files that were tested.

File 1

Tool File Size
Initial Filesize 5278905
zip 5270224
gzip 5270086
bzip2 5270491

File 2

Tool File Size
Initial Filesize 4135331
zip 4126138
gzip 4126000
bzip2 4119410

Best Tool For Compressing Video

For this test, two video files were tested. As with MP3, the MP4 file already contains a level of compression. The FLV file does not have any level of compression as it is a lossless format.

MP4

Tool File Size
Initial Filesize 731908
zip 478546
gzip 478407
bzip2 478042

FLV

Tool File Size
Initial Filesize 7833634
zip 4339169
gzip 4339030
bzip2 4300295

Both file formats were compressed, and on both, bzip2 did the best job, although the results were similar.

Executables

The last category contains executables. Because executables are compiled code, it's no surprise that they don't compress well.

File 1

Tool File Size
Initial Filesize 26557472
zip 26514031
gzip 26513892
bzip2 26639209

File 2

Tool File Size
Initial Filesize 195629144
zip 193951631
gzip 193951493
bzip2 194834876

Although the effects were minimal, the gzip compression comes out on top and bzip2 comes in last. 

Complete Folder Test

This time, the test is run on a folder full of images, documents, spreadsheets, videos, audio files, executables, and other different file formats.

Default Compression

Tool File Size Time Taken
Initial File 1333084160 0
zip 1303177778 1 minute 10 seconds
gzip 1303177637 1 minute 35 seconds
bzip2 1309234947 6 minutes 5 seconds

Maximum Compression

Tool File Size Time Taken
Initial File 1333084160 0
zip 1303107894 1 minute 10 seconds
gzip 1303107753 1 minute 35 seconds
bzip2 1309234947 6 minutes 10 seconds

Fastest Compression

Tool File Size Time Taken
Initial File 1333084160 0
zip 1304163943 1 minute 0 seconds
gzip 1304163802 1 minute 15 seconds
bzip2 1313557595 6 minutes 10 seconds

Based on the final test, it is clear that bzip2 is not as useful as the other two compression tools. It takes longer to compress the files, and the final file size is larger than the other two tools.

The difference between zip and gzip is negligible, and while gzip generally comes out on top, the zip format is more common across different operating systems.

The Verdict

Use either zip or gzip as your Linux file compression tool. Maybe bzip2 has had its day and needs to be confined to history.