Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




6.1 Choosing and Naming Archive Files

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.

     $ 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 --file=@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 rmt program installed (This command is included in the GNU tar distribution and by default is installed under prefix/libexec/rmt, were prefix means your installation prefix). 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.

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.

  Published under the terms of the GNU General Public License Design by Interspire