Archiving files with tar

The tar command is very useful in bundling up your files and directories. Suppose you want to bundle up the entire directory cs253 under your home directory. You would use the following command:

tar cvf cs253.tar cs253

This creates a file, often called a tarball, that contains the entire cs253 folder along with any subdirectories inside it recursively. The option c stands for create, the option v for verbose and the option f for the name of the tarball to follow.

Then you can copy the tarball to another location on your system, or copy to another system or copy it to a CD or USB drive or email it to someone. Suppose you have a tarball that you want to unpack. Use the following command:

tar xvf cs253.tar

Here the option x stands for extract.

If you want to list the table of contents for a tarball without extracting any files, use the t option.

tar tvf cs253.tar