TAR(1)

NAME
tar - tape archiver

SYNOPSIS
tar [ key ] [ name ... ]

DESCRIPTION

tar saves and restores multiple files on a single file (traditionally on magtape, but it can be any file). tar's actions are controlled by the key argument. The key is a string of characters containing at most one function letter and possibly one or more function modifiers. Other arguments to tar are file or directory names specifying which files to dump or restore. In all cases, appearance of a directory name refers to the files and (recursively) subdirectories of that directory.

The function portion of the key is specified by one of the following letters:

x   The named files are extracted from the tape. If the named file matches a directory whose contents had been written onto the tape, this directory is (recursively) extracted. The owner, modification time, and mode are restored, if possible (the mode has the current umask (see umask(2)) applied, unless the p keyletter is given). If no file argument is given, the entire content of the tape is extracted. Note that if multiple entries specifying the same file are on the tape, the last one overwrites all earlier.

t   The names of the specified files are listed each time they occur on the tape. If no file argument is given, all of the names on the tape are listed. Note that the argument must precisely match the name on the tape; in particular, a leading ./ is often necessary. (But see the section below titled ARGUMENT LIST PROCESSING.)

c   Create a new archive. The named files are packaged up into an archive.

C   Compare an archive with files on disk. An archive is read, as if for an x operation, but rather than writing anything to disk, tar compares the data that would be extracted with what's in the corresponding file on disk, reporting any discrepancies. Note that while files present on the tape but not on disk will be mentioned, files on disk but not on the tape will not be noticed.

P   This causes tar to act as a filter. It will read a tar canister from its standard input and write another to its standard output. What else is done depends on any other action letter specified: t causes a listing to be produced on tar's standard error, c causes named files to be appended to the archive, and x causes the output archive to contain only the named files from the input archive. If no other operation letter is given, nothing is done but copy the archive. (The output is always on the standard output; the input is read from the place(s) specified by any f options, or the standard input if f is not given. But see the P-to long key, below.) The output archive is regenerated, not just copied from the input; thus, for example, the o flag can be used to strip directory information, or the M keyletter can be used to merge multiple input canisters. See the S keyletter for how this option interacts with sparse files in the archive.

The following characters may be used in addition to the letter which selects the function desired.

o   On output, tar normally places information specifying owner and modes of directories in the archive. Some really old versions of tar, when encountering this information, will give error messages of the form <name>/: cannot create This modifier will suppress the directory information. (It is ignored when the operation does not call for creating an archive.)

p   This modifier says to restore files to their original modes, ignoring the present umask(2). Setuid and sticky information will also be restored to the super-user. (If files are not being restored, this flag has no effect.) Normally, tar never touches the set-gid bit on a directory under any circumstances, assuming that it's performing the Berkeley/SysV group-ID semantics function SunOS gives it. But if p is given twice, this is suppressed: the extracted directory's mode is literally the mode on the tape, even down to the setgid bit.

v   Normally tar does its work silently. The v (verbose) option makes tar print the name of each file it treats preceded by the function letter. With the t function, the verbose option gives more information about the tape entries than just their names.

f   tar uses the next argument as the name of the archive. tar can be used as the head or tail of a filter chain this way; see the section below titled PATHNAME INTERPRETATION. For example, tar can be used to copy directory hierarchies with a command such as tar cf - -C fromdir . | (cd todir; tar xf -) This keyletter must be given, except when the P keyletter is used. Traditionally, tar has used a tape device name (typically /dev/rmt8) if f is not used; however, tape device names are sufficiently nonstandardized now that the danger of root accidentally creating a large plain file in /dev seems to me to override the slight inconvenience of having to specify the tape name explicitly when it would match the default. When using an operation that reads archives (x, t, P, or C), f can be given multiple times. Each archive thus specified is assumed to be a complete archive; tar does not simply concatenate the data streams, but rather treats each archive as a stream of archive entries and concatenates those streams. Each archive can potentially produce a ``premature EOT'' error, for example, and the M keyletter is not needed (or desirable) unless one or more of the data streams contains multiple canisters.

K   Causes tar to skip parts of an archive based on the sequential order of items in it. You can use this to, for example, restart an extract that crashed due to a full disk at the point where it failed, without re-extracting everything before that point. The K flag takes an argument, which is an operation character followed by a path name. As tar processes archive entries (as it creates them, for a c operation, or as it reads entries from an input archive for a t, x, C, or P operation), it compares the archive member names with the argument path. When a match is found, action is taken according to the operation character. If the path string is zero-length (if the argument argument is just the operation character), then any archive member will match. If you give no K options, no part of the archive is skipped. If you give one or more K options, the initial state is ``skipping'', which causes archive members to be discarded. K options are processed left-to-right; each operation character can be ``@'', ``='', ``+'', or ``-''; the actions taken when the corresponding path is matched are as follows: @
    If this is the last K option, treat it as a ``+'', otherwise, as a ``-''. =
    Don't change the state. This is useful largely to constrain a later K option to match only after the current one. +
    Set the state to ``not skipping'', that is, process archive members as normal. -
    Set the state to ``skipping'', so that archive members are ignored. If the first character of the K argument is not one of those listed, then ``@'' is supplied. When using Pc, the stream of archive members for purposes of matching K arguments is first the items in the input archive, then items (potentially) written to the output archive due to the c operation. Non-skipped items are packaged up to form the output archive. The stream of archive members is not affected by any selection performed by filename arguments given to a t or x operation; only the members in the archive matter. The argument-list selection occurs after the K filter is applied. As a special case, if the first K argument has a zero-length path, it is processed before the first archive member is seen. (This allows you to override the default initial state if desired.) This applies to only the first K option; the second one will never be processed before the first archive member, even if both the first two have zero-length paths.

e   Causes tar to redo the stat(2) system call after dumping a plain file, to see if the file appears to have changed during the dump. Size changes will normally be noticed without this, but most other changes will not. In most circumstances, other changes do not matter, so this is not the default.

d   Causes tar to restrict its dumping to entities residing on the same filesystem as the argument; things that appear to reside on other filesystems will simply be omitted from the output archive. (This modifier affects operation only when c is used.) The output archive may still contain things from different filesystems if multiple arguments are given; d merely limits what is dumped for each argument to things on the same filesystem as that argument. (If I is used, an ``argument'' should be interpreted as referring to one of the names read from stdin.)

A   This affects how tar treats kill entries in input archives. See the description of the k keyletter, just below, for a description of its function.

k   When specified in conjunction with a c operation, creates a ``kill archive'', consisting of headers of a private ``kill'' type. When tar sees a header of this type when reading archives, it remembers the name in the header, and when it finds a later archive member with that same name, it silently skips over it, discarding the remembered name. (If the same name appears in multiple kill entries, it is remembered once for each such kill entry; each (non-kill) entry with that name will consume exactly one of the remembered names.) When creating a kill archive, the names on the command line (or on the input, with I) are used directly to create the kill entries; tar makes no attempt to recurse into directories, interpret the i or d keyletters, or any other such filesystem operations. When reading an archive with kill entries, if the A keyletter is not given, the kill entry editing is done before all other operations; in particular, the stream of entries seen by the logic described under the K keyletter has already had the kill entries, and the entries they kill, removed. If A is given, the stream of entries includes the kill entries; they cannot be extracted, of course, but they can be copied by a P operation or listed by a t operation. It is not an error for a kill entry to go unmatched by any ``real'' entry when reading archives.

i   When given i, tar will dump plain files by reading the filesystem directly from the disk device. (This option may have been disabled when tar was compiled.) Note that this will work only when tar is being run by a user with read access to the disk devices. When S is also given, the archive will describe exactly what portions of the file really exist on disk, regardless of the contents of those partitions; no attempt is made to optimize storage in the archive by squeezing out chunks of NULs which are actually on-disk (this is a feature, not a bug).

r   When used in conjunction with i, r gives the number of times tar should try rereading the on-disk inode if an error is noticed while dumping the file. A sync(2) is done before each reread; before the second and later rereads sleep(3) is called (after the sync()) to sleep for one second. Because of the system overhead it incurs, this is not the default. (The number is taken from the next argument.)

u   When used in conjunction with i, u tells tar to use the raw (``uncooked'') disk device for filesystem access (otherwise it uses the block device).

U   Superseding u, this specifies what disk device to use. Note that this device is used regardless of what filesystem the file being dumped is on, so you probably want to specify d as well.

b   tar uses the next argument as the blocking factor for tape records. The default is 20; the maximum is 2048. This option should be used only with raw magnetic tape archives (see the f modifier above). The block size is determined automatically when reading tapes (key letters `x' and `t').

l   tells tar to complain if it does not see all of the links to files dumped. If this is not specified, no such messages are printed.

m   tells tar not to restore the modification times. The modification time will be the time of extraction.

h   Force tar to follow symbolic links as if they were normal files or directories. Normally, tar does not follow symbolic links, but instead puts the link itself into the archive. Note that when this option is used, symbolic links that point upwards in the directory hierarchy can cause tar to repeatedly descend into that portion of the hierarchy, producing an effectively infinite archive.

B   Causes tar to treat its input and output as byte streams rather than record streams. When this option is used with operations that produce output, the result is not guaranteed to be usefully blocked; see dd(1) for one way to re-block such a stream.

F   Causes tar to check the consistency of its header blocks (see tar(5)) less strictly. Normally, when tar sees a header block which appears to be corrupted in any way, it will print a message and skip input blocks until it finds a block which looks like a valid header block. In the presence of the F modifier, certain consistency checks are relaxed: if they fail, a message is produced, but the header block is accepted as valid. If this modifer is present twice, even the complaints are suppressed. This allows tar to read tapes produced by `foreign' versions of tar which have defined extra fields or alternative values for some of the existing fields. Certain errors, such as a checksum error, are always considered to be real errors and are not affected by F.

R   The R modifier is used to extract files from tapes which were carelessly written with absolute pathnames. Normally, tar will complain if it is asked to extract a file whose name begins with a /. If the R key is given, the next argument is taken as a string to be prepended to the name in the archive, thus extracting the files into a hierarchy rooted at the argument path. Thus, if the file contains paths beginning /usr/..., these files could be extracted into /tmp/usr/... with tar xR /tmp To extract the files to the names under which they were archived, for example, use tar xR "" or, for most systems (those for which a leading // is equivalent to /), tar xR / The R modifier has no effect when restoring files not archived under names beginning with a / - even if the archive contains both kinds of names, the R modifier affects only those beginning with a /.

I   The I modifier causes tar to read filenames for a c operation from its standard input, rather than from the argument list. (With other operations, the I keyletter is ignored.) This is intended largely for use with find(1), as in find /u1 -mtime +7 -user karels -print | tar cvfI /dev/rmt12 (note that if you just want to dump files newer than a certain time, the s keyletter is probably what you want). It is also useful in conjunction with ck and E list= output from another run. If I is given multiple times, the second (and later) occurrences need an argument. The first character of this argument is used as the filename terminator in the input (when I is given only once, a newline is used as the terminator). If the argument is zero characters long, the terminator is taken to be a NUL character. (See the I-source long key, below, for more.)

E   The E keyletter describes what to do with files that did not dump correctly. In many cases, particularly when e or i is given, tar can detect when a file was dumped incorrectly. This option specifies how to handle such files. It can be given multiple times; each option is processed separately. It takes an argument, which is a comma-separated list of options (whitespace is ignored after, but not before, the comma). Except as noted, they are independent. now=N
    Specifies that the file is to be retried up to N times immediately after the failure, when the failure is one that can be retried (see below). later=N
    Specifies that the file is to be retried up to N times at the end of the dump (after all normal dumping operations are complete), when the failure is one that can be retried (see below). list=path
    Specifies that the file's pathname is to be sent to the specified path. No checking is done when the writes are attempted; errors such as ``disk full'' will not be noticed by tar. Each failure to dump produces an entry (which can mean multiple entries for a given pathname, if retries are specified with now= or later=); each entry consists of a pathname followed by a NUL (not a newline). If multiple list= specs are given, the last one silently overrides all others. See also the section below titled PATHNAME INTERPRETATION. file=keyword
    Allows another file, of the same name, to be written to the archive following the failed file (so as to overwrite it when extracted). The keyword can be ``none'', which turns this feature off, ``empty'', which specifies that an empty file is to be written, or ``msg'', which specifies that a file containing an explanatory message is to be written. If multiple file= values are given, the last one silently overrides all others. log=path
    Causes all complaints about files being dumped incorrectly to be sent to the specified path as well as to stderr. If multiple log= specs are given, the last one silently overrides all others. See also the section below titled PATHNAME INTERPRETATION. Some failures can be retried (such as a file that changed size while being dumped); some failures cannot (such as an error opening the file). When a failure can be retried, the now= and later= options control how many retries happen and when; when all the specified retries have failed, or if the failure is one that cannot be retried, the file= option controls what (if anything) is done. list= is intended to be used to obtain a list of everything that made it to the tape but isn't correct; this can be used directly with a cIIk '' run to produce a kill archive appropriate for use when reading the tape.

s   tar will archive files only whey they are newer than the time specified by the next argument. This argument can be a numeric time of the form YYYYMMDDhhmmss, where trailing components can be omitted (and default to the earliest possible value for that component). The month can also be given as the usual three-letter (English) abbreviations. If the argument does not have this form, it is assumed to be a pathname, and the mtime of that path is used. Note that this affects only plain files; all other entities are dumped regardless of their timestamps.

M   Normally, tar stops when it sees a header block which indicates the end of the tape. The M modifier causes it to assume that another canister follows immediately; tar effectively ignores the end-of-tape header and continues reading.

O   The O modifier causes tar to write extracted files to tar's standard output, rather than to disk files. If multiple files are being extracted, they are concatenated, with no indication where one file ends and the next begins. (The O keyletter will be ignored unless the operation indicator is x.) If you wish to just select some files from an archive, consider using Px rather than O. Note that directories, device special files, and other non-file entities cannot be extracted with O.

W   The presence of the W flag indicates that the ``filename'' arguments are actually filename patterns. When used with c operations, this affects only how arguments marked with -I and -X are matched; it does not affect processing of arguments that name files to go on the tape. With t or x, filenames from the tape are not matched literally against the argument list but rather the arguments are considered to be patterns, much like what the shell does. (Note that the pattern will normally have to be quoted to protect it from the shell. Note also that slashes must be explicitly represented; they cannot be match wildcards.)

L   The tar format imposes a maximum length of 100 bytes on pathnames in an archive. Normally, this version of tar uses a private header block format to handle longer names transparently. The L keyletter modifies this: if given once, names longer than 100 characters produce a warning message, but the archive is generated just as usual; if given twice, such items are omitted entirely from the generated archive.

S   The S flag indicates that tar should take special actions to deal intelligently with sparse files. When copying files from disk to an archive, this flag indicates that the generated header should use a private format to store files, if they can benefit from it. When extracting files from an archive to disk, this causes tar to create holes in the disk file whenever possible (regardless of whether the file in the archive is stored as a sparse file or not). When extracting a sparse file, the created file will have all the holes described by the archive format (sparse files are always recognized in an archive, even in the absence of the S flag); if S was given, it will also have all other possible holes. When a P operation is being performed, non-sparse files in the input archive are always output as non-sparse files, because the format used for sparse files is incompatible with the one-pass nature of P; if S is not given, all files in the output archive will be non-sparse, even if they were sparse in the input archive. When S is given with P, files that are sparse on input are sparse on output (and any files added due to the c keyletter may or may not be sparse, depending on the file contents).

T   Makes tar paranoid about ftruncate(2). This is equivalent to the long key ftruncate paranoid; see the ftruncate long key for more.

V   tar uses the next argument to specify where log-style output (output generated by the v or t keyletters) goes. By default, such output goes to stdout if nothing else is going there, otherwise to stderr. See the V-toc and V-info keys, below, for finer-grained control. See also the section below titled PATHNAME INTERPRETATION.

X   The X keyletter reverses the sense of the test tar uses to determine whether a file is of interest during any operation that selects files from an archive based on the argument list. For precise details, see the section below on argument list processing.

j   Causes tar to be paranoid when extracting an archive. This option enables checking to ensure that the extraction operation does not affect anything outside the directory tar is running in. This is intended for use when extracting archives of unknown or untrusted origin. There are numerous things an archive normally does not contain, but could, which would cause damage; as a simple example, consider the following archive: % tar tvf evil.tar rwxr-xr-x 0/0 0 Dec 10 09:47 1995 foo/ rwxrwxrwx 0/0 0 Dec 10 09:47 1995 foo/bar symbolic link to /etc rw-r--r-- 0/0 546 Dec 10 09:48 1995 foo/bar/passwd % Such a thing would not be created by a simple tar run, but could easily be constructed by a malicious person. The j keyletter checks each item being extracted to ensure it would not write outside the current directory, by walking the path and following any symlinks found. If a symlink to an absolute path is found, or if sufficient ../ components to ascend out of tar's working directory are found, a complaint is printed and the item is skipped. (This option will also suppress the extraction of absolute pathnames even if R is given; this is arguably the wrong thing to do.)

D   Turns on internal debugging. Takes an argument, which is one or more debugging keywords, separated by one or more commas and/or spaces, each possibly prefixed with `!' to turn it off rather than on. One can also specify `out=path' to redirect debugging output (no provision is made for paths containing spaces or commas), or `help' to get a list of valid keywords. The output is usually cryptic and useless for anything but debugging, and changes too often in any case, so this document makes no attempt to describe it. See also the section below titled PATHNAME INTERPRETATION.

An additional, more general, syntax is available for arguments. A + in the key argument directs tar to read keys from the argument list; any keys that take arguments are followed immediately by those arguments. All the single-character keys that can appear in the first argument (except + itself) are valid on their own as keys under this syntax; in addition, many multi-character keys can appear. The list of keys is terminated by a + key; this terminates the list of arguments to the + in the first argument, and processing picks up with the next character following it, if any. For example, tar cfiUvVr - /dev/rz0h /backup/logs/current 5 -C /home . could (perhaps more comprehensibly) be written tar + c f - i U /dev/rz0h v V /backup/logs/current r 5 + -C /home . or tar ci+v f - U /dev/rz0h V /backup/logs/current r 5 + -C /home . or even tar cUi+vr /dev/rz0h f - V /backup/logs/current + 5 -C /home . or any of many other similar ways. If the terminating + would be the last argument to tar, it can be omitted.

The permitted multi-character keys are as follows. For many of them, refer to the section below titled PATHNAME INTERPRETATION.

I-source
    Turns on I-style archive creation, specifying an alternative input source. The I keyletter specifies that archive member names are to come from stdin; this allows them to come from anywhere, and also allows multiple streams to be read. Two arguments are used. The first specifies where the input is to come from; the second, what character is to be used to terminate arguments. C-style backslash escapes are accepted for the terminator, but are not necessary; if the second argument is only one character long, or if it doesn't begin with a backslash, its first character is the terminator (if it's zero characters long, NUL is used). Thus, I (given once) is equivalent to I-source - \n. Input sources are read in the order they're specified.

O-to
    Turns on O-style extraction, but specifies an alternative place for the extracted output to go. Takes one argument. Plain O is equivalent to O-to -.

P-to
    Turns on P-style archive filtering, but specifies an alternative place for the output archive to go. Takes one argument. Plain P is equivalent to P-to -. (To specify where input comes from, use the f keyletter.)

V-toc
    Redirects v and t output, like V, but redirects only just enough of it to accumulate a list of what's actually on the tape. Other informational messages are not redirected, and continue to go where they would have gone (unless V-info is also given).

V-info
    Redirects all output that V would redirect, except that which is controlled by V-toc. (This doesn't control much. At present, it covers just reports of GNU-tar private or kill entries under x or C, difference reports from the C operation, and warnings from the d key.)

i-file
    Equivalent to i: dumps plain files by direct filesystem access.

i-full
    Takes one argument, which is a disk device name. Causes tar to do direct-to-disk I/O for all filesystem access necessary for obtaining stuff to dump. In this mode, all pathnames of files to dump, directories to change to, etc, are treated as though rooted in the filesystem being dumped (the initial current directory is the root of the filesystem). The d key is implicitly in force as well, since the disk is being read at such a low level that mount points will not be noticed. The disk device being dumped does not have to be mounted; indeed, if it is mounted read/write, there is some danger that filesystem writes will change the filesystem while tar is running. (The e, r, and E keyletters are designed to help deal with such situations.) The `disk device' does not even have to be a real disk device; it can be a filesystem image contained in an ordinary file.

f-stream-term
    Takes two arguments. Causes tar to read a list of strings from the place specified by the first argument (see PATHNAME INTERPRETATION, below); the second argument specifies a terminator character, as for the I-source key, above. tar reads these strings once, at startup, and behaves as though each one had been provided as an f keyletter argument. (Note that strings beginning with - signs will be taken as requesting input from or output to a file descriptor, as described below.) This is wholly equivalent to specifying a separate f keyletter for each string, and can be used with any operation that f can be.

f-stream
    Equivalent to f-stream-term except that it provides a newline terminator automatically, and thus takes only one argument, not two.

align
    Takes one argument, N, which is a tape block count. tar will pad the output archive (with a private ``idling'' header block) as necessary so that no N-block boundary falls partway through an archive member (unless a single member requires more than N tape blocks, in which case that member will overlap an N-block boundary). These ``idling'' headers silently disappear on read; not even the A keyletter will make them visible. When P is used, the output archive will not contain any unless align is given, regardless of what's in the input archive and what other flags are given. Note that align does not cause tar to pad the end of the archive out to an alignment boundary, and it takes no notice of the output blocking factor (see the b and B keys), treating the output as a stream of tape blocks. It is designed for creating an archive which is split up into multiple tapes (or other pieces) of equal size, with reasonable confidence that no tape begins partway through an archive entry. (For this use, the align argument will need to be a multiple of the tape blocking factor used when writing the archive pieces to tape.)

ftruncate
    Takes one argument, which can be `unknown', `can-grow', `shrink-only', or `paranoid'. This affects tar's behavior with respect to ftruncate(2). Some systems' versions of ftruncate will extend files; others will only shrink them. By default, tar's notion of ftruncate's behavior is `unknown'; in this state, tar will notice whether ftruncate is willing to extend files or not, and will shift into 'can-grow' or `shrink-only' as appropriate; in the latter two states, it assumes that the behavior is as described. `paranoid' is a state in which tar tries to use ftruncate to extend, and if that fails, falls back on the `shrink-only' behavior, but does not actually change state. See also the T keyletter. This affects tar's operation when doing a sparse file extract that wants to put a hole at the end of a file. The `paranoid' state is intended for cases (such as extractions across multiple heterogenous NFS servers) where ftruncate may sometimes behave as `can-grow' and sometimes as `shrink-only', in a way too complicated for tar to try to predict. If multiple ftruncate keys are given, the last one silently overrides all others. They affect only the initial state; if it's set to `unknown', it will automatically shift to `can-grow' or `shrink-only' at the first opportunity (the first time tar wants to put a hole at the end of a file). To generate a hole at the end of a file under `shrink-only' behavior, tar does an lseek(2) to a point one megabyte past the desired end-of-file, writes one byte, and then makes an ftruncate call to truncate the file to the desired size. The intent is that any data blocks allocated for the write will be wholly discarded by the truncate. This is not perfect; it is still possible to end up allocating an ultimately unnecessary indirect block or two, but it's about as good as we can do without real kernel support for creating a hole at the end of a file.

config
    Takes no arguments. Causes tar to dump out a list of C preprocessor definitions used to build it, and then exit without examining any further arguments or taking any other actions. This is normally used only by people working with the source code, as when trying to debug or port tar.

sortdirs
    Takes no arguments. Normally, when creating an archive, tar processes directory entries in the order it finds them in the directory. This option causes it to read the entire directory, sort the names, and process them in sorted order. It has no effect when not creating archives.

unlink
    Takes no arguments. Causes tar to use unlink(2) (or rmdir(2), as appropriate) on filesystem objects as soon as they have been successfully appended to the archive. This is a dangerous option; even after tar has successfully appended an object to the archive, the archived version could be lost for any of many reasons: tar could crash or be killed before flushing all of the buffered data to the place the archive is going; the archive could be going to a disk file on a partition which fills up unexpectedly; or the archive could be going to a tape drive which gets a write error, to name just three. Note when using this option with E: tar will not unlink files that failed to dump. If later= is used with E, and a file that fails to dump then successfully dumps on the `later' retry, tar will attempt to unlink it at that point. The major implication of this is that the non-unlinked file can cause attempts to remove directories to fail with ``not empty'' errors; tar is not capable of retrying the removal of the directories after dumping the file. This does not strike me as a heavy price, especially since the situations E is designed for are not ones where unlink would be appropriate.

debug
    Equivalent to the D key.

There are also some options that can appear in the argument list:

-Q  The -Q (``quote'') flag indicates that the next argument is to be taken as a pathname, even if it looks like a flag, thus allowing files with names like -H to be handled.

-C  If a file name is preceded by -C during a c operation, then tar will perform a chdir(2) to that file name before processing the rest of the argument list. This allows multiple directories not related by a close common parent to be archived using short relative path names. For example, to archive files from /usr/include and from /etc, one might use tar c -C /usr include -C / etc which would put files on the tape with names like include/stdio.h and etc/fstab. Unlike some other tars, a -C applies to all further filename arguments, not just the next one.

-X  If a file name is preceded by -X, the following name (or names matching the following pattern, with the W modifier) will be excluded from the operation. This allows the extraction of everything except a given file, for example. Note that the argument list is scanned left-to-right when determining whether a file should be included. For precise details, including how -X interacts with the X keyletter, see the section below on argument list processing.

-I  For a c operation, an argument may be preceded by -I to suppress a later -X that would otherwise exclude it. For example, one could exclude all .o files except those in a particular directory with something like tar cf - src -I src/lib -X -T .o See the section below on argument list processing for full details.

-H  If an argument is preceded by -H, that argument is considered to be matched if the argument is a prefix (`head') of the pathname under consideration. Normally, the argument must match exactly, or else match an initial string with a slash immediately following it. With this option, it need only be an initial string. For example, tar xf - ./foo would normally extract a file called ./foo/think.c, but would not extract a file called ./food.c. But if the command were tar xf - -H ./foo both would be extracted.

-T  If an argument is preceded by -T, that argument is considered to be matched if the argument is a suffix (``tail'') of the pathname under consideration. This is most useful to match extensions, as in tar xf - -X -T .o ./src but its use is not restricted to that. (For example, one could use tar PxX -T / to get an effect similar to that of tar Po .)

-F  If an argument is preceded by -F (``full''), that argument is considered to be matched only when it matches the pathname under consideration exactly (as opposed to normal processing, which will also match when the argument matches a prefix of the argument which is immediately followed by a slash).

-N  Similar to -H, -T, and -F, but restores normal processing: the argument must match exactly, or else match an initial string with a slash immediately following it.

-S  Produces `synthetic' entries, that is, entries that do not necessarily match anything present on the archiving system. The argument is a structured string describing the entry to be synthesized. First can appear various prefixes which, when present, specify aspects of the synthetic entry:

mode:xxxx:...
    The mode bits of the created entry will be xxxx, which must be an octal number, only the low 12 bits (four digits) of which will be used.

uid:xxxx:...
    The owner UID in the archive entry will be xxxx, which must be a number.

gid:xxxx:...
    The owner GID in the archive entry will be xxxx, which must be a number.

mtime:xxxx:...
    The modify time in the archive entry will be xxxx, which must be a number giving the time in seconds-since-the-epoch.

    The defaults for these values are usually 0666 modified by the umask for the mode, the UID and GID of the tar process for the uid and gid, and the current time for the mtime. However, for file: synthesis, the defaults are those of the actual file, and for dir:, the default mode bits are 0777 modified by the umask. The entry, after any prefixes, can be:

file:tape-name:actual-path
    Creates a plain-file entry, just as if actual-path (which must be a plain file) were being archived, except that the name used for it on the tape is tape-name. The defaults, as mentioned above, are those of actual-path. Note that actual-path is treated as it would be if it were simply given as a file to add at this point; in particular, -C will affect relative paths and if i-full is in effect then the path will be followed in the filesystem being read. Also, if h is in effect, symlinks to plain files will be accepted.

link:tape-name:linkto
    Creates a hard-link entry, just as if tape-name were being archived and it were a hard link to linkto. There is no requirement that linkto exist either on disk or in the archive (though the resulting archive may fail when extracted).

symlink:tape-name:linkto
    Creates a symbolic-link entry, showing tape-name as a symbolic link pointing to linkto.

bdev:tape-name:major:minor
    Creates a block-special device entry, showing tape-name as the name and major and minor as the major and minor numbers. This works even if tar was compiled without device support.

cdev:tape-name:major:minor
    Creates a character-special device entry, showing tape-name as the name and major and minor as the major and minor numbers. This works even if tar was compiled without device support.

fifo:tape-name
    Creates a FIFO-special device entry, showing tape-name as the name. This works even if tar was compiled without FIFO support.

dir:tape-name
    Creates a directory entry, showing tape-name as the name. Note that it does not create any entries for anything in the directory; they must be created separately if desired. A slash will always be appended to the name specified. As noted above, the default mode bits are 0777, not 0666 (but the umask is still applied).

    There is no way to `rename' directories, that is, to archive the contents of an existing directory as if its name were something else (as file: does for files).

    Note that the above descriptions show `:' as a separator. This can actually be any non-letter character; the first non-letter after the keyword will be used as the delimiter for the rest of the entry (or, if it's one of the prefix keywords, the rest of that prefix). This allows names containing colons.

If more than one of -H, -T, -F, and -N are specified for a given argument, the last one given supersedes the rest.

DIRECTORY CREATION
tar will create directories as necessary when extracting archives. Directories are created with mode 700 to ensure that files can be extracted into them even if the mode in the archive would prohibit this; the modes are changed as soon as tar sees something outside the directory. If the archive later contains more things within the directory, errors may occur.

Intermediate directories that do not appear on the archive are also possible; for example, assuming the existence of the necessary directories, tar cf - dir1/dir2/dir3/file will create an archive that calls for the creation of three directories that do not have corresponding archive entries. Such directories are created mode 700 like any others; when resetting the modes on them, tar leaves them set to mode 777 modified by the umask, regardless of the p keyletter, and does not touch their ownership, leaving them owned by the user extracting the archive. The intent is to leave them as they would be if they had been created with mkdir(1).

PATHNAME INTERPRETATION
There are several places where tar takes a pathname to tell it where to read from or write to. At this writing, they are
- archive filenames
- The out= argument to D or debug
- The argument to I-source
- The list= or log= argument to E
- The argument to O-to
- The argument to V, V-toc, or V-info
- The argument to f-stream
- The first argument to f-stream-term
In these places, the string can be a lone -, which means to use stdin or stdout as appropriate, a - with a number appended, which means to read from or write to the specified descriptor (eg, -2 to use stderr), or a pathname. When the first syntax is used (a bare -), tar performs checks to make sure that neither stdin nor stdout is in use for more than one thing. If you really want to overload stdin or stdout, use -0 or -1, as appropriate; this will not trigger these checks. (If you want to use - or -n as a pathname, simply prefix it with ./ so the - is not the first character.) When - or -n is used and the thing being read or written is an archive, the B key is effectively enabled for that archive automatically.

ARGUMENT LIST PROCESSING
For t, x, and C operations, and P when x is also used, the argument list is taken to specify files of interest from an archive. In this case, the X and W keyletters, and the -X, -W, -H, and -T flags, control whether a given file is of interest. This is done as follows:

-   If -W is given, it means that the next argument is treated as if the W flag were given if it is actually absent, or vice versa. Note that giving -W twice is equivalent to giving it once; it sets a flag that effectively toggles W, rather than itself being a toggle.

-   -X effectively toggles the X flag for the next argument, as -W does for W. (This applies to t, x, C, and P when x is also given. See below for the effect of -X on c operations.)

-   If -H is used, the argument must match a prefix (`head') of the pathname; if -T, a suffix (`tail'); if -F, it must match in its entirety (`full'); -N (`normal') restores the default behavior, which is that the argument must either match the whole pathname or must match a prefix which is immediately followed by a slash. (If more than one of these options is given for some argument, the last one given takes precedence.)

-   If no filename arguments at all are given, everything is considered to be of interest (even if the X keyletter is given); however, if at least one filename argument is given, but no argument matches, then the pathname is considered to be of interest iff the X keyletter was given.

For c operations, the argument list is scanned left-to-right. Each argument with no -C, -X, or -I flag is considered for addition to the archive. When a directory is added to the archive, everything in it is considered for addition as well. For every thing that's being considered for addition, all arguments marked with -I or -X are scanned, left to right; the first match stops the scan. If the matching file is marked with -I, the file is included; if -X, it is not included. (If no such arguments match - for example, if no -I or -X options are present - it is included.) Note that the X keyletter is ignored. Arguments marked with -C cause tar to perform a chdir(2) call at that point in its pass through the argument list. If both -X and -I are given for the same argument, the last one given takes precedence. -W, -H, and -T function as described above for c operations. Note that arguments marked with -I and -X describe pathnames as they would go on the tape, regardless of where they appear in the argument list; with -C, the result can sometimes be counterintuitive. For example, tar cf - -C / vmunix -X usr/include/stdio.h -C /usr include will not work, because /usr/include/stdio.h would be archived under the name include/stdio.h, not usr/include/stdio.h.

FILES
/dev/rmt?

SEE ALSO
tar(5)

DIAGNOSTICS
Complaints about bad key characters and failing system calls.

AUTHOR
Mike Parker, at the time mouse@mcrcim.mcgill.edu. The impetus for, and the initial implementation of, the raw-filesystem code (the i keyletter and related options) is due to Concordia, in particular Steven Winikoff (then smw@alcor.concordia.ca) and Anne Bennett (then anne@alcor.concordia.ca).

BUGS
There is no direct way to ask for the n-th occurrence of a file, though it can be done by prepending a appropriate kill archive or using K carefully. Tape errors are handled ungracefully. There is no way to selectively follow symbolic links. Running out of memory usually means a coredump. Some corrupted archives can cause tar to crash. There is no way to turn options like M on for only some of the f arguments.