Skip to content
Related Articles

Related Articles

Improve Article

How to Compress Files Faster with Pigz Tool in Linux

  • Last Updated : 28 Jul, 2021

Pigz (parallel implementation of gzip) is a free, open-source multi-threaded compression software for Linux that compresses and uncompresses files. Pigz is pronounced as “pig-zee”, it compresses data using the zlib and pthread libraries and takes full advantage of many processors and cores. Pigz can archive larger files significantly quicker than gzip since it compresses using threads to make use of multiple CPUs and cores. To put it another way, pigz performs the same thing as gzip, but it distributes the work across multiple processors and cores while compressing, considerably speeding up the compression/decompression process. Let’s look at how to use Pigz in Linux to compress and decompress files in parallel.

Install Pigz On Linux

Install Pigz in your Linux system using the following command:

$ sudo apt install pigz

Compressing And Decompressing Files

Pigz breaks the input file into 128 KB chunks and compresses each one in turn. The compressed data is created in the gzip, zlib, or single-entry zip formats using the deflate compression method. It compresses files in the gzip (.gz) format by default.

Compressing files

For compressing a single file in a zip format, use the following syntax.



$ pigz archlinux-2021.07.01-x86-64.iso

The above command will compress the specified file, archlinux.iso, and save it in the current working directory as archlinux.iso.gz.

Please note that after compressing archlinux.iso, the above operation will erase the original file. Use -k (keep) to tell Pigz not to remove the original file after processing it if you don’t want it to be deleted.

Compressing a Directory

Pigz does not have the ability to compress a folder by itself; it only compresses single files. Pigz is used in conjunction with the tar command for zip the directories as a workaround.

$ tar --use-compress-program="pigz -k " -cf test.tar.gz test

How to Limit the Number of Processors While Compressing

Pigz, as previously stated, takes full advantage of several CPUs and cores while compressing files. The -p switch can be used to change this behavior.

The following command, for example, will compress a file using the best compression algorithm and four processors while keeping the original file:

$ pigz -9 -k -p4 archlinux-2021.07.01-86x_64.iso



Check Content of Compressed File

Use the -l flag to list the contents of the above-archived file without extracting it.

$ pigz -l archlinux-2021.07.01-x86-64.iso.gz

Decompress files

Use the -d option or the unpigz command to decompress a file or directory with pigz. The command for our compressed ISO file will be:

$ unpigz archlinux-2021.07.01-x86-64.iso.gz
or
$ pigz -d archlinux-2021.07.01-x86-64.iso

So, if you have a contemporary multi-processor, multi-core machine and want to compress larger files as quickly as possible while utilizing all of your CPU cores, pigz is an excellent option! Give it a shot and let us know what you think of the Pigz compression application in the comments below.

Comparison between Pigz vs Gzip

Compression using Gzip:

$ time gzip <file name>

Compression using Pigz:

$ time pigz <file name>

Decompression using Gzip:

$ time gzip -d test.tar.gz

Decompression using Pigz:

$ time pigz -d test.tar.gz

We can clearly see that in both the vases of compression and decompression pigz is faster than gzip.

My Personal Notes arrow_drop_up
Recommended Articles
Page :