Tarred, Not Feathered

Tarred, Not Feathered

When I was a kid, I was very influenced by my peers. In frustration at some of the stupid things I’d do for peer recognition, my mom used to ask me, “If your friends stuck their hands in a bucket of tar, would you have to do it, too?”


Tar in Linux is a different matter, though. It doesn’t smell. From what I can tell, it’s colorless, and, rather than making a mess, it can actually help clean one up.

“Tar” stand for tape archive, and is yet another throwback to the days of Unix. But the metaphor with the sticky road-covering substance is actually pretty appropriate. The purpose of the tar program in Linux is to stick (or unstick) a bunch of files into one while retaining all the original file permissions and ownership. Thus the term “tarball.” Just a big bunch of files all stuck together. The convention for creating a tar is:

    tar [options] new_file.tar files_you’re_tarring

The convention for untarring a file is surprisingly similar:

    tar [options] file_you’re_untarring

The common options for use with tar are:

    c – create an archive (tar file)
    f – specifies that the file to be acted upon is filename
    r – append the files to the end of an existing archive
    v – show the actions taken in verbose mode
    x – extract a file from an archive
    z – specifies that the tar file being created *or* extracted is compressed or in gzip format

Ok. So let’s stick this all together. To create a tar file named downloads.tar from the directory /home/tony/downloads, I’d issue the following command:

     cd /home/tony/downloads; tar cf downloads.tar *

(The asterisk is the wildcard in this case for “everything in this directory.”) This will create downloads.tar in the /home/tony/downloads/ directory.

If I wanted to also compress that file using gzip, the command would vary only a little:

    cd /home/tony/downloads; tar czf downloads.tar.gz *

Finally, we can untar and unzip that file using:

    cd /home/tony/downloads; tar f downloads.tar


    cd /home/tony/downloads; tar zxvf downloads.tar.gz

Sure beats black hands and my mom’s look of shock.

Think independently?