Learn how to Compress Information Quicker with Pigz Device in Linux

Written by Mark Adler, Pigz is an acronym for Parallel Implementation of GZip. It’s a nifty compression software that helps you compress recordsdata with blazing quick speeds. As an enchancment of the nice outdated gzip utility, it leverages a number of cores and processors to compress knowledge.

This information shines extra mild on Pigz and takes you thru how one can use the utility to compress recordsdata in Linux techniques.

Putting in Pigz on Linux Techniques

Putting in Pigz is a stroll within the park as a result of the Pigz package deal is contained in official repositories for main distributions comparable to Debian, and CentOS.

You’ll be able to set up Pigz in a single command in numerous distributions utilizing their respective package deal managers as follows.

$ sudo apt set up pigz [On Debian/Ubuntu]
$ sudo dnf set up pigz [On CentOS/RHEL/Fedora]
$ sudo pacman -S pigz [On Arch/Manjaro Linux]
$ yay -S pigz

Learn how to Compress Information with Pigz

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

$ pigz filename

On this information, we’ll use the file ubuntu-20.04-beta-desktop-amd64.iso for demonstration functions. To compress the file execute:

$ pigz ubuntu-20.04-beta-desktop-amd64.iso

Compress File in Linux

Compress File in Linux

Nevertheless, the command deletes the unique file upon compression as you might need observed. To retain the unique file after compression, run use the -k choice as proven.

$ pigz -k ubuntu-20.04-beta-desktop-amd64.iso

Compress File without Delete

Compress File with out Delete

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

Test Content material of Compressed File in Linux

To examine the contents of the compressed file, together with the statistics on the compression ratio achieved use the -l choice with pigz command:

$ pigz -l ubuntu-20.04-beta-desktop-amd64.iso.gz

View Content of Compressed File in Linux

View Content material of Compressed File in Linux

From the output, you not solely get to see the contents of the zipped file but in addition the share of compression which on this case is 1.9%.

Moreover, you need to use numerous compression ranges that exist from 1 to 9. The next compression ranges are supported:

  • 6 – Default compression.
  • 1 – Quickest however affords the least compression.
  • 9 – Slowest however the very best compression.
  • 0 – No compression.

For instance, to compress the file with the very best compression degree, execute:

$ pigz -9 ubuntu-20.04-beta-desktop-amd64.iso

Learn how to Compress a Listing with Pigz

By itself, Pigz doesn’t have choices to compress a folder, it solely compresses single recordsdata. As a workaround, pigz is used along with tar command to zip directories.

To compress a listing, use the –use-compress-program argument as proven:

$ tar –use-compress-program=”pigz -k ” -cf dir1.tar.gz dir1

Compress a Directory in Linux

Compress a Listing in Linux

Learn how to Restrict the Variety of Processors Whereas Compressing

We talked about earlier that the pigz utility software makes use of a number of cores & processors when compressing recordsdata. You’ll be able to specify the variety of cores for use utilizing the -p choice.

On this instance, beneath, we’ve got used the very best compression (denoted by -9) with four processors (-p4) whereas retaining the unique file (-k).

$ pigz -9 -k -p4 ubuntu-20.04-beta-desktop-amd64.iso

Learn how to Decompress Information utilizing Pigz

To decompress a file or listing utilizing pigz, use the -d choice or the unpigz command.

Utilizing our compressed ISO file, the command might be:

$ pigz -d ubuntu-20.04-beta-desktop-amd64.iso
$ unpigz dir1.tar.gz

Decompress Files in Linux

Decompress Information in Linux

Comparability between Pigz vs Gzip

We went a bit additional and pitted Pigz in opposition to Gzip software.

Listed below are the outcomes:

Gzip Compression

$ time gzip ubuntu-20.04-beta-desktop-amd64.iso

Check Gzip Compression Time

Test Gzip Compression Time

Pigz Compression

$ time pigz ubuntu-20.04-beta-desktop-amd64.iso

Check Pigz Compression Time

Test Pigz Compression Time

Gzip Decompression

$ time gzip -d ubuntu-20.04-beta-desktop-amd64.iso.gz

Check Gzip Decompression Time

Test Gzip Decompression Time

Pigz Decompression

$ time unpigz ubuntu-20.04-beta-desktop-amd64.iso.gz

Check Pigz Decompression Time

Test Pigz Decompression Time

From the comparability, we will clearly see that compression and decompression occasions for Pigz are a lot shorter than Gzip. This suggests that the Pigz command-line software is far quicker than the Gzip software

For extra particulars on the utilization of pigz command, go to the person pages.

$ man pigz

Moreover, run the command beneath to view all of the choices obtainable to be used with pigz command.

$ pigz –help

Pigz Command Help

Pigz Command Assist

And there you have got it. We have now coated the pigz command-line software and confirmed you how one can compress and decompress recordsdata. We went additional and in contrast Pigz with Gzip and discovered that Pigz is the higher of the 2 when it comes to velocity of each compression and decompression. We invite you to present it a shot and inform us the way it went.


Germany Devoted Server

Leave a Reply