Tutorial to create a compressed tar gzip file

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

On Linux based systems, you can bundle a large set of files and folders into a single “tar” file. Furthermore, you can then compress this tar file to make it a smaller size using gzip.

One typical reason for doing this for backup and ease of download. In this tutorial, we will create a compressed tar file of a WordPress site on a shared webhost so that we can download it to our local computer for safekeeping.

1. Log into Command Line

tar is a command line utility. So you first have to log into the command line of your Linux system. We’ve used a SSH Shell application called PuTTY to log into our Hostmonster shared webhost. This is a secured shell that gives you command line access. The three pieces of information needed to login are the hostname, username, and password.

Note: some shared webhosts may allow command line shell access and others may not. Some may require that you “apply” for such access.

2. List Files

Then we do the “ls” command (letter el as in “list”) to see the list of files and folders that we want to compress…

ls command

3. Now run the tar command with these options ….

tar -czvf bu072311.tar.gz *

tar command

tar command

The “-czvf” are flag options that tells the tar command what to do. The “c” tells it to create the tar file. A tar file is single file that contains a bundle of files and folder with its directory structure preserved. The “z” tells it to then compress this file into the gzip format. The “v” is the “verbose” option flag to tell it to display the filenames as it is processing it. And the “f” flag indicates that the next parameter is the output filename that we want created.

In our example, this output filename is an arbitrary filename that we specified as “bu072311.tar.gz” We use the file extension “tar.gz” to indicate that it is a tar file that is compressed in gzip format. This file is sometimes known as a “tarball”.

And the final parameter of * tells tar to do it for every file and folder in the current directory.

4. After the command is run, you will find the file “bu072311.tar.gz” created for you which you can then download to your local computer using FileZilla.

You can verify the integrity of the compressed tar file by extracting it to see if you get back the original files.

5. If for some systems where the “z” option of tar is not available, you can do …

tar -cvf bu072311.tar *

to obtain the tar file. And then gzip the file with …

gzip bu072311.tar

and it will convert your bu072311.tar file into the compressed tar file “bu072311.tar.gz”.