1. Home
  2. Linux
  3. Compress files linux

How to compress files on Linux faster with Pigz

Pigz is one of the best tools for compressing files into archives. The reason? It’s incredibly fast and efficient. It can perform much better than a lot of the other compression programs available. In this guide, we’ll show you how to set up Pigz on your Linux PC. We’ll also go over how to extract the files you compress using the terminal.

Installing Pigz on Linux

Pigz is an excellent program, but unfortunately, it does not come pre-installed on any mainstream Linux operating systems. As a result, before we can go over how to use the Pigz tool, we must demonstrate how to set up the program on your computer.

To start the installation of Pigz on Linux, launch a terminal window by pressing Ctrl + Alt + T or Ctrl + Shift + T on the keyboard. Then, when the terminal window opens, follow the command-line installation instructions to get the Pigz application working.

Ubuntu

On Ubuntu, the Pigz program is easy to get working. Just use the Apt command below.

sudo apt install pigz

Debian

If you’re using Debian, you will be able to install the Pigz compression tool using the following Apt-get command.

sudo apt-get install pigz

Arch Linux

If you’re using Arch Linux, you will be able to get Pigz working via the Pacman command below.

sudo pacman -S pigz

Fedora

On Fedora Linux, the Pigz app can be set up and installed using the Dnf command below.

sudo dnf install pigz

OpenSUSE

Need to get Pigz working on OpenSUSE Linux? Install it on the system by making use of the following Zypper command.

Using Pigz to compress files

Pigz is excellent with compression because of its ease of use. Unlike other compression tools, you don’t need to specify a ton of different program options to compress files. Just use the pigz command and the file you’d like to compress.

In this section of the guide, we’ll show you how to use Pigz to compress files. To start the compression process, open up a terminal window by pressing Ctrl + Alt + T or Ctrl + Shift + T on the keyboard. When the terminal window is open, run the ls command to view the contents of your home directory (~).

ls

After running the ls command, you will see a complete output of everything in your home directory. This means your Documents, Music, Videos, Pictures, Downloads folder, as well as other folders and files.

Look through these folders and files for the item you wish to compress. If this item is a single file, for example, you can compress it by using the following command-line example.

pigz my-file-to-compress.filetype

Running a compression command with Pigz is fast, but if you have a large file, it’ll still take time. Sit back and be patient and wait for it to complete.

Usually, when you compress a file using the Pigz command, it’ll make use of the GZ format. This format is excellent for Linux and even Mac. However, it won’t work on Windows that well. Thankfully, you can also compress files via Pigz in the Zip format.

To compress something in Pigz to Zip, you need to run the compression command using the -k option switch.

pigz -k my-file-to-compress.filetype

Much like the GZ archive compression, keep in mind that although Pigz is pretty fast, a large file might take a bit of time to complete.

Compressing multiple files

Pigz, while excellent, does not support compressing folders. So, if you want to compress many different files all at once, you’ll have to do it using the wildcard function in Bash.

For example, if you have a ton of MP4 files, and they all need to be compressed, you can simply run the command below.

pigz *.mp4

When the command above is run, Pigz will have generated a GZ compressed archive of every single MP4 file in the folder you run the command. It’s not an ideal solution, and the Pigz compression tool is more about quickly compressing a single file, but if you’re a huge fan of Pigz, feel free to give it a try!

Extracting files

The Pigz program can compress files in two file formats: GZ and Zip. If you’ve previously compressed these files and are now looking to extract them, here’s how to do it in the terminal.

First, place the GZ or Zip file you wish to extract in the home directory using the Linux file manager. After the file is in the home directory, make use of either the unzip or tar commands to extract the contents of the file.

To extract a GZ file, make use of the tar command with the xvf options.

tar xvf my-pigs-file.gz

If you need to extract a Zip archive, make use of the Unzip program.

unzip my-pigs-file.zip

After the command runs, the contents of the archive will be in the home directory.