Home Linux Commandline Tools How to Install Pigz to Compress Files Faster in Linux

How to Install Pigz to Compress Files Faster in Linux

File compression and decompression is an important milestone for any Linux user. It saves you some significant storage space when dealing with sizable data. Also, we cannot overlook the data security implementations successfully contributed by reputable file compression tools.

Compressed files are safer from data corruption and compromise than uncompressed files. The success of file compression and decompression depends on the tool you use for the task.

Pigz (parallel implementation of gzip) is one such tool. The free and open-source nature of Pigz is not the only attribute that contributes to it being a dependable file compression and decompression tool. It is also reputably fast in delivering this functionality.

[ You might also like: How to Gzip Large (100GB+) Files Faster in Linux ]

Pigz is an upgrade from the gzip utility due to its use of multiple cores and processors (through threads) to implement its swift data compression and decompression algorithm.

Install Pigz in Linux

Depending on the Linux operating system distribution you chose to use, you can install pigz on your Linux system from one of the following commands:

$ sudo apt-get install pigz     [On Debian, Ubuntu and Mint]
$ sudo yum install pigz         [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
$ sudo emerge -a app-arch/pigz  [On Gentoo Linux]
$ sudo pacman -S pigz           [On Arch Linux]
$ sudo zypper install pigz      [On OpenSUSE]    

Using Pigz to Compress and decompress Files

There is a valid reason for the naming convention of pigz i.e. parallel implementation of gzip. Whenever an input file is availed for compression, pigz first analyzes the file’s size before splitting it into 128kb chunks. Afterward, the split file chunks are then compressed in parallel. The resulting compressed file acquires a .gz file extension format.

Compress File Using Pigz

Let us try to compress a 370MB iso file (win_xp.iso) using gzip.

$ sudo pigz win_xp.iso

The resulting compressed file will be saved under the name win_xp.iso.gz. Also, the above command deletes the original iso file (win_xp.iso).

$ ls -l win_xp.iso.gz
Check Compressed File Size
Check Compressed File Size

If you want to retain both the original and compressed files, your compression command should resemble the following:

$ sudo pigz -k win_xp.iso

View Contents of Compressed File Using Pigz

To list an archived file’s content, your pigz command should be implemented in the following manner:

$ sudo pigz -l win_xp.iso.gz

Compressing Directories Using Pigz

Since we cannot directly compress directories through a single pigz command, we can combine this command with the tar command to achieve the needed directory compression.

$ sudo tar cf – pay/ | pigz > pay.tar.gz

Decompressing Compressed Files Using Pigz

You can use either of the following command implementations.

$ sudo pigz -d win_xp.iso.gz
or
$ sudo unpigz win_xp.iso.gz

Pigz Compression Methods

There are four useful pigz compression methods that are applicable to file size and level of compression a Linux user may wish to attain.

1. The best/highest file compression that takes more time to complete is implemented in the following manner:

$ sudo pigz -9 win_xp.iso  

2. The lowest file compression takes less time to complete and is implemented in the following manner:

$ sudo pigz -1 win_xp.iso 

3. No compression method will only archive your files.

$ sudo pigz -0 win_xp.iso

4. It is the default compression method already demonstrated.

$ sudo pigz -6 win_xp.iso

Changing the Pigz File Compression Format

If you want the format of the resulting compressed file to change from gzip (.gz) to something like zlib (.zz), reference the following command implementation:

$ sudo pigz -k -z win_xp.iso

If we want the resulting file compression to attain a zip format, the command to use looks like the following:

$ sudo pigz -k -K win_xp.iso

If we want pigz to use 4 processors, attain the best compression, and retain the original file, its command implementation will look similar to the one below.

$ sudo pigz -9 -k -p4 win_xp.iso

More on the usage of pigz compression and decompression tool can be found from its man pages or help section by running the following commands on your Linux terminal.

$ man pigz
or 
$ pigz --help
Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.