Quick reference

Tutorial ButtonHaving trouble with the mission? Read how to get help.

Quick reference

Tools for working with tar archives

If you are running a GNU/Linux distribution, Mac OS X, or another Unix-like operating system, your system almost certainly has the tar program on it already, and you can run it by typing “tar” into a terminal. If you are running Windows and prefer to try this the Unix way, you can get tar as part of MSYS; many Windows archiving programs, such as 7-Zip, support working with tar archives as well.

This page is just a quick reference; see the bottom for other resources.

Unpacking (and listing)

To unpack a tarball, you can use:

tar xvzf [tarball]

To be more specific:

tar [option letters]xf [tarball]

(The x stands for extract.)

The tarball’s contents are placed into the current directory. Option letter z makes tar transparently un-gzip the tarball, and v shows the filenames as tar unpacks them.

Listing a tarball works the same way as unpacking it, except that you use tf instead of xf.

So the command would look something like:

tar [option letters]tf [tarball]

(The t stands for list. Go figure.)

Option letter v, which would otherwise be redundant because tar is already listing the contents as it examines the tarball, shows more details (such as permissions and sizes) about the files inside.

It is generally a good idea to try unpacking or listing a tarball you are about to send out so you can verify that it really contains what you wanted.

Creating a tarball

If you have a directory named dir, and you want to make a tar file called mytar.tar.gz, you could:

tar zcvf mytar.tar.gz dir

The general way to create a tarball from a set of files and directories is:

tar [option letters]cf [tarball] [things to tar up]

(The c stands for create, and the f means that the next argument is the file you want tar to work with.)

Common option letters are v (verbose) to make tar list the things it is adding as it goes along and z to make tar gzip the tarball for you rather than giving you an uncompressed one.

If any of the things listed to include in the tarball is a directory, tar will automatically recursively add everything inside the directory too. This is part of the reason for the convention of using a single wrapper directory, as then that is the only thing you have to explicitly list when creating the tarball.

Other resources

There are many more options to tar, which are detailed in tar’s documentation. The ones mentioned here, though, are the most commonly used ones. For further reading: