There's no shortage of compression tools available for Linux systems. Having so many choices is ultimately a good thing, but it can also be confusing and make it more difficult to select a compression method to use on your own files. To complicate things further, there is no objectively best tool for every user or system, and we'll explain why.

When it comes to compression, there are two benchmarks that we need to be concerned with. One is how much space is saved, and the other is how fast the compression process takes place. Another thing to take into consideration is how widespread a certain compression tool is. For example, it'd be much more appropriate to package files into a .zip archive instead of .tar.gz if you know that the archive will need to be opened on a Windows system. Conversely, a .tar.gz archive makes more sense on Linux, since tar files save file permissions.

In this guide, we'll be looking at a variety of compression tools that are available on the most popular Linux distributions. We'll compare their compression ratio, speed, and other features. By the end of this guide, you'll be armed with enough information to choose the best compression tool for any given scenario.

In this tutorial you will learn:
  • Benchmark results of various compression utilities
  • How to conduct your own tests to measure compression ratio and speed
  • Picking a compression utility based on compatibility
Benchmarking compression results of a directory with 7zip, the winner of our test
Benchmarking compression results of a directory with 7zip, the winner of our test
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software gzip, bzip2, xz, zip, rar, 7zip
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Benchmarking Compression Tools

In order to compare the various compression tools available, we will try compressing a video game installation. Video game installations include a large assortment of music, videos, text, executables, and other file types. These tests are meant to give a general average of how well each compression tool compares to the next. Video games act as a good benchmark since they contain a large amount of data in lots of different formats.

Benchmark Test Results

We'll be compressing an installation of Star Wars Galactic Battlegrounds, which weighs in at 790 MB before our compression. Let's see how far we can compress these files.

Compression Method File Size Time Elapsed
gzip 591 MB 2:27
bzip2 567 MB 8:57
xz 534 MB 15:27
zip 591 MB 2:23
rar 541 MB 5:24
7zip 531 MB 8:41

Benchmark Conclusions

As you can see, 7zip gave us the best compression ratio, and even took less time to perform its operation than some other methods that produced a bigger file.

You should take these tests with a small grain of salt, as you may get varying results depending on the types of files you compress. The time elapsed will also vary widely, depending on the system's hardware.

Furthermore, some compression methods have extra options to further increase compression ratio or speed. For example, gzip uses level 6 compression by default, but can go all the way to 9. This may save you a few extra megabytes but will also take your system longer to do the job. Conversely, a smaller number will yield a faster result, but less compression.

Our results should definitely give you a general impression of the efficacy of each compression method, but feel free to replicate our tests using your own system and files of your choosing. This can help you determine if the best tool for us is also the best tool for you.

We used each compression command with its default options. We also used the time and nice Linux commands to help us measure time elapsed and increase CPU priority for the compression process, respectively. To mirror our test commands exactly, the correct syntax would look like this:

$ sudo time nice -n -20 tar -czvf archive.tar.gz game-directory

Of course, substitute a different compression command for each utility you'd like to test. We've written guides for most of the compression methods here. Be sure to check them out if you need more help, as well as example commands, etc.


SUBSCRIBE TO NEWSLETTER
Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


What About Compatibility?

There's one important aspect that we can't measure in our benchmarking test, which is a compression format's compatibility. You need to keep your target audience in mind. For example, tar files work well on Linux because they preserve file permissions. Plus, Linux users are generally very familiar with tar files and how to open them, whether they're compressed with gzip, bzip2, or xz.

For Windows systems, you'll find much better compatibility with zip files. This format also works fine on Linux, and can almost always be opened natively. RAR and 7zip are a little less popular, but have become widespread enough that most users can probably open them.

When in doubt, it's always better to stick with a widely accepted file format and deal with the bit of extra file size. If your situation doesn't call for compatibility, then you only need to factor compression ratio and speed into your decision.

Closing Thoughts

In this guide, we saw a comparison of various compression tools used in Linux, as well as a benchmark test to determine which tools work most efficiently for compression ratio and speed. You also learned how to perform similar tests on your own system, as file formats and system hardware have a huge influence on compression results.

Linux comes with many compression utilities by default, but our guide should help save you time in picking the best one for your situation. We used a Ubuntu Linux machine to conduct our tests, and found that most of these compression utilities came preinstalled. Depending on your Linux distro, you may find that you need to install some of these utilities yourself. Don't forget to check our previously mentioned guides for extra help.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.