Decompression

A tar.gz archive

The standard[30] compression format under UNIX systems is the gzip format, developed by the GNU project, and considered as one of the best general compression tools.

gzip is often associated with a utility named tar. tar is a survivor of antediluvian times, when computerists stored their data on tapes. Nowadays, floppy disks and CD-ROM have replaced tapes, but tar is still being used to create archives. All the files in a directory can be appended in a single file for instance. This file can then be easily compressed with gzip.

This is the reason why much free software is available as tar archives, compressed with gzip. So, their extensions are .tar.gz (or also .tgz to shorten).

The use of GNU Tar

To decompress this archive, gzip and then tar can be used. But the GNU version of tar (gtar) allows us to use gzip on-the-fly, and to decompress an archive file without noticing each step (and without the need for the extra disk space).

The use of tar follows this format:

    tar <file options> <.tar.gz file> [files] 
   

The <files> option is not required. If it is omitted, processing will be made on the whole archive. This argument does not need to be specified to extract the contents of a .tar.gz archive.

For instance:

    $ tar xvfz guile-1.3.tar.gz
    -rw-r--r-- 442/1002      10555 1998-10-20 07:31 guile-1.3/Makefile.in
    -rw-rw-rw- 442/1002       6668 1998-10-20 06:59 guile-1.3/README
    -rw-rw-rw- 442/1002       2283 1998-02-01 22:05 guile-1.3/AUTHORS
    -rw-rw-rw- 442/1002      17989 1997-05-27 00:36 guile-1.3/COPYING
    -rw-rw-rw- 442/1002      28545 1998-10-20 07:05 guile-1.3/ChangeLog
    -rw-rw-rw- 442/1002       9364 1997-10-25 08:34 guile-1.3/INSTALL
    -rw-rw-rw- 442/1002       1223 1998-10-20 06:34 guile-1.3/Makefile.am
    -rw-rw-rw- 442/1002      98432 1998-10-20 07:30 guile-1.3/NEWS
    -rw-rw-rw- 442/1002       1388 1998-10-20 06:19 guile-1.3/THANKS
    -rw-rw-rw- 442/1002       1151 1998-08-16 21:45 guile-1.3/TODO
    ...
   

Among the options of tar:

  • v makes tar verbose. This means it will display all the files it finds in the archive on the screen. If this option is omitted, the processing will be silent.

  • f is a required option. Without it, tar tries to use a tape instead of an archive file (i.e., the /dev/rmt0 device).

  • z allows you to process a “gziped” archive (with a .gz extension). If this option is forgotten, tar will produce an error. Conversely, this option must not be used with an uncompressed archive.

tar allows you to perform several actions on an archive (extract, read, create, add...). An option defines which action is used:

  • x: allows you to extract files from the archive.

  • t: lists the contents of the archive.

  • c: allows you to create an archive. You may use it to backup your personal files, for instance.

  • r: allows you to add files at the end of the archive. It cannot be used with a compressed archive.

Bzip2

A compression format named bzip2 has already replaced gzip in general use, though some software is still distributed in gzip format, mainly for compatibility reasons with older systems. Almost all free software is now distributed in archives which use the .tar.bz2 extension.

bzip2 is used like gzip by means of the tar command. The only change is to replace the letter z by the letter j. For instance:

    $ tar xvjf foo.tar.bz2
   

Some distributions may still use the option I instead:

    $ tar xvfI foo.tar.bz2
   

Another way (which seems to be more portable, but is longer to type!):

    $ tar --use-compress-program=bzip2 -xvf foo.tar.bz2
   

bzip2 must be installed on the system in a directory included in your PATH environment variable before you run tar.

Just do it!

The easiest way

Now that you are ready to decompress the archive, do not forget to do it as administrator (root). You will need to do things that a ordinary user is not allowed to do, and even if you can perform some of them as a regular user, it is simpler to just be root the whole time, even if it might not be very secure.

The first step is to be in the /usr/local/src directory and copy the archive there. You should then always be able to find the archive if you lose the installed software. If you do not have a lot of space on your disk, save the archive on a floppy disk after having installed the software. You can also delete it but be sure that you can find it on the web whenever you need it.

Normally, decompressing a tar archive should create a new directory (you can check that beforehand thanks to the t option). Go then in that directory. You are now ready to proceed further.

The safest way

UNIX systems (of which GNU/Linux and FreeBSD are examples) can be secure systems. That means that normal users cannot perform operations that may endanger the system (format a disk, for instance) or alter other users' files. It also immunizes the system against viruses.

On the other hand, root can do everything - even running a malicious program. Having the source code available allows you to examine it for malicious code (viruses or Trojans). It is better to be cautious in this regard[31].

The idea is to create a user dedicated to administration (free or admin for example) by using the adduser command. This user must be allowed to write in the following directories: /usr/local/src, /usr/local/bin and /usr/local/lib, as well as all the sub-trees of /usr/share/man (he also may need to be able to copy files elsewhere). We recommend that you make this user owner of the necessary directories or create a group for him and make the directories writable by the group.

Once these precautions are taken, you can follow the instructions in the section called “The easiest way”.



[30] On GNU/Linux nowadays the standard is the bzip2 format. bzip2 is more efficient on text files at the cost of more computing power. Please refer to the section called “Bzip2”, which deals specifically with this program.

[31] A proverb from the BSD world says: “Never trust a package you don't have the sources for.