Get to know Linux: File compression - gHacks Tech News

Get to know Linux: File compression

How many times have you come across a .tar, .tgz, or .bz2 file in Linux and had no idea what to do with it? Or what it was? Most users of computers know what the .zip file is. Simple, it's a compressed file. And to uncompress you generally double click it or right click and select Extract. Most people recognize that from the world of Windows. But did you know that file compression/decompression is just as easy in the world of Linux? It is. The only problem is that most don't recognize what files are, in fact, compressed files, archives, or compressed archives.

In this article I am going to de-mystify Linux file compression and archiving for you. By the end of the article you'll be compressing and decompressing files in your sleep. And, as a bonus, you'll know how to do this both via command line and GUI.

Compression versus archiving

The difference between compression and archiving is simple: Compression makes a file (or directory) smaller and Archiving takes many seperate files (such as a directory containing sub-directories and/or files) and turns it into a single file. You can have a compressed archive (such as .tar.gz or .tgz) and you can even have an archive of compressed files (such as a directory that contains a bunch of compressed files). But how do you know what are compressed files verses archived files? Here's a list of file extensions and what they are.

.tar - This is an uncompressed Tar archive file. This type of archive is unpacked with the command tar xvf file.tar.

.tgz - This is a compressed Tar archive file. This type of archive is decompressed and unpacked with the command tar xvzf file.tgz.

.gz - This is a file compressed with the gzip program. This type of file is decompressed with the command gunzip file.gz.

.zip - This is a compressed file. This type of file is decompressed with the command unzip

.bz2 - This is a compressed file. This type of file is decompressed with the command bunzip2 file.bz2.

Which compression to use?

Of the three compression utilities (bzip2, zip, and gzip) the tool that will result in the most compression (the smallest file) is bzip2. The only disadvantage to bzip2 is that the algorithm uses more processor to complete than does the other utilities.

If you are sharing your compressed files with Windows users your best bet is to use zip for compression. Although there are tools (such as Stuffit Deluxe for Windows) that can handle bz2 files, the default supported is .zip.

Using the GUI

If you are a fan of the GUI (and who isn't these days?) you will be glad to know that most all Linux file managers can handle compressed and archived files. In both Nautilus (GNOME) and Dolphin (KDE) you can simply right click a compressed, archived, or compressed archive file and select Extract. Both file managers also offer compression and archiving options when you right click a file or directory.

Final thoughts

Working with compression and archiving is very simple with the Linux operating system. You have plenty of options in both the command line and the GUI worlds.

  • We need your help

    Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

    We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.

    If you like our content, and would like to help, please consider making a contribution:


    1. Bob said on January 23, 2010 at 6:48 am

      Thanks , you don’t have to hit the road jack ,no more,no more,no more,no more(hope you get it [:)

    2. Giorgos said on January 23, 2010 at 4:04 pm

      I’m using p7zip in Kubuntu and it rocks! ;-)
      (Konsole syntax is the same as windows 7zip).
      Binaries are available too from SF.NET.

    3. Kasi Viswanath said on January 30, 2010 at 3:28 am

      Uncompressing is fine. But I guess you missed showing how to compress/archive a file. Like “tar cvf”, etc…

    4. gbviswanadh said on September 18, 2011 at 1:18 pm

      files are in, and so on i want to unzip and bzip2 to remove as this file in single command , is this possible

      i don’t want as this way in single command to extract

      bzip2 -fd


    Leave a Reply