What Is the Best Compression Tool in Linux?

In this article, we will compare all the best and most popular Linux compression tools. This will include benchmark tests to see which compression method performs the best, and we’ll also weigh the pros and cons of compatibility and other areas. Compression methods covered will be gzip, xz, bzip2, 7zip, zip, rar, and zstd (Zstandard).

Linux gives us a lot of options when we need to compress files. While that’s definitely a good thing, it can lead to confusion about which one should be used. Let’s start by comparing each method across a few key areas.

Compression Benchmark Test

Although compression ratio should not be the only determining factor when deciding on which tool to use, it will definitely play a big role.

For our benchmark test, we’ll try compressing a copy of the 2002 video game Age of Mythology with a variety of tools. Older video games like AOM make for a good test, since compression methods weren’t up to par with today’s technology and video games contain a wide range of file formats, like audio, video, images, binary files, text, etc. The total size of this video game installation is 1350 MB.

Default Compression Results

Here are the results of our compression test when we use each tool’s default compression level. You can see the resulting compressed size, time elpased, and the precise commands we used to perform the compression.

Compression Size Time Elapsed Command
gzip 955 MB 1:45 tar cfz AOM.tar.gz AOM/
xz 856 MB 16:06 tar cfJ AOM.tar.xz AOM/
bzip2 943 MB 5:36 tar cfj AOM.tar.bz2 AOM/
7zip 851 MB 10:59 7z a AOM.7z AOM/
zip 956 MB 1:41 zip -r AOM.zip AOM/
rar 877 MB 6:37 rar a AOM.rar AOM/*
zstd 934 MB 0:43 tar --zstd -cf AOM.tar.zst AOM/

Our test directory has been compressed with multiple tools

Highest Compression Results

And here are the results when we use each tool’s maximum compression level. A higher compression level usually results in some minor space savings, but can take the tool a lot longer to perform the job. The commands we use below are utilizing the absolute maximum compression level for each tool.

Compression Size Time Elapsed Command
gzip 954 MB 2:10 tar cf - AOM/ | gzip -9 - > AOM.tar.gz
xz 847 MB 27:32 tar cf - AOM/ | xz -9e - > AOM.tar.xz
bzip2 943 MB 5:42 tar cf - AOM/ | bzip2 -9 - > AOM.tar.bz2
7zip 845 MB 16:41 7z a -mx=9 AOM.7z AOM/
zip 955 MB 2:05 zip -9 -r AOM.zip AOM/
rar 876 MB 6:31 rar a -m5 AOM.rar AOM/*
zstd 873 MB 22:19 tar -I 'zstd --ultra -22' -cf AOM.tar.zst AOM/

And the Winner Is…

According to our benchmark test:

For compression ratio, the best compression tool on Linux is 7zip.

For compression speed, the best compression tool on Linux is Zstandard (zstd).

Potential for Varying Results

Keep in mind that you should take these benchmark results with a grain of salt. Depending on the type of files you’re compressing, and the hardware of your PC or server, you could get very different results in compression ratio and speed. This benchmark test works well as a very general measurement of the compression tools listed, but every situation is going to be different. If in doubt, try out a few of them yourself – that’s why we’ve given you the commands for each compression tool.

Note also that we used the normal compression level and maximum compression level for each tool. There are a lot of other choices than just these two options. You could use some value in between, or even use a lesser compression level so the files compress very quickly.

Compatibility

Compression ratio and speed aren’t the only concern. Not always, anyway.

On Linux systems, tar is the usual format for archives. Compression is then added to the tar file, resulting in extensions like .tar.gz and .tar.bz2 and .tar.xz. The tar format is able to combine files into a single archive, while preserving all of the Linux file permissions. Its compatibility with Linux file systems is why it’s preferred on Linux.

On other operating systems, like Windows, the .zip format is much more common. Zip files are usually pretty painless to open on Linux, but tar files don’t always enjoy the same privilege on Windows. Zip files also won’t preserve file permissions on Linux.

Why’s this matter? Well, depending on what you’re doing with your compressed archive, you may need to take the filetype into consideration. For example, it’s better to share zip files with Windows users. If you’re sharing the archive with Linux users, then it won’t matter as much. Users of both systems usually need extra software if they’re going to extract the contents of a 7z, rar, or zstd file.

Remember your target audience when you compress files, and think about whether or not the users will have an easy time extracting files from the archive. Of course, if these files are for your eyes only, then this may not matter at all.

Conclusion

After taking benchmark results and compatibility into consideration, the answer to “which compression tool is best?” is just it depends. Are you in a hurry? Does every last megabyte count? Can users easily open your archive? It’s always going to depend on these factors. Using the information in this guide should help you make the right choice, but the “right choice” may change in different situations.

1 thought on “What Is the Best Compression Tool in Linux?”

  1. Mauricio Lopez

    Great article!
    I’m using GNU tar v1.30 in AlmaLinux 8 so I need to use tar --use-compress-program zstd -cf directory.tar.zst directory/ instead of tar --zstd

    Regards,
    Mauricio

Leave a Comment

Your email address will not be published. Required fields are marked *