Pigz stands for “Parallel Implementation of GZip,” which is a compression tool used to compress and uncompress files in Linux. It is written using the most commonly used zipping library functions. Pigz is the improved version of the older gzip utility that leverages multiple cores and processors to compress data. It can be able to archive larger files much faster than with gzip.
In this post, we will show you how to compress and decompress files in parallel using Pigz in Linux.
- A server running Linux on the Atlantic.Net Cloud Platform
- A root password configured on your server
Create Atlantic.Net Cloud Server
First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing any Linux operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.
By default, the Pigz package is included in the default repository of all major Linux distributions.
For Debian and Ubuntu distributions, install the Pigz utility using the following command:
apt-get install pigz -y
For CentOS, Rocky Linux, RHEL, and Fedora distributions, install the Pigz utility using the following command:
dnf install pigz -y
After the installation, verify the Pigz version using the following command:
You will get the following output:
Compress a File with Pigz
To compress a single file with the default options, use the following syntax:
For example, to compress a file named linux.iso, run the following command:
This will compress the linux.iso file and save it as linux.iso.gz in your current working directory. The above command will also delete the original file after compression. If you don’t want to delete the original file, use the -k option:
pigz -k linux.iso
How to Install LFTP to Download and Upload Files in Linux
Compress a Directory with Pigz
Pigz does not provide an option to compress the directory directly. You will need to use the tar command with the Pigz command to compress the directory.
tar cf - /etc/ | pigz > etc.tar.gz
The above command will compress the /etc directory and saves it as etc.tar.gz.
List the Content of the Compress File
You can use the -l option with the Pigz command to list the content of the compressed file:
pigz -l linux.iso.gz
You will get the following output:
compressed original reduced name 228799 209715200 99.9% linux.iso
Define Compression Method
Pigz supports different compression methods during the compression process. You can use any method depending on your needs. Here is the list of different compression methods:
- -9 Slowest and best compression
- -1 Fastest and less compression
- -0 No compression
- -6 Default compression
For example, to compress the file named linux.iso with the “less compression” method, run the following command:
pigz -1 linux.iso
How to Use Zip and Unzip Command in Linux
Change the Compression Format
By default, the Pigz command saves the file in gzip format. You can also use the different options to change the default format.
To compress the file in zlib format, run the following command:
pigz -k -z linux.iso
To compress the file in zip format, run the following command:
pigz -k -K linux.iso
Define Processors During Compression
Pigz allows you to define the number of processors and cores during the file compression. You can use the -p option to define the processor.
pigz -9 -k -p2 linux.iso
This command will compress the file using the best compression method and 2 processors while keeping the original file:
Decompress a File with Pigz
After compressing the file, you can use the pigz -d or unpigz commands to uncompress the file.
For example, to uncompress the file linux.iso.gz, run the following command:
pigz -d linux.iso.gz
In this post, we explained how to use the Pigz command-line utility to compress and uncompress files and directories. If you are using a modern multi-processor, multi-core system and want to compress a large file with the best results, then the Pigz is the best option for you. Try it on dedicated hosts from Atlantic.Net!