Installation

To install pigz on Ubuntu, Mint, and other Debian-compatible distributions, use: On Arch and Manjaro Linux, install it with: If you’re using openSUSE, try:

Compress a Single File

To compress any file to GNU Zip format with pigz, use: For some, it may be a problem that, by default, pigz deletes the original file after the compression. If you want to keep it, you must use the -k switch (notice that it’s lowercase). Pigz supports multiple levels of compression, and you can choose between them by stating their number after a dash. For example: You can use numbers from 1 to 9, with “1” offering the quickest performance but lowest compression and “9” offering the slowest but highest compression.

Compressing Folders

Pigz has a significant restriction: it doesn’t support folders. You can only compress single files with it. A workaround is to use it together with tar. Let’s say you want to compress your “Pictures” folder. Since tar supports the use of external compression programs, you can do the following: In the above command, tar –use-compress-program states that although you will create a file archive with tar, the compression of its contents will happen through an external program. This external program and its parameters are defined with the pigz -k -9 part of the command. Finally, state that you want to Create a File (“-cf”) called “pictures.tar.gz” with everything found in the “Pictures” folder.

Decompressing Files And Folders

Decompressing any gz file with pigz is as simple as entering any of the following commands: In our previously created tar.gz files, decompressing folders uses the same “tar” approach.

Limiting Parallelization

Finally, it should be noted that an extra switch might come in handy: p. Pigz, by default, uses all processors/cores in your computer. When compressing large data sets, this can affect your computer’s responsiveness. With the p switch, you can limit pigz to only use a specific number of processors/cores. This will leave the rest of the cores free for your other tasks and interactivity. To do so, add the number of processors/cores right after the switch: -p2 restricts pigz to only use two processors/cores. You can use any number you like, but it’s suggested that you keep it within your hardware’s limits. To learn more about file compression and extraction in Linux, check out our in-depth guide to Linux’s archiving and compression commands. Image credit: Miguel Á. Padriñán @Pexels