How to install and use Pigz tool in Linux

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Pigz is an acronym for Parallel Implementation of GZip. It’s a compression tool that helps you compress files with blazing fast speeds. As an improvement of the good old gzip utility, it leverages multiple cores and processors to compress data.

Installing Pigz on Linux

Pigz package is contained in official repositories for major distributions such as Debian, and CentOS.

You can install Pigz in a single command in various distributions using their respective package managers as follows.

On Debian/Ubuntu

$ sudo apt install pigz 


# sudo dnf install pigz  

On Arch/Manjaro

$ sudo pacman -S pigz
$ yay -S pigz 

Compress Files with Pigz

To compress a single file to a zip format use the syntax.

$ pigz filename

In this guide, we will use the file unixcop for demonstration purposes. To compress the file execute:

$ pigz unixcop

However, the command deletes the original file upon compression as you might have noticed. To retain the original file after compression, run use the -k option as shown.

$ pigz -k unixcop

From the output, we can clearly see that the original file has been retained even after compression.

Content of Compressed File in Linux

To check the contents of the compressed file, including the statistics on the compression ratio achieved use the -l option with pigz command:

$ pigz -l unixcop

From the output, you not only get to see the contents of the zipped file but also the percentage of compression which in this case is 0.0%.

Additionally, you can use various compression levels that exist from 1 to 9. The following compression levels are supported:

  • 6 – Default compression.
  • 1 – Fastest but offers the least compression.
  • 9 – Slowest but the best compression.
  • 0 – No compression.

For example, to compress the file with the best compression level, execute:

$ pigz -9 unixcop

Compress a Directory with Pigz

By itself, Pigz does not have options to compress a folder, it only compresses single files. As a workaround, pigz iused in conjunction with tar command to zip directories.

To compress a directory, use the –use-compress-program argument as shown:

tar --use-compress-program="pigz -k " -cf unixcop_dir.tar.gz unixcop_dir/

Limit the Number of Processors While Compressing

We mentioned earlier that the pigz utility tool uses multiple cores & processors when compressing files. You can specify the number of cores to be used using the -p option.

In this example, below, we have used the best compression (denoted by -9) with 4 processors (-p4) while retaining the original file (-k).

$ pigz -9 -k -p4 unixcop

Decompress Files using Pigz

To decompress a file or directory using pigz, use the -d option or the unpigz command.

Using our compressed ISO file, the command will be:

$ pigz -d unixcop.gz
$ unpigz unixcop_dir.tar.gz

Comparison between Pigz vs Gzip

We went a bit further and pitted Pigz against Gzip tool.

Here are the results:

Gzip Compression

$ time gzip unixcop

Pigz Compression

$ time pigz unixcop

Gzip Decompression

$ time gzip -d unixcop.gz

Pigz Decompression

$ time unpigz unixcop.gz

From the comparison, we can clearly see that compression and decompression times for Pigz are much shorter than Gzip. This implies that the Pigz command-line tool is much faster than the Gzip tool

For more details on the usage of pigz command, visit the man pages.

$ man pigz

Furthermore, run the command below to view all the options available for use with pigz command.

$ pigz --help
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"
unixcop Admin


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook