How to TAR a file or folder, GZIP, and UNTAR (create TAR files archive)

If you’re running a Linux based server, here a step by step guide on how to tar a file and then how to gzip (compress) that file using a simple SSH command.

When you are logged into your server through SSH, you can use this command line to tar and then gzip your folder into a tarball file. This will compress your file into the current directory

  • tar -czf whatever.tar foldername
    (another method would be…)
  • tar -czf whatever.tar.gz foldername

If you’d like to tar your file and have it put in another location use this:

  • tar -czf /directory/directory/whatever.tar foldername

Now that you have a tar file, here’s how to untar / ungzip (or unzip, uncompress) a file in SSH. Using this command you’ll untar and uncompress your file, then it will place that folder in the directory you are currently in restoring your old folder and file structure.

  • tar -xf whatever.tar
    (another method would be…)
  • gunzip -dc whatever.tar.gz | tar xvf –

Here are a list of tar options, and their significance.

-c = create
-f = read to/from the named file (instead of the device /tape)
-t = list contents of .tar file
-r = append to a .tar file
-v = verbose (tells you everything its doing)
-x = extract contents of .tar file
-z = compress files

Want to learn more SSH commands? I recommend the book Linux in a Nutshell

If you’re a server admin, another thing you might be interested in is how to clear the qmail queue.