The tar command is used to process archive files. Archive files can only be placed on the POSIX file system, not on magnetic tapes and cartridges.
The actions to be performed are defined by the mainkey operand.
The tar command has been withdrawn from the XPG4 standard and replaced by the command pax.
Consequently, only the pax command should be used in the future, since tar is now supported only for compatibility reasons.
Syntax
tar mainkey[ modifier...][ file] |
Main keysmainkey consists of a “function character”, which may be specified with or without a hyphen (-). It may be immediately followed by one or more additional options called modifiers (see "tar file archiver"). mainkey can be one of the following characters:
(c- create) A new archive is created. The specified file or files are written at the start of the archive.
(r - replace) The specified file or files are appended to the end of the archive.
(u - update) The specified file or files are added to the archive if not already present in it or if the last modification time of the file to be archived is later than that of the archived file.
(t - table) tar prints a table, showing the contents of the archive. If one or more existing files from the archive files are specified, the names of the specified file or files are written to standard output. If no files are specified, the names of all files located in the archive are written to standard output.
(x - extract) The specified file or files are extracted from the archive. Files that are stored in the archive with relative pathnames are extracted to thecurrent directory. Files that are stored in the archive with absolute pathnames are extracted to the corresponding directory (if such a directory exists). If the specified file is a directory, all subdirectories contained in it are extracted recursively. If the specified file does not exist in the directory in which the extracted file is to be placed, it is created as a new file with the following attributes:
If the file already exists, the access permissions are not changed. If one or more files of the same name already exist in the archive, the last extracted file will overwrite all such files. |
ModifiersThe characters listed below can be directly appended to the main key as a modifier, provided the following rules are observed:
(v - verbose) The name of each processed file is written to standard error. Each name is preceded by one of the characters below, which indicates the type of processing:
The individual file names are then followed by the corresponding file size (in blocks). If the modifier v is used with the mainkey [-]t , the access permissions and the owner and group of the file are also displayed.
(w -what) For each file, tar waits for a confirmation before executing the corresponding function specified with mainkey. tar displays the following:
and expects you to enter your input after the colon. It is only after you enter your confirmation (with y or If w is not specified, the requested actions are performed without confirmation.
(f - file) The first specified file operand (or the second if b has already been specified) is interpreted as the name of the archive to be processed. If the specified name is '-' (a hyphen), the archive will be written to standard output or read from standard input. This makes it possible to use tar at both ends of a command pipe:
If f is not specified, the default archive file defined by the shell variable TAPE is used.
tar follows symbolic links. If h is omitted, tar will process only the symbolic link, but not the associated file.
(l - link ) tar issues a message when a reference to another file cannot be resolved. If l is omitted, no messages displayed.
(m - modification date/time) (modification date/time) On copying the specified file from the archive, tar sets the time of last modification for the copy to the current date and time. If m is omitted, the original date and time that was recorded in the archive are retained.
(o - owner) The file copied from the archive is assigned the same owner as the user who called tar. The file is also assigned the group of that user. If o is omitted, the original owner and group that was recorded in the archive are retained.
Pathname of a file or directory that is to be written to the archive (mainkey -c,-r or -u), read from an archive (mainkey -x), or listed (mainkey -t). If file is the name of a directory, the corresponding actions are applied (recursively) on all files and subdirectories of that directory. If the modifier f is specified, the first file operand is interpreted as the archive name. |
Variable
TAPE Determines the name of the archive to be used if the modifier f is not specified. |
Locale
The following environment variables affect the execution of tar: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other. LC_COLLATE Determine the collating sequence. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example 1
Create an archive file:
|
Example 2
List the contents of an archive file on standard output:
|
Example 3
Read files from an archive file of another user into the current directory: The files stored in the archive file have a different user ID and group ID than that of the user who calls the tar command. On reading the files from the archive, this user also wants the file ownership to be changed to his/her user ID and group ID, respectively: (1) $ id uid=3010(VSC0) gid=3030(VSCG0) (2) $ tar tvf /home/vsx/vsx1/km/example.TAR Tar: blocksize = 20 USTAR format archive rw-r--r-- 3001/3002 883 May 28 13:29 2008, ./pos_examp/file1 rw-r--r-- 3001/3002 1766 May 28 13:30 2008, ./pos_examp/file2 rw-r--r-- 3001/3002 2649 May 28 13:30 2008, ./pos_examp/file3 (3) $ tar xvfo /home/vsx/vsx1/km/example.TAR Tar: blocksize = 20 USTAR format archive tar: . : exists - no update x ./pos_examp/file1, 883 bytes, 2 tape blocks x ./pos_examp/file2, 1766 bytes, 4 tape blocks x ./pos_examp/file3, 2649 bytes, 6 tape blocks (4) $ ls -lR total 8 drwxr-xr-x 2 VSC0 VSCG0 2048 May 28 13:42 pos_examp ./pos_examp: total 24 -rw-r--r-- 1 VSC0 VSCG0 883 May 28 13:29 file1 -rw-r--r-- 1 VSC0 VSCG0 1766 May 28 13:30 file2 -rw-r--r-- 1 VSC0 VSCG0 2649 May 28 13:30 file3
|
Hint: Exchanging tar archives between Unix systems and BS2000
In Unix systems, tar archives are created in ASCII format. Since POSIX processes files in EBCDIC format by default and no normal ASCII-EBCDIC conversion of archive files is possible, the exchange of archive files can only occur via ASCII file systems. The following two variants briefly explain how this can be achieved: Variant 1 (with NFS) The tar archive is stored on the Unix system and can be accessed in POSIX (mounted via NFS). If the shell variable IO_CONVERSION is set to YES, the tar archive can be upacked with automatic conversion to the POSIX file system. Variant 2 (without NFS) An ASCII file system must be created in POSIX (see the description for POSIX filesystem marker = n under Install POSIX subsystem in the manual "POSIX Basics for Users and System Administrators" [1]. Setting the shell variable IO_CONVERSION=YES causes the files in such a file system to be treated as ASCII files. The tar archive must now be copied from the Unix system to the POSIX file system by means of a binary transfer. It can then be automatically converted to a POSIX EBCDIC file system when it is unpacked. |
See also
ar, cpio, pax |