NAME | SYNOPSIS | DESCRIPTION | OPTIONS | OPERANDS | EXAMPLES | ENVIRONMENT VARIABLES | EXIT STATUS | ATTRIBUTES | SEE ALSO | DIAGNOSTICS | NOTES
The tar command archives and extracts files to and from a single file called a tarfile. A tarfile is usually a magnetic tape, but it can be any file. tar's actions are controlled by the key argument. The key is a string of characters containing exactly one function letter (c, r, t , u, or x) and zero or more function modifiers (letters or digits), depending on the function letter used. The key string contains no SPACE characters. Function modifier arguments are listed on the command line in the same order as their corresponding function modifiers appear in the key string.
The -I include-file, -C directory file, and file arguments specify which files or directories are to be archived or extracted. In all cases, appearance of a directory name refers to the files and (recursively) subdirectories of that directory. Arguments appearing within braces ({}) indicate that one of the arguments must be specified.
The following options are supported:
Opens include-file containing a list of files, one per line, and treats it as if each file appeared separately on the command line. Be careful of trailing white spaces. Also beware of leading white spaces, since, for each line in the included file, the entire line (apart from the newline) will be used to match against the initial string of files to include. In the case where excluded files (see X function modifier) are also specified, they take precedence over all included files. If a file is specified in both the exclude-file and the include-file (or on the command line), it will be excluded.
Performs a chdir operation on directory and performs the c (create) or r (replace) operation on file. Use short relative path names for file. If file is ".", archive all files in directory. This option enables archiving files from multiple directories not related by a close common parent.
The following operands are supported:
A path name of a regular file or directory to be archived (when the c, r or u functions are specified), extracted (x) or listed (t). When file is the path name of a directory, the action applies to all of the files and (recursively) subdirectories of that directory.
When a file is archived, and the E flag (see Function Modifiers) is not specified, the filename cannot exceed 256 characters. In addition, it must be possible to split the name between parent directory names so that the prefix is no longer than 155 characters and the name is no longer than 100 characters. If E is specified, a name of up to PATH_MAX characters may be specified.
For example, a file whose basename is longer than 100 characters could not be archived without using the E flag. A file whose directory portion is 200 characters and whose basename is 50 characters could be archived (without using E) if a slash appears in the directory name somewhere in character positions 151-156.
Under ChorusOS, the path name cannot be more than 13 directories deep.
The function portion of the key is specified by one of the following letters:
Create. Writing begins at the beginning of the tarfile, instead of at the end.
Replace. The named files are written at the end of the tarfile. A file created with extended headers must be updated with extended headers (see E flag under Function Modifiers). A file created without extended headers cannot be modified with extended headers.
Table of Contents. The names of the specified files are listed each time they occur in the tarfile. If no file argument is given, the names of all files in the tarfile are listed. With the v function modifier, additional information for the specified files is displayed.
Update. The named files are written at the end of the tarfile if they are not already in the tarfile, or if they have been modified since last written to that tarfile. An update can be rather slow. A file created with extended headers must be updated with extended headers (see E flag under Function Modifiers). A file created without extended headers cannot be modified with extended headers.
Under ChorusOS, only one update may be performed per tarfile.
Extract or restore. The named files are extracted from the tarfile and written to the directory specified in the tarfile, relative to the current directory. Use the relative path names of files and directories to be extracted. If a named file matches a directory whose contents has been written to the tarfile, this directory is recursively extracted. The owner, modification time, and mode are restored (if possible); otherwise, to restore owner, you must be the super-user. Character-special and block-special devices (created by mknod(1M)) can only be extracted by the super-user. If no file argument is given, the entire content of the tarfile is extracted. If the tarfile contains several files with the same name, each file is written to the appropriate directory, overwriting the previous one. Filename substitution wildcards cannot be used for extracting files from the archive.
When extracting tapes created with the r or u functions, directory modification times may not be set correctly. These same functions cannot be used with many tape drives due to tape drive limitations such as the absence of backspace or append capabilities.
When using the r, u, or x functions or the X function modifier, the named files must match exactly the corresponding files in the tarfile. For example, to extract ./thisfile, you must specify ./thisfile, and not thisfile. The t function displays how each file was archived.
The characters below may be used in conjunction with the letter that selects the desired function.
Blocking Factor. Use when reading or writing to raw magnetic archives (see f below). The block argument specifies the number of 512-byte tape blocks to be included in each read or write operation performed on the tarfile. The minimum is 1, the default is 20. The maximum value is a function of the amount of memory available and the blocking requirements of the specific tape device involved. The maximum cannot exceed INT_MAX/512 (4194303).
When a tape archive is being read, its actual blocking factor will be automatically detected, provided that it is less than or equal to the nominal blocking factor (the value of the block argument, or the default value if the b modifier is not specified). If the actual blocking factor is greater than the nominal blocking factor, a read error will result.
The automatic determination of the actual blocking factor may be fooled when reading from a pipe or a socket (see the B function modifier below).
1/4" streaming tape has an inherent blocking factor of one 512-byte block. It can be read or written using any blocking factor.
This function modifier works for archives on disk files and block special devices, among others, but is intended principally for tape devices.
Block. Force tar to perform multiple reads (if necessary) to read exactly enough bytes to fill a block. This function modifier enables tar to work across the Ethernet, since pipes and sockets return partial blocks even when more data is coming. When reading from standard input, "-", this function modifier is selected by default to ensure that tar can recover from short reads.
Error. Exit immediately with a positive exit status if any unexpected errors occur. The SYSV3 environment variable overrides the default behavior. (See ENVIRONMENT section below.)
Write a tarfile with extended headers. (Used with c, r, or u options; ignored with t or x options.) When a tarfile is written with extended headers, the modification time is maintained with a granularity of microseconds rather than seconds. In addition, filenames no longer than PATH_MAX characters that could not be archived without E, and file sizes greater than 8GB, are supported. The E flag is required whenever the larger files and/or files with longer names, or whose UID/GID exceed 2097151, are to be archived, or if time granularity of microseconds is desired.
File. Use the tarfile argument as the name of the tarfile. If f is specified, /etc/default/tar is not searched. If f is omitted, tar will use the device indicated by the TAPE environment variable, if set; otherwise, it will use the default values defined in /etc/default/tar. If the name of the tarfile is "-", tar writes to the standard output or reads from the standard input, whichever is appropriate. tar can be used as the head or tail of a pipeline.
Under ChorusOS, this flag is required as no tape devices are currently available.
With one F argument, tar excludes all directories named SCCS and RCS from the tarfile. With two arguments, FF, tar excludes all directories named SCCS and RCS, all files with .o as their suffix, and all files named errs, core, and a.out. The SYSV3 environment variable overrides the default behavior. (See ENVIRONMENT section below.)
Follow symbolic links as if they were normal files or directories. Normally, tar does not follow symbolic links.
Ignore directory checksum errors.
Requires tar to use the size argument as the size of an archive in kilobytes. This is useful when the archive is intended for a fixed size device such as floppy disks. Large files are then split across volumes if they do not fit in the specified size.
Link. Output error message if unable to resolve all links to the files being archived. If l is not specified, no error messages are printed.
Modify. The modification time of the file is the time of extraction. This function modifier is valid only with the x function.
The file being read is a non-tape device. Reading of the archive is faster since tar can randomly seek around the archive.
Ownership. Assign to extracted files the user and group identifiers of the user running the program, rather than those on tarfile. This is the default behavior for users other than root. If the o function modifier is not set and the user is root, the extracted files will take on the group and user identifiers of the files on tarfile (see chown(2POSIX) for more information). The o function modifier is only valid with the x function.
Restore the named files to their original modes, if applicable, ignoring the present umask(2POSIX). SETUID and stick information are also extracted for the super-user.
Suppress the addition of a trailing "/" on directory entries in the archive.
Stop after extracting the first occurrence of the named file. tar will normally continue reading the archive after finding an occurrence of a file.
Verbose. Output the name of each file preceded by the function letter. With the t function, v provides additional information about the tarfile entries. The listing is similar to the format produced by the -l option of the ls(1CC) command.
What. Output the action to be taken and the name of the file, then await the user's confirmation. If the response is affirmative, the action is performed; otherwise, the action is not performed. This function modifier cannot be used with the t function.
Exclude. Use the exclude-file argument as a file containing a list of relative path names for files (or directories) to be excluded from the tarfile when using the functions c, x, or t. Be careful of trailing white spaces. Also beware of leading white spaces, since, for each line in the excluded file, the entire line (apart from the newline) will be used to match against the initial string of files to exclude. Multiple X arguments may be used, with one exclude-file per argument. In the case where included files (see -I include-file option) are also specified, the excluded files take precedence over all included files. If a file is specified in both the exclude-file and the include-file (or on the command line), it will be excluded.
The following is an example that uses tar to create an archive of the etc directory in a file foo.tar:
example% rsh target arun /bin/tar cvf /tmp/foo.tar etc |
The c function letter means create the archive; the v function modifier outputs messages explaining what tar is doing; the f function modifier indicates that the tarfile is being specified as /tmp/foo.tar. The etc at the end of the command line indicates the directory to archive recursively in /tmp/foo.tar.
The following is an example that uses tar to display the table of contents of the tarfile /tmp/foo.tar:
example% rsh target arun /bin/tar tvf /tmp/foo.tar |
The output will be similar to the following:
rw-r--r-- 1677/40 2123 Feb 15 18:15 2000 etc/security ... |
The columns have the following meanings:
Column 1 shows the access permissions to the /etc/security file.
Column 2 shows the user and group ID of the /etc/security file.
Column 3 shows the size of the file in bytes.
Column 4 shows the modification date of the file.
Column 5 shows the name of the file.
The following is an example that uses tar to extract the contents of the tarfile /tmp/foo.tar:
example% rsh target arun /bin/tar xf /tmp/foo.tar |
This variable is used to override the default behavior of tar, provide compatibility with INTERACTIVE UNIX Systems and SCO UNIX installation scripts, and should not be used in new scripts. (It is intended for compatibility purposes only.) When set, the following options behave differently:
Uses filename to obtain a list of command line switches and files on which to operate.
Prevents files from being split across volumes. If there is insufficient room on one volume, tar prompts for a new volume. If the file will not fit on the new volume, tar exits with an error.
The TZ environment variable affects the execution of tar.
The TMPDIR environment variable can be used to define and alternate temporary directory (other than /tmp).
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
Diagnostic messages are output for bad key characters and tape read/write errors, and for insufficient memory to hold the link tables.
There is no way to access the n-th occurrence of a file.
The tar archive format allows UIDs and GIDs up to 2097151 to be stored in the archive header. Files with UIDs and GIDs greater than this value will be archived with the UID and GID of 60001.
NAME | SYNOPSIS | DESCRIPTION | OPTIONS | OPERANDS | EXAMPLES | ENVIRONMENT VARIABLES | EXIT STATUS | ATTRIBUTES | SEE ALSO | DIAGNOSTICS | NOTES