Next / Previous / Index / ITC Help System / Publications / Site map / NM Tech homepage

How to make a tar archive

Tech Computer Center logo

To construct a ``tarball'' that contains copies of all the files in a particular directory subtree:

  1. Use the cd command to change your current working directory to the parent directory of the root directory of the subtree you want to archive. For example, if you want to build a tarball of a directory whose pathname is /u/gertrude/rain/pics/, you would use this command:
            cd /u/gertrude/rain
  2. Pick a name for the tarball that ends in .tgz. In the example, we might call the tarball rainpics.tgz.
  3. Build the tarball with this command:
            tar -cvzf name.tgz subdir
    where subdir is the name of the subdirectory you want to save. To continue the example, this command would be:
            tar -cvzf rainpics.tgz pics

The -c option tells tar to create an archive. The v option tells it to write out the names of the files on your screen as it saves them, so you can be sure it is including everything you want. The z option specifies that the file should be compressed, to save space. The f option instructs tar to use the next name (in the example, rainpics.tgz) for the tarball it is building.

The last argument is the name of the directory subtree to be saved. You could use an absolute path name here, but it is not recommended, because you may be moving the tarball to a system that has different directories. That's why we recommend you use a relative path name here.

Once your tarball file is completed, you can move or copy it elsewhere on the system, or to a different system altogether.

Next: Listing the contents of a tar archive
See also: How to move an entire directory tree
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Information Technology and Communications: Help System
ITC Publications
To report a problem: File a ticket
Send mail to the User consultant on duty or call them at 575-835-5437
Home: About New Mexico Tech

John Shipman,
Last updated: 2000/09/20 21:22:12 UT
QR two-dimensional bar code