Close Menu
    X (Twitter)
    Hectic GeekHectic Geek
    • Apps
      • Apps for Mac
      • Apps for PCs
      • Best Apps
    • Concepts
      • Comparison
      • For Geeks
      • IT Careers
    • Gadgets
      • Accessories
      • Best Work Laptops
      • Budget Laptops
    • GNU/Linux
      • Ubuntu
    • How To
      • Virtualization
      • Windows
      • Windows How-To
    Hectic GeekHectic Geek
    Home » pigz: Multithreaded File Compression tool for Ubuntu Linux
    Ubuntu

    pigz: Multithreaded File Compression tool for Ubuntu Linux

    GayanBy GayanApril 18, 2012Updated:October 1, 201210 Comments4 Mins Read
    Twitter Reddit Telegram WhatsApp Email
    Share
    Twitter Reddit Telegram WhatsApp Email

    If you use the official “GNU Zip” (file compression tool, widely known as “gzip”) for compressing files in the GNU/Linux and have a powerful multi-core (and multithreaded) CPU unit, then just like me (though my CPU unit ain’t that powerful :D), you too might be frustrated by the fact “gzip” only using a single CPU core when running.

    Because, if it used all the available CPU power while running (compressing files that is), then it should speed up the process quite significantly. But, it does not do that. Luckily though, just like with the previously discussed “pbzip2” utility, there’s a tool called “pigz” which basically is the multithreaded version of the “gzip” utility.

    So, if you have a multicore CPU unit, and need to compress files as fast as possible, by using all of your available CPU cores, then “pigz” will come in handy.

    Main features …

    *. By default, “pigz” will automatically detect your CPU cores and threads and will adjusts itself, so at the end, all of your CPU cores will be used while compressing.

    However, if you don’t like to use all the available CPU cores (say for maintaining a stable system), then you can tell “pigz” to use only a certain number of cores instead.

    *. According to its manual page, it’s the “almost compatible” version of “gzip”. Meaning that all the commands used in “gzip” are usable in “pigz”. It also has few additional ones as well.

    *. Just like with “gzip”, “bzip2” or many other compression tools in GNU/Linux, “pigz” only compresses single files. Thus, if you have a folder, then you’ll have to put it into a single file container such as ‘tar’, before you can compress it using “pigz”.

    Installation …

    You can install “pigz” in Ubuntu 12.04 Precise Pangolin, 11.10 Oneiric Ocelot, 11.04 Natty Narwhal, 10.10 and 10.04 by using the below command in your Terminal window.

    sudo apt-get install pigz

    How to use it?

    Now I’m assuming that you are already comfortable with ‘gzip’. And as said before,”pigz” has the exact same functionality of “gzip”, so you can use it as you’d do with “gzip”.

    But, since it has few options of its own, you can use the below command for getting a list of supported commands.

    pigz –help

    If you want to read its manual (nothing much to read there), use the below one instead.

    man pigz

    A simple example ….

    Compressing …

    If you’re someone a bit new, then below is a simple example of compressing a file named “testing”.

    pigz –best -k testing

    At the end, it’ll output a file named “testing.gz”, in the same directory. But please remember to replace your source file’s name and its path with “testing”, (the “-k” parameter is used not to let “pigz” to delete the source file and “–best” means using the best possible compression levels).

    Decompressing …

    Decompression is pretty easy as the default file compression tool that comes with Ubuntu (called “File Roller”) or almost all the other GUI tools available in the GNU/Linux platform, should be able to read and extract the archives created by “pigz” as it’s based on the “gzip”.

    However, if you’d like to use “pigz” for decompressing as well, then …

    To decompress (extract) the above mentioned compressed file, I’ll use the below command.

    pigz -d testing.gz

    Again, make sure to replace “testing.gz” with your source file name and its path.

    I can’t compress folders, why?

    As mentioned before, you cannot compress folders with “pigz” as it only supports dealing with single files.

    So as a fix, first you’ll have to use the “tar” utility (built into your GNU/Linux distribution) to put that folder and its content into a single file (not compressing it, just coping the content into a single file, almost like an another folder) and then you can compress that file with “pigz”.

    Example …

    Let’s say that I have a folder called “temp”, then I’ll use the below command in my Terminal to put that folder and its content into a single file called “my-single-file”. Make sure to replace “temp” & “my-single-file” with your desired files and their locations. Don’t change anything else.

    tar -cf my-single-file temp

    Then later you can use the “my-single-file” with “pigz” and compress it. That’s it.

    Share. Twitter Reddit Telegram WhatsApp Email
    Gayan

    An RHCE, 'Linux' user with 14+ years of experience. Extreme lover of Linux and FOSS. He is passionate to test every Linux distribution & compare with the previous release to write in-depth articles to help the FOSS community.

    Related Posts

    How to Check Linux CPU Usage?

    February 5, 2024

    Linux export Command: A Comprehensive Tutorial

    February 3, 2024

    Debian vs Ubuntu Server: A Brief Comparison for Beginners

    July 2, 2023

    CPU Based Simple System Stability and Benchmark Tester for Ubuntu Linux – systester

    June 16, 2023

    Typespeed: Typing Speed Testing Game for Ubuntu Linux

    March 12, 2023

    Debian vs Ubuntu in 2023- Which Linux OS is Right for You?

    January 6, 2023

    10 Comments

    1. John Holdsworth on May 21, 2013 3:34 am

      There is a multi-threaded version of tar itself here: https://github.com/johnno1962/mtar

      Reply
    2. nixperson on January 15, 2015 2:00 pm

      Thanks for sharing this. Been interesting in the topic for quite awhile though finally getting around to messing with it further. Much appreciated and imo, very well written. Thanks again …

      Reply
      • Gayan on January 15, 2015 2:48 pm

        You’re welcome, and thank you for the kind words 🙂 .

        Reply
    3. Ian on October 15, 2015 7:45 am

      But when you decompress the pigz you get a single file, how do you use tar to get it back to multiple files again?

      Reply
      • Ian on October 15, 2015 7:47 am

        Nevermind! tar -xvf file-name did the trick!

        Reply
        • Gayan on October 15, 2015 8:05 am

          🙂 .

          Reply
    4. jsage on December 25, 2015 4:07 am

      If you have multiple files and you’d prefer not to make an interim temp file you can use the tar command without the -f option to write to stdout instead of file and then pipe that as stdin to pigz (where the -p flag sets the number of CPUs to use) rather than giving it a file path input and write out to a file like so:

      tar -cv [file name(s)/dir name(s)] | pigz -p 4 > [filename.tar.gz]

      Reply
      • Gayan on December 25, 2015 7:03 am

        Thank you.

        Reply
    5. him26 on December 13, 2016 11:30 am

      is there a way to pipe pbzip2 and pigz or the other way?

      Reply
    6. Sam Patterson on December 24, 2019 6:09 am

      Thanks for explaining pigz

      Reply
    Leave A Reply Cancel Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Latest Posts

    Transforming Geek Culture with Advanced Software Development

    April 8, 2024

    The Role of Technology in Enhancing Digital Signage Solutions

    February 21, 2024

    How to Check Linux CPU Usage?

    February 5, 2024

    Linux export Command: A Comprehensive Tutorial

    February 3, 2024

    [Fixed] HDMI No Signal to TV or Monitor on Windows 10/11

    November 7, 2023

    AlmaLinux vs Ubuntu – How to Select the Best One?

    October 22, 2023

    Subscribe to Updates

    Get the latest news and updates from Hectic Geek. We won't overload you or sell your data!

    Contact
    • About Us
    • Contact Us
    • Privacy Policy
    • Write for Us
    X (Twitter)
    © 2026 Hectic Geek.

    Type above and press Enter to search. Press Esc to cancel.