Archiving and Compressing


gzip is the GNU zip program that can be used to compress files.

It was designed to have better compression than the ‘compress’ command which is provided by many versions of Unix. Files that are compressed with gzip have the file extension .gz normally; while those compressed with ‘compress’ have the file extensions .Z, gzip will uncompress .Z files but not vice versa. It is common to first “tar” files and then compress them afterwards using gzip. These files are normally given the extentions .tar.gz to show that they are tar archives zipped up with gzip. You may also see the extension, .tgz. An archive that is compressed with gzip is compatible with WinZip and 7zip. So, a file zipped up on a UNIX box can be unzipped with a Windows box.

Here are some examples:

  1. To compress a file using gzip, execute the following command:
    % gzip filename.tar
    (where ‘filename.tar’ is the name of the file you wish to compress) The result of this operation is a file called ‘filename.tar.gz’. By default, gzip will delete the ‘filename.tar’ file.
  2. To decompress a file using gzip, execute the following command:
    % gzip -d filename.tar.gz
    The result of this operation is a file called filename.tar. By default, gzip will delete the filename.tar.gz file.
  3. You can also decompress the file using the command:
    % gunzip filename.tar.gz
    This is the same as using the gzip -d command.

    There are many options that you can use with gzip. Do a man gzip on the command line to learn more.


tar stands for ‘Tape ARchive’.

It was originally designed for tape backups, but it is used to create a tar file anywhere on the filesystem. tar creates one ‘tar file’ (also known as a ‘tarball’) out of several files and directories. A tar file isn’t compressed, it’s just a heap of files assembled together in ‘one container’. So, the tar file will take up the same amount of space as all the individual files combined, plus a little extra. A tar file can be compressed by using gzip. Here are some examples:

% tar -xvf example.tar – Extracts the contents of example.tar and displays the files as they are extracted.

% tar -cf backup.tar /home/ftp/pub – Creates a tar file named backup.tar from the contents of the directory /home/ftp/pub

% tar -tvf example.tar – Lists the contents of example.tar to the screen

Comments are closed.