Similarities and differences between gzip and bzip2

This tutorial explains the gzip and bzip2 commands' options along with their descriptions. Learn the similarities and differences between the gzip and bzip2 Linux commands in detail.

A compressed file not only uses less disk space but consumes less memory and network bandwidth when moved to another location. Linux has many compression utilities. Among them, in this tutorial, we will discuss the similarities and differences between the two most popular utilities; gzip and bzip2. Later we will also discuss which utility provides more compression ratio and speed.

To learn how to use the gzip and bzip2 commands through practical examples, please check the first part of this article. This tutorial is the second and last part of the article. The first part of this article is the following.

How to use gzip and bzip2 Linux commands Explained

Similarities and differences between the gzip and bzip2

The following table lists the similarities and differences between the gzip and bzip2 commands based on their supported options.

Short option Long option Supported command Description
-h --help Both List all supported options.
-d --decompress Both Decompress the compressed file.
-f --force Both Overwrite the existing output file.
-t --test Both Test the compressed file's integrity.
-c --stdout Both Write the output to the standard output device.
-q --quiet Both Don’t display non-critical errors and warnings.
-v --verbose Both Display verbose messages.
-L --license Both The bzip2 displays both the software version and license information. The gzip displays License information only.
-V --version Both The bzip2 displays both software version and license information. The gzip shows version information only.
-1 --fast Both The bzip2 sets block size to 100k. The gzip compresses faster.
-9 --best Both The bzip2 sets block size to 900k. The gzip compresses better.
-z --compress bzip2 only Force compression.
-k --keep bzip2 only Keep the original file.
-s --small bzip2 only Use less memory.
-l --list gzip only Display the compressed and decompressed size.
-n --no-name gzip only Do not save or restore the original name and time stamp.
-N --name gzip only Save or restore the original name and time stamp.
-r --recursive gzip only Operate recursively on directories.
-S --suffix=SUF gzip only Use suffix SUF on compressed files.

As we can see in the above table: -

  • The options -h, -d, -f, -t, -c, -q and -v similarly work in both commands.
  • The options -1, -9 -L and -V work slightly different in both commands.
  • The options -z, -k and -s work only in the bzip2 command.
  • The options -l, -n, -S, -N and -r work only in the gzip command.

Besides command line-options, there are a few more differences between both commands. The following table lists those differences.

Differences between gzip command and bzip2 command

The gzip command The bzip2 command
It uses the DEFLATE algorithm. It uses the Burrows-Wheeler block sorting algorithm.
To denote the compressed file, it uses the extension .gz. To denote the compressed file, it uses the extension .bz2.
It compresses files at a higher speed in comparison with the bzip2 command. It provides a higher compression ratio in comparison with the gzip command.
It doesn’t provide any inbuilt functionality or associate program to recover the damaged .gz files. It provides an additional program called bzip2recover that can recover the damaged .bz2 files.
For decompression, it provides the utility gunzip. For decompression, it provides the utility bunzip2.
It supports recursive compression. It doesn’t support recursive compression.
The gzip vs bzip2 which utility provides a higher compression ratio

The bzip2 provides a higher compression ratio but takes more time in compression. To verify this, let’s compress a file with both commands and compare the file size of the compressed file.

The following image shows the actual size of a file named file_a and the file size after the compression from both utilities.

similarities and differences between gzip and bzip2

As you can see in the above image the file compressed with the gzip utility is larger than the file compressed with the bzip2 utility.

It verifies that the bzip2 utility provides more compression ratio than the gzip utility. If you need more proof, you can perform the same compression with the -v option. The -v option displays the compression ratio in the percentage.

comparing zip and bzip2

As you can see in the above image when the file file_a was compressed with the bzip2 utility, the compression ratio was 62.58% while the same file was compressed with the gzip utility, the compression ratio was 61.6%. It confirms that the bzip2 provides a higher compression ratio.

That all for this part. If you like this tutorial, please don't forget to share it with friends through your favorite social network.

Advertisements

ComputerNetworkingNotes Linux Tutorials Similarities and differences between gzip and bzip2