Even if it’s one of the faster archiving/compression solutions available, gzip has a tiny problem: it doesn’t support multiple processors/cores. Thus, if you have a relatively new PC, it doesn’t take advantage of its capabilities. Pigz is a multi-threaded implementation of gzip that allows you to compress files to the GNU zip format at a fraction of the time. Here is 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’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.
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.
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.
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
Our latest tutorials delivered straight to your inbox