How to Compress Files Faster with Pigz Tool in Linux - GeeksforGeeks

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 in your Linux system using the following command:
$ sudo apt install pigz
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.
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.
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
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
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
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.
$ time gzip <file name>
$ time pigz <file name>
$ time gzip -d test.tar.gz
$ time pigz -d test.tar.gz
We can clearly see that in both the vases of compression and decompression pigz is faster than gzip.
How To
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Install FFmpeg on Windows?
How to Set Git Username and Password in GitBash?
How to Add External JAR File to an IntelliJ IDEA Project?
How to Install Jupyter Notebook on MacOS?
How to Create and Setup Spring Boot Project in Eclipse IDE?
Sed Command in Linux/Unix with examples
AWK command in Unix/Linux with examples
grep command in Unix/Linux
cut command in Linux with examples
TCP Server-Client implementation in C