Pigz, compress your files in no time from the terminal

about pigz

In the next article we are going to take a look at pigz. This is a multithreaded gzip implementation that will allow us compress files in a very short time. This tool offers us one more option for compression, since even one of the fastest archiving / compression solutions available such as gzip, has a small problem, and that is that it does not support multiple processors / cores. This means that if we have a relatively new PC, it will not take advantage of all its capabilities.

Pigz, which stands for parallel gzip implementation, is a fully functional replacement for gzip, which exploits multiple processors and multiple cores when compressing data. Pigz was written by Mark Adler and uses libraries zlib and pthread.

Pigz compresses using threads to utilize multiple processors and cores. Each is divided into pieces of 128 KB. Each of them and the individual control value for each slice are calculated in parallel. The compressed data is written in order for the output, and the combined check value is calculated from the individual check values.

Pigz installation on Ubuntu

For install pigz on Ubuntu, Mint, and other Debian-compatible distributions, we will only have to open a terminal (Ctrl + Alt + T) and use the command:

install pigz

sudo apt install pigz

Basic use of pigz

Compress a single file

For compress any file to format GNU Zip with pigz, we will only have to use it in the following way:

compress simple file

pigz NOMBRE_DEL_ARCHIVO

For some, it may be a problem that by default pigz delete original file after compression. If you want to keep it, you must use the -k switch as follows:

compress keeping original file with pigz

pigz -k NOMBRE_DEL_ARCHIVO

Pigz supports multiple levels of compression, and it will allow us to choose between them indicating their number after a hyphen. An example of this would be:

pigz compression level

pigz -9 -k NOMBRE_DEL_ARCHIVO

We can use numbers from 1 to 9. With '1' we will get a faster performance, but with the lowest compression and with '9' we will obtain the slowest, but highest compression.

Compress folders

Pigz has a significant restriction, and that is that it does not support folders. We will only be able to compress files individually. Although we can find an alternative solution, which is to use it together with tar.

If we wanted to compress the folder 'Funds', and since tar supports the use of external compression programs, we could do something like the following:

folder compression

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

In the above command, tar --use-compress-program establishes that Although it will create a file with tar, the compression of its content will be done through an external program, in this case pigz. This external program and its parameters are defined with the part pigz-k-9 of the command. Finally, we will indicate that we want to create a file using '-cf', called'Backgrounds.tar.gz'with everything in the folder'Money/'.

Unzip files and folders

Unzip any .gz file with pigz it's as simple as typing any of the following commands:

pigz -d NOMBRE_DEL_ARCHIVO.gz

unpigz NOMBRE_DEL_ARCHIVO.gz

In the previously created file with a folder with the extension tar.gz, folder decompression uses the same approach 'tar'that we use for compression:

unzip folder

tar --use-compress-program="pigz -d" -xvf NOMBRE_CARPETA.tar.gz

Limiting parallelism

Pigz, by default uses all processors / cores on the computer. When compressing large data sets, this can affect the responsiveness of your computer.

With the p option, we can limit the use to a specific number of processors / cores. This will leave the rest free for your other tasks and interactivity. To do this, you just have to add the number of processors / cores as follows:

limiting parallelization

pigz -k -p2 NOMBRE_DEL_ARCHIVO

-p2 restricts pigz to use only two processors / cores. We can use any number we want, and even if it is obvious, it is important to keep that number within the limits of our hardware.

For more information, users can take a look at the file README or read the page of user manual by pigz.


Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.