How to Make a Tar Archive (a.k.a. “tarball”)

So you want to compress a directory. Here’s how you make a tar file, also known as a “tarball,” from the command line. What follows assumes you already have a basic familiarity with how to navigate the via the terminal.

First, change your current working directory to the parent directory of the folder you want to archive. In other words, if you want to make a tarball of a directory whose pathname is /home/username/Documents/computing/linux/ , you would use the following command:

cd /home/username/Documents/computing

Second, select a name for the tarball that ends in .tgz . For example, you could call the tarball for the directory above linux.tgz

Third, create the tarball with this command (here I continue with the same example as above):

tar -cvzf linux.tgz linux

What does the command above mean and do?

-c tells tar to create an archive. v makes it display the names of of the files as it processes them. z is to compress the file and f tells tar to use the next name in the command (in this example, linux.tgz for the tarball being created. The final argument in the command is the name of directory (folder) to be saved and compressed.

Hope this helps!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s