Go to the first, previous, next, last section, table of contents.

Choosing and Naming Archive Files


@FIXME{should the title of this section actually be, "naming an archive"?}

By default, tar uses an archive file name that was compiled when it was built on the system; usually this name refers to some physical tape drive on the machine. However, the person who installed tar on the system may not set the default to a meaningful value as far as most users are concerned. As a result, you will usually want to tell tar where to find (or create) the archive. The --file=archive-name (-f archive-name) option allows you to either specify or name a file to use as the archive instead of the default archive file location.

-f archive-name
Name the archive to create or operate on. Use in conjunction with any operation.

For example, in this tar command,

$ tar -cvf collection.tar blues folk jazz

`collection.tar' is the name of the archive. It must directly follow the `-f' option, since whatever directly follows `-f' will end up naming the archive. If you neglect to specify an archive name, you may end up overwriting a file in the working directory with the archive you create since tar will use this file's name for the archive name.

An archive can be saved as a file in the file system, sent through a pipe or over a network, or written to an I/O device such as a tape, floppy disk, or CD write drive.

If you do not name the archive, tar uses the value of the environment variable TAPE as the file name for the archive. If that is not available, tar uses a default, compiled-in archive name, usually that for tape unit zero (ie. `/dev/tu00'). tar always needs an archive name.

If you use `-' as an archive-name, tar reads the archive from standard input (when listing or extracting files), or writes it to standard output (when creating an archive). If you use `-' as an archive-name when modifying an archive, tar reads the original archive from its standard input and writes the entire new archive to its standard output.

@FIXME{might want a different example here; this is already used in "notable tar usages".}

$ cd sourcedir; tar -cf - . | (cd targetdir; tar -xf -)


To specify an archive file on a device attached to a remote machine, use the following:

--file=hostname:/dev/file name

tar will complete the remote connection, if possible, and prompt you for a username and password. If you use `[email protected]hostname:/dev/file name', tar will complete the remote connection, if possible, using your username as the username on the remote machine.

If the archive file name includes a colon (`:'), then it is assumed to be a file on another machine. If the archive file is `user@host:file', then file is used on the host host. The remote host is accessed using the rsh program, with a username of user. If the username is omitted (along with the `@' sign), then your user name will be used. (This is the normal rsh behavior.) It is necessary for the remote machine, in addition to permitting your rsh access, to have the `/usr/ucb/rmt' program installed. If you need to use a file whose name includes a colon, then the remote tape drive behavior can be inhibited by using the --force-local option.

@FIXME{i know we went over this yesterday, but bob (and now i do again, too) thinks it's out of the middle of nowhere. it doesn't seem to tie into what came before it well enough <<i moved it now, is it better here?>>. bob also comments that if Amanda isn't free software, we shouldn't mention it..}

When the archive is being created to `/dev/null', GNU tar tries to minimize input and output operations. The Amanda backup system, when used with GNU tar, has an initial sizing pass which uses this feature.

Go to the first, previous, next, last section, table of contents.