ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Linux: File Compression Utilities

    IT Discussion
    sam linux administration linux compression gzip bzip2 system administration unix rhel centos ubuntu suse opensuse scottalanmiller
    3
    8
    3.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by scottalanmiller

      File compression is a common task on any platform. On Linux this is almost always handled by a set of small, discrete utilities. Each utility typically handles a single compression algorithm keeping each as small as possible. The common utilities include gzip, bzip2 and xz.

      Using either of these commands is very simple. They simply require the command the file that we want to compress. Let's look at a file that we have, the du -b command will tell us exactly how big the original file is in bytes.

      $ du -b hostedrpm.out 
      19815	hostedrpm.out
      

      Now let's use gzip to compress this file:

      $ gzip hostedrpm.out 
      $ du -b hostedrpm.out.gz 
      6558	hostedrpm.out.gz
      

      What you should notice in doing this is that the gzip command was very simple and the file that we had was compression and had .gz appended to the end of it. If you look in the directory where you try this, you will notice that the original file has disappeared. This is an "in place" compression process.

      Uncompressing is simple and uses the gunzip command.

      $ gunzip hostedrpm.out.gz
      

      And voila, we have our original file back again, just as it was before. Now we can try this same process with bzip2.

      $ bzip2 hostedrpm.out 
      $ du -b hostedrpm.out.bz2 
      5571	hostedrpm.out.bz2
      

      Here we can see the same process has happened. In this case the file extension appended is .bz2. And to decompress our file again...

      $ bunzip2 hostedrpm.out.bz2
      

      The big difference between gzip and bzip2 is that gzip focuses on being fast while compression levels are normally not that impressive and bzip2 focuses on heavy compression while taking more time. Of course compression and speed varies by the file type, but gzip is almost universally faster (read: uses less CPU time) and bzip2 nearly always compresses a bit better.

      The newcomer is xz which utilises the LZMA compression algorithm, the same as 7Zip. (We can use 7Zip itself on UNIX but 7Zip uses its own packaging format that does not fully support UNIX so it is generally only used to open files made on Windows.) The xz utility works identically to its compression siblings.

      $ xz hostedrpm.out 
      $ du -b hostedrpm.out.xz 
      6144	hostedrpm.out.xz
      
      $ unxz hostedrpm.out.xz 
      

      All of these compression utilities are lossless and can be safely used with any file. By and large, gzip is used for nearly all tasks and has the greatest compatibility across different UNIX variants.


      On Windows, we are used to compression and archiving tools being combined into a single package. This is a great example of how the Windows mindset favours monolithic utilities and UNIX favours modular ones. These utilities only handle compression and decompression of individual files. To get Windows Zip-like functionality we combine these utilities with an archiving utility which we will explore separately. UNIX also has all of the same utilities and functions as Windows which we will cover as well.

      Part of a series on Linux Systems Administration by Scott Alan Miller

      1 Reply Last reply Reply Quote 3
      • dafyreD
        dafyre
        last edited by

        Any particular reason you left tar out of this set?

        DustinB3403D scottalanmillerS 2 Replies Last reply Reply Quote 0
        • DustinB3403D
          DustinB3403 @dafyre
          last edited by

          @dafyre said in Linux: File Compression Utilities:

          Any particular reason you left tar out of this set?

          http://mangolassi.it/topic/9174/linux-using-tar

          dafyreD 1 Reply Last reply Reply Quote 1
          • dafyreD
            dafyre @DustinB3403
            last edited by

            @DustinB3403 said in Linux: File Compression Utilities:

            @dafyre said in Linux: File Compression Utilities:

            Any particular reason you left tar out of this set?

            http://mangolassi.it/topic/9174/linux-using-tar

            I just saw that go up, ha ha ha.

            scottalanmillerS 1 Reply Last reply Reply Quote 0
            • scottalanmillerS
              scottalanmiller @dafyre
              last edited by

              @dafyre said in Linux: File Compression Utilities:

              Any particular reason you left tar out of this set?

              It's not compression 🙂

              1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller @dafyre
                last edited by

                @dafyre said in Linux: File Compression Utilities:

                @DustinB3403 said in Linux: File Compression Utilities:

                @dafyre said in Linux: File Compression Utilities:

                Any particular reason you left tar out of this set?

                http://mangolassi.it/topic/9174/linux-using-tar

                I just saw that go up, ha ha ha.

                I put the placeholder into the main list so that people would see it, as well.

                dafyreD 1 Reply Last reply Reply Quote 0
                • dafyreD
                  dafyre @scottalanmiller
                  last edited by

                  @scottalanmiller said in Linux: File Compression Utilities:

                  @dafyre said in Linux: File Compression Utilities:

                  @DustinB3403 said in Linux: File Compression Utilities:

                  @dafyre said in Linux: File Compression Utilities:

                  Any particular reason you left tar out of this set?

                  http://mangolassi.it/topic/9174/linux-using-tar

                  I just saw that go up, ha ha ha.

                  I put the placeholder into the main list so that people would see it, as well.

                  Odd, I don't remember seeing it. I been up since 5:30am and just got done replacing a UPS, so my brain is still not in gear yet.

                  1 Reply Last reply Reply Quote 0
                  • scottalanmillerS
                    scottalanmiller
                    last edited by

                    It doesn't update as "new" when I just update the list. Only if I comment on the thread.

                    1 Reply Last reply Reply Quote 1
                    • 1 / 1
                    • First post
                      Last post