Tar and Gzip
with Unix and Linux

Tar and Gzip are all popular forms of file compression and file packaging that you may use or need to use on your web account.  Sometimes in order to setup a CGI program, the instructions include the necessary details to uncompress your file(s).  Our experience has been that most instructions leave out this detail of how to uncompress your file(s).

Note that you can uncompress your tar or gzip files with the PC based Winzip software and then simply FTP the files to the server.  After the files are on the server, change the permissions (chmod) according to the CGI script setup instructions.

Uncompressing

By performing tar or gzip usually the permissions are set correctly when the files are uncompressed directly on the server - this is not always the case and you should always check your permissions in any event.

Remember to place your compressed file on the server in the location you want all the files to appear.  When you uncompress your file, naturally it will uncompress it in its current location on the server.  So make sure the file is located in the folder/directory you wish the files to appear.

The following are popular Tar and Gzip commands using SSH Telnet.

Gzip

Gzip files are noted by the extension .gz

To untar a gzipped file and retain the permissions and maintain the established directory structure in the compressed file, use the following command:

tar zxvf tarfile.tar.gz
(sometimes you must leave out the z in zxvf)

The most common tar extraction parameters for gzip files are:

  • x - Extract the files
  • z - Use compression (GNU version only).
  • v - Be verbose about it (output status of its extraction)
  • f - Use this file

Note that tar is picky and that it is advisable to use the sequence zxvf or xvf as the order is important.

Tar - (T)ape (AR)chive

To tar the current folder and all sub folders, and retain all permissions, cd to the directory you wish to tar and use the following command:

tar cpvf nameoffile.tar *

  • c - Create
  • p - Preserve file and folder permissions
  • v - Be verbose about it (output status of its extraction)
  • f - Use this file

Other popular tar commands...

This will tar a folder and all of it's contents including subfolders...
tar cpvf nameoffile.tar foldername

You can filter the file through gzip compression using "z" while performing the tar such as...
tar cpvfz nameoffile.tar.gz *

To "untar" or uncompress the same file above...

  • x - Extract
  • v - Be verbose about it
  • f - Use this file
  • p - Retain permissions

TIPS

  • You must use "c" in order to create the file.
  • Usually it is always a good idea to use "p" so that the file and folder permissions will be maintained.
  • It is safe to leave off the "v" as the tar will be generated faster since it doesn't have to output the file by file status on the screen.
  • If you leave off "f" the output will be generated to your screen which is usually not what is intended.
  • Keep in mind that a tar file that is created is only slightly compressed - if any at all.
  • To get the smallest file size possible, use the "z" parameter while performing tar.  Make sure to use the correct extension while naming the file such as nameoffile.tar.gz
  • To ensure the parameters you have used work correctly, download the tar file to ensure it will open on your PC.
Further Details

For further details, use the man command.

[Manual Index]
Copyright 2000-2006 ActiveWebHost.com. All Rights Reserved. Terms and Conditions of Use and Privacy Policy. ActiveWebHost.com - Your Success Is Our Success