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.
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.
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.
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.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.
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.