How to compress your files faster with pigz

How to compress your files faster with pigz

Even though it is one of the fastest archiving / compression solutions available, gzip has a small problem: it does not support multiple processors / cores. So if you have a relatively new PC, it doesn’t take advantage of its capabilities. Pigz is a multi-threaded implementation of gzip that lets you compress GNU zip files at a fraction of the time. Here’s how to compress your files faster with pigz.


To install pigz on Ubuntu, Mint and other Debian compatible distributions, use:

On Arch and Manjaro Linux, install it with:

If you are using openSUSE, try:

Compress a single file

To compress any file in GNU Zip format with pigz, use:

Ultrafast compression with single Pigz file

For some, this may be an issue which, by default, pigz deletes the original file after compression. If you wish to keep it, you must use the -k switch (note that it is lowercase).

Ultrafast compression with single Pigz Ls file

Pigz supports multiple levels of compression, and you can choose between them by specifying their number after a dash. For example:

You can use numbers from 1 to 9, with “1” offering the fastest performance but the lowest compression and “9” offering the slowest but highest compression.

Ultra-fast compression with high single Pigz file

Compression of files

Pigz has an important restriction: it does not support files. You can only compress single files with it. A workaround is to use it with tar.

Suppose you want to compress your “Images” folder. Since tar supports the use of external compression programs, you can do the following:

In the above command, tar --use-compress-program indicates that although you create an archive of files with tar, the compression of its contents will be done via an external program.

READ:   Elementary OS 5.1 Hera Review

This external program and its parameters are defined with the pigz -k -9 part of the order.

Finally, indicate that you want to create a file (“-cf”) called “images.tar.gz” with everything in the “Images” folder.

Ultra-fast compression with Pigz Tar Directory

Decompressing files and folders

Decompressing any gz file with pigz is as simple as entering one of the following commands:

In our tar.gz files created previously, the decompression of the folders uses the same “tar” approach.

Ultrafast compression with Pigz decompression file

Limit parallelization

Finally, it should be noted that an additional switch can be useful: p. Pigz, by default, uses all of the processors / cores on your computer. When compressing large data sets, this can affect the responsiveness of your computer.

With the p switch, you can limit pigz to use only a specific number of processors / cores. This will leave the rest of the hearts free for your other tasks and your interactivity. To do this, add the number of processors / cores just after the switch:

-p2 restrict pigz to use only two processors / cores. You can use any number you want, but it is suggested that you keep it within the limits of your hardware.

For more information on compressing and extracting files in Linux, see our detailed guide to Linux archive and compress commands.

Image credit: Miguel Á. Padriñán @Pexels


Is this article useful?


More Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed