Contained WithinFind More DocumentationFeatured Support Resources | Download this book in PDF (7229 KB)
tar(1)Name | Synopsis | Description | Operands | Usage | Examples | Environment Variables | Exit Status | Files | Attributes | See Also | Diagnostics | Notes Name
Synopsis
tar c[BDeEFhilnopPqTvw@/[0-7]][bfk][X...] [blocksize]
[tarfile] [size] [exclude-file]...
{file | -I include-file | -C directory file}...
tar r[BDeEFhilnqTvw@/[0-7]][bfk] [blocksize] [tarfile]
[size]
{file | -I include-file | -C directory file}...
tar t[BeFhilnqTv[0-7]][fk][X...] [tarfile] [size]
[exclude-file]... {file | -I include-file}...
tar u[BDeEFhilnqTvw@/[0-7]][bfk] [blocksize] [tarfile]
[size] file...
tar x[BeFhilmnopqTvw@/[0-7]][fk][X...] [tarfile] [size]
[exclude-file]... [file]...
DescriptionThe 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. Operands
The following operands are supported: Function LettersThe function portion of the key is specified by one of the following letters: When extracting tapes created with the r or u functions, directory modification times can 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. Function ModifiersThe characters below can be used in conjunction with the letter that selects the desired function. UsageSee largefile(5) for the description of the behavior of tar when encountering files greater than or equal to 2 Gbyte ( 231 bytes). The automatic determination of the actual blocking factor can 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. For information on tar header format, see archives.h(3HEAD). Examples
Example 1 Creating an archive of your home directoryThe following is an example using tar to create an archive of your home directory on a tape mounted on drive /dev/rmt/0:
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 (/dev/rmt/0 in this example). The dot (.) at the end of the command line indicates the current directory and is the argument of the f function modifier. Display the table of contents of the tarfile with the following command:
The output is similar to the following for the POSIX locale:
The columns have the following meanings: To extract files from the archive:
If there are multiple archive files on a tape, each is separated from the following one by an EOF marker. To have tar read the first and second archives from a tape with multiple archives on it, the non-rewinding version of the tape device name must be used with the f function modifier, as follows:
Notice that in some earlier releases, the above scenario did not work correctly, and intervention with mt(1) between tar invocations was necessary. To emulate the old behavior, use the non-rewind device name containing the letter b for BSD behavior. See the Close Operations section of the mtio(7I) manual page. Example 2 Archiving files from /usr/include and from /etc to default tape drive 0To archive files from /usr/include and from /etc to default tape drive 0:
The table of contents from the resulting tarfile would produce output like the following:
To extract all files in the include directory:
Example 3 Transferring files across the networkThe following is an example using tar to transfer files across the network. First, here is how to archive files from the local machine (example) to a tape on a remote system (host):
In the example above, we are creating a tarfile with the c key letter, asking for verbose output from tar with the v function modifier, specifying the name of the output tarfile using the f function modifier (the standard output is where the tarfile appears, as indicated by the `-' sign), and specifying the blocksize (20) with the b function modifier. If you want to change the blocksize, you must change the blocksize arguments both on the tar command and on the dd command. Example 4 Retrieving files from a tape on the remote system back to the local systemThe following is an example that uses tar to retrieve files from a tape on the remote system back to the local system:
In the example above, we are extracting from the tarfile with the x key letter, asking for verbose output from tar with the v function modifier, telling tar it is reading from a pipe with the B function modifier, specifying the name of the input tarfile using the f function modifier (the standard input is where the tarfile appears, as indicated by the “-” sign), and specifying the blocksize (20) with the b function modifier. Example 5 Creating an archive of the home directoryThe following example creates an archive of the home directory on /dev/rmt/0 with an actual blocking factor of 19:
To recognize this archive's actual blocking factor without using the b function modifier:
To recognize this archive's actual blocking factor using a larger nominal blocking factor:
Attempt to recognize this archive's actual blocking factor using a nominal blocking factor that is too small:
Environment Variables
See environ(5) for descriptions of the following environment variables that affect the execution of tar: LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_TIME, TZ, and NLSPATH. Affirmative responses are processed using the extended regular expression defined for the yesexpr keyword in the LC_MESSAGES category of the user's locale. The locale specified in the LC_COLLATE category defines the behavior of ranges, equivalence classes, and multi-character collating elements used in the expression defined for yesexpr. The locale specified in LC_CTYPE determines the locale for interpretation of sequences of bytes of text data a characters, the behavior of character classes used in the expression defined for the yesexpr. See locale(5). Exit StatusFiles
AttributesSee attributes(5) for descriptions of the following attributes:
See Alsoar(1), basename(1), cd(1), chown(1), cpio(1), csh(1), dirname(1), find(1), ls(1), mt(1), pax(1), setfacl(1), umask(1), mknod(1M), archives.h(3HEAD), attributes(5), environ(5), fsattr(5), largefile(5), mtio(7I) DiagnosticsDiagnostic messages are output for bad key characters and tape read/write errors, and for insufficient memory to hold the link tables. Notes
There is no way to access the n-th occurrence of a file. Tape errors are handled ungracefully. 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 is archived with the UID and GID of 60001. If an archive is created that contains files whose names were created by processes running in multiple locales, a single locale that uses a full 8-bit codeset (for example, the en_US locale) should be used both to create the archive and to extract files from the archive. Neither the r function letter nor the u function letter can be used with quarter-inch archive tapes, since these tape drives cannot backspace. Since tar has no options, the standard “--” argument that is normally used in other utilities to terminate recognition of options is not needed. If used, it is recognized only as the first argument and is ignored. Since -C directory file and -I include-file are multi-argument operands, any of the following methods can be used to archive or extract a file named -C or -I: Name | Synopsis | Description | Operands | Usage | Examples | Environment Variables | Exit Status | Files | Attributes | See Also | Diagnostics | Notes |
||||||||||||||||||||||||||||||||||||