How to Compress Files Faster with Pigz Tool in Linux
Last Updated :
28 Jul, 2021
Pigz (parallel implementation of gzip) is a free, open-source multi-threaded compression software for Linux that compresses and uncompresses files. Pigz is pronounced as "pig-zee", it compresses data using the zlib and pthread libraries and takes full advantage of many processors and cores. Pigz can archive larger files significantly quicker than gzip since it compresses using threads to make use of multiple CPUs and cores. To put it another way, pigz performs the same thing as gzip, but it distributes the work across multiple processors and cores while compressing, considerably speeding up the compression/decompression process. Let's look at how to use Pigz in Linux to compress and decompress files in parallel.
Install Pigz On Linux
Install Pigz in your Linux system using the following command:
$ sudo apt install pigz

Compressing And Decompressing Files
Pigz breaks the input file into 128 KB chunks and compresses each one in turn. The compressed data is created in the gzip, zlib, or single-entry zip formats using the deflate compression method. It compresses files in the gzip (.gz) format by default.
Compressing files
For compressing a single file in a zip format, use the following syntax.
$ pigz archlinux-2021.07.01-x86-64.iso
The above command will compress the specified file, archlinux.iso, and save it in the current working directory as archlinux.iso.gz.
Please note that after compressing archlinux.iso, the above operation will erase the original file. Use -k (keep) to tell Pigz not to remove the original file after processing it if you don't want it to be deleted.
Compressing a Directory
Pigz does not have the ability to compress a folder by itself; it only compresses single files. Pigz is used in conjunction with the tar command for zip the directories as a workaround.
$ tar --use-compress-program="pigz -k " -cf test.tar.gz test

How to Limit the Number of Processors While Compressing
Pigz, as previously stated, takes full advantage of several CPUs and cores while compressing files. The -p switch can be used to change this behavior.
The following command, for example, will compress a file using the best compression algorithm and four processors while keeping the original file:
$ pigz -9 -k -p4 archlinux-2021.07.01-86x_64.iso

Check Content of Compressed File
Use the -l flag to list the contents of the above-archived file without extracting it.
$ pigz -l archlinux-2021.07.01-x86-64.iso.gz

Decompress files
Use the -d option or the unpigz command to decompress a file or directory with pigz. The command for our compressed ISO file will be:
$ unpigz archlinux-2021.07.01-x86-64.iso.gz
or
$ pigz -d archlinux-2021.07.01-x86-64.iso
So, if you have a contemporary multi-processor, multi-core machine and want to compress larger files as quickly as possible while utilizing all of your CPU cores, pigz is an excellent option! Give it a shot and let us know what you think of the Pigz compression application in the comments below.
Comparison between Pigz vs Gzip
Compression using Gzip:
$ time gzip <file name>

Compression using Pigz:
$ time pigz <file name>

Decompression using Gzip:
$ time gzip -d test.tar.gz

Decompression using Pigz:
$ time pigz -d test.tar.gz
We can clearly see that in both the vases of compression and decompression pigz is faster than gzip.
Similar Reads
How to Compress Files in Linux | Tar Command
File compression is a fundamental task in managing and transferring data efficiently on a Linux system. The Tar command, short for Tape Archive, is a powerful tool that allows users to create compressed and archived files. In this comprehensive guide, we will explore the various options and examples
11 min read
XZ (Lossless Data Compression) Tool in Linux with Examples
xz is a general-purpose data compression and decompression command-line tool. It is similar to gzip and bzip2. It can be used to compress and decompress the files. The native file format of xz is .xz. But it can also support other various formats to compress or decompress files.xz gives us complete
7 min read
How to Copy a File to Multiple Directories in Linux
In this article, we will discuss how to copy a file to multiple directories in Linux. xargs, find, tee, shell loop, and parallel are the commands that can help you to copy a File to Multiple Directories. Suppose we have a file with the name "xyz.txt" and we want to copy it into 3 directories with th
5 min read
How to compress file in Linux | Compress Command
Linux, renowned for its powerful command-line utilities, provides users with various tools to streamline file management tasks. One such tool, the compress `command`, is specifically designed to compress individual files, reducing their size for efficient storage and transfer. In this comprehensive
5 min read
How to Create a Password Protected ZIP File in Linux?
Linux provides Zip command to work with a file like compressing the file and decompressing with a password. It's not come with built-in you need to install from an external source. The Zip command has two different utility(zip and unzip). zip is used for compressing the file and unzip is used for de
2 min read
How to Compress and Extract Files Using the tar Command on Linux
Tar archives are special files that bundle multiple files and directories into a single file, making it easier to store, share, and manage. While tar archives themselves are not compressed, they can be combined with various compression utilities to reduce their size. The tar command is highly versat
3 min read
Split Command in Linux with Examples
Split command in Linux is used to split large files into smaller files. It splits the files into 1000 lines per file(by default) and even allows users to change the number of lines as per requirement. The names of the files are PREFIXaa, PREFIXab, PREFIXac, and so on. By default the PREFIX of files
6 min read
How to Unrar Files in Linux
The RAR file format is popularly used to compress large files, thus allowing users to share and store them easily. Now, while we often see TAR and GZIP file formats in Linux, one might cross paths with RAR files too. In this article, we will learn how to unrar files in Linux in detail. Installing th
6 min read
Fcrackzip Tool - Crack a Zip File Password in Kali Linux
The fcrackzip utility and wordlists are included by default in Kali to crack passwords for these compressed files. Because of their compact size and encryption algorithm, we frequently use zipped files. These zipped files have a password protection feature that ensures the files' confidentiality. Wh
3 min read
time command in Linux with examples
'time' command in Linux is used to execute a command and prints a summary of real-time, user CPU time and system CPU time spent by executing a command when it terminates. 'real' time is the time elapsed wall clock time taken by a command to get executed, while 'user' and 'sys' time are the number of
6 min read