4mTAR24m(1) General Commands Manual 4mTAR24m(1) 1mNAME0m tar — manipulate tape archives 1mSYNOPSIS0m 1mtar 22m[4mbundled-flags24m ⟨args⟩] [⟨4mfile24m⟩ | ⟨4mpattern24m⟩ ...] 1mtar 22m{1m-c22m} [4moptions24m] [4mfiles24m | 4mdirectories24m] 1mtar 22m{1m-r 22m| 1m-u22m} 1m-f 4m22marchive-file24m [4moptions24m] [4mfiles24m | 4mdirectories24m] 1mtar 22m{1m-t 22m| 1m-x22m} [4moptions24m] [4mpatterns24m] 1mDESCRIPTION0m 1mtar 22mcreates and manipulates streaming archive files. This implementa‐ tion can extract from tar, pax, cpio, zip, jar, ar, xar, rpm, 7-zip, and ISO 9660 cdrom images and can create tar, pax, cpio, ar, zip, 7-zip, and shar archives. The first synopsis form shows a “bundled” option word. This usage is provided for compatibility with historical implementations. See COM‐ PATIBILITY below for details. The other synopsis forms show the preferred usage. The first option to 1mtar 22mis a mode indicator from the following list: 1m-c 22mCreate a new archive containing the specified items. The long option form is 1m--create22m. 1m-r 22mLike 1m-c22m, but new entries are appended to the archive. Note that this only works on uncompressed archives stored in regular files. The 1m-f 22moption is required. The long option form is 1m--append22m. 1m-t 22mList archive contents to stdout. The long option form is 1m--list22m. 1m-u 22mLike 1m-r22m, but new entries are added only if they have a modifi‐ cation date newer than the corresponding entry in the archive. Note that this only works on uncompressed archives stored in regular files. The 1m-f 22moption is required. The long form is 1m--update22m. 1m-x 22mExtract to disk from the archive. If a file with the same name appears more than once in the archive, each copy will be ex‐ tracted, with later copies overwriting (replacing) earlier copies. The long option form is 1m--extract22m. In 1m-c22m, 1m-r22m, or 1m-u 22mmode, each specified file or directory is added to the archive in the order specified on the command line. By default, the contents of each directory are also archived. In extract or list mode, the entire command line is read and parsed be‐ fore the archive is opened. The pathnames or patterns on the command line indicate which items in the archive should be processed. Patterns are shell-style globbing patterns as documented in 4mtcsh24m(1). 1mOPTIONS0m Unless specifically stated otherwise, options are applicable in all op‐ erating modes. 1m@4m22marchive0m (c and r modes only) The specified archive is opened and the entries in it will be appended to the current archive. As a simple example, 1mtar -c -f 4m22m-24m 4mnewfile24m 1m@4m22moriginal.tar0m writes a new archive to standard output containing a file 4mnewfile24m and all of the entries from 4moriginal.tar24m. In contrast, 1mtar -c -f 4m22m-24m 4mnewfile24m 4moriginal.tar0m creates a new archive with only two entries. Similarly, 1mtar -czf 4m22m-24m 1m--format pax @4m22m-0m reads an archive from standard input (whose format will be de‐ termined automatically) and converts it into a gzip-compressed pax-format archive on stdout. In this way, 1mtar 22mcan be used to convert archives from one format to another. 1m-a22m, 1m--auto-compress0m (c mode only) Use the archive suffix to decide a set of the format and the compressions. As a simple example, 1mtar -a -cf 4m22marchive.tgz24m 4msource.c24m 4msource.h0m creates a new archive with restricted pax format and gzip com‐ pression, 1mtar -a -cf 4m22marchive.tar.bz2.uu24m 4msource.c24m 4msource.h0m creates a new archive with restricted pax format and bzip2 com‐ pression and uuencode compression, 1mtar -a -cf 4m22marchive.zip24m 4msource.c24m 4msource.h0m creates a new archive with zip format, 1mtar -a -jcf 4m22marchive.tgz24m 4msource.c24m 4msource.h0m ignores the “-j” option, and creates a new archive with re‐ stricted pax format and gzip compression, 1mtar -a -jcf 4m22marchive.xxx24m 4msource.c24m 4msource.h0m if it is unknown suffix or no suffix, creates a new archive with restricted pax format and bzip2 compression. 1m--acls 22m(c, r, u, x modes only) Archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of 1m--no-acls 22mand the default behav‐ ior in c, r, and u modes (except on Mac OS X) or if 1mtar 22mis run in x mode as root. On Mac OS X this option translates extended ACLs to NFSv4 ACLs. To store extended ACLs the 1m--mac-metadata0m option is preferred. 1m-B22m, 1m--read-full-blocks0m Ignored for compatibility with other 4mtar24m(1) implementations. 1m-b 4m22mblocksize24m, 1m--block-size 4m22mblocksize0m Specify the block size, in 512-byte records, for tape drive I/O. As a rule, this argument is only needed when reading from or writing to tape drives, and usually not even then as the de‐ fault block size of 20 records (10240 bytes) is very common. 1m-C 4m22mdirectory24m, 1m--cd 4m22mdirectory24m, 1m--directory 4m22mdirectory0m In c and r mode, this changes the directory before adding the following files. In x mode, change directories after opening the archive but before extracting entries from the archive. 1m--chroot0m (x mode only) 1mchroot22m() to the current directory after process‐ ing any 1m-C 22moptions and before extracting any files. 1m--clear-nochange-fflags0m (x mode only) Before removing file system objects to replace them, clear platform-specific file attributes or file flags that might prevent removal. 1m--exclude 4m22mpattern0m Do not process files or directories that match the specified pattern. Note that exclusions take precedence over patterns or filenames specified on the command line. 1m--exclude-vcs0m Do not process files or directories internally used by the ver‐ sion control systems ‘Arch’, ‘Bazaar’, ‘CVS’, ‘Darcs’, ‘Mercurial’, ‘RCS’, ‘SCCS’, ‘SVN’ and ‘git’. 1m--fflags0m (c, r, u, x modes only) Archive or extract platform-specific file attributes or file flags. This is the reverse of 1m--no-fflags 22mand the default behavior in c, r, and u modes or if 1mtar 22mis run in x mode as root. 1m--format 4m22mformat0m (c, r, u mode only) Use the specified format for the created archive. Supported formats include “cpio”, “pax”, “shar”, and “ustar”. Other formats may also be supported; see 4mlibarchive-formats24m(5) for more information about currently-sup‐ ported formats. In r and u modes, when extending an existing archive, the format specified here must be compatible with the format of the existing archive on disk. 1m-f 4m22mfile24m, 1m--file 4m22mfile0m Read the archive from or write the archive to the specified file. The filename can be 4m-24m for standard input or standard output. The default varies by system; on FreeBSD, the default is 4m/dev/sa024m; on Linux, the default is 4m/dev/st024m. 1m--gid 4m22mid0m Use the provided group id number. On extract, this overrides the group id in the archive; the group name in the archive will be ignored. On create, this overrides the group id read from disk; if 1m--gname 22mis not also specified, the group name will be set to match the group id. 1m--gname 4m22mname0m Use the provided group name. On extract, this overrides the group name in the archive; if the provided group name does not exist on the system, the group id (from the archive or from the 1m--gid 22moption) will be used instead. On create, this sets the group name that will be stored in the archive; the name will not be verified against the system group database. 1m--group 4m22mname24m[:4mgid24m] Use the provided group, if 4mgid24m is not provided, 4mname24m can be ei‐ ther a group name or numeric id. See the 1m--gname 22moption for details. 1m-H 22m(c and r modes only) Symbolic links named on the command line will be followed; the target of the link will be archived, not the link itself. 1m-h 22m(c and r modes only) Synonym for 1m-L22m. 1m-I 22mSynonym for 1m-T22m. 1m--help 22mShow usage. 1m--hfsCompression0m (x mode only) Mac OS X specific (v10.6 or later). Compress ex‐ tracted regular files with HFS+ compression. 1m--ignore-zeros0m An alias of 1m--options read_concatenated_archives 22mfor compati‐ bility with GNU tar. 1m--include 4m22mpattern0m Process only files or directories that match the specified pat‐ tern. Note that exclusions specified with 1m--exclude 22mtake precedence over inclusions. If no inclusions are explicitly specified, all entries are processed by default. The 1m--include0m option is especially useful when filtering archives. For exam‐ ple, the command 1mtar -c -f 4m22mnew.tar24m 1m--include='*foo*' @4m22mold.tgz0m creates a new archive 4mnew.tar24m containing only the entries from 4mold.tgz24m containing the string ‘foo’. 1m-J22m, 1m--xz0m (c mode only) Compress the resulting archive with 4mxz24m(1). In extract or list modes, this option is ignored. Note that this 1mtar 22mimplementation recognizes XZ compression automatically when reading archives. 1m-j22m, 1m--bzip22m, 1m--bzip222m, 1m--bunzip20m (c mode only) Compress the resulting archive with 4mbzip224m(1). In extract or list modes, this option is ignored. Note that this 1mtar 22mimplementation recognizes bzip2 compression automatically when reading archives. 1m-k22m, 1m--keep-old-files0m (x mode only) Do not overwrite existing files. In particular, if a file appears more than once in an archive, later copies will not overwrite earlier copies. 1m--keep-newer-files0m (x mode only) Do not overwrite existing files that are newer than the versions appearing in the archive being extracted. 1m-L22m, 1m--dereference0m (c and r modes only) All symbolic links will be followed. Nor‐ mally, symbolic links are archived as such. With this option, the target of the link will be archived instead. 1m-l22m, 1m--check-links0m (c and r modes only) Issue a warning message unless all links to each file are archived. 1m--lrzip0m (c mode only) Compress the resulting archive with 4mlrzip24m(1). In extract or list modes, this option is ignored. Note that this 1mtar 22mimplementation recognizes lrzip compression automatically when reading archives. 1m--lz4 22m(c mode only) Compress the archive with lz4-compatible compres‐ sion before writing it. In extract or list modes, this option is ignored. Note that this 1mtar 22mimplementation recognizes lz4 compression automatically when reading archives. 1m--zstd 22m(c mode only) Compress the archive with zstd-compatible com‐ pression before writing it. In extract or list modes, this op‐ tion is ignored. Note that this 1mtar 22mimplementation recognizes zstd compression automatically when reading archives. 1m--lzma 22m(c mode only) Compress the resulting archive with the original LZMA algorithm. In extract or list modes, this option is ig‐ nored. Use of this option is discouraged and new archives should be created with 1m--xz 22minstead. Note that this 1mtar 22mimple‐ mentation recognizes LZMA compression automatically when read‐ ing archives. 1m--lzop 22m(c mode only) Compress the resulting archive with 4mlzop24m(1). In extract or list modes, this option is ignored. Note that this 1mtar 22mimplementation recognizes LZO compression automatically when reading archives. 1m-m22m, 1m--modification-time0m (x mode only) Do not extract modification time. By default, the modification time is set to the time stored in the archive. 1m--mac-metadata0m (c, r, u and x mode only) Mac OS X specific. Archive or ex‐ tract extended ACLs and extended file attributes using 4mcopyfile24m(3) in AppleDouble format. This is the reverse of 1m--no-mac-metadata22m. and the default behavior in c, r, and u modes or if 1mtar 22mis run in x mode as root. Currently supported only for pax formats (including "pax restricted", the default tar format for bsdtar.) 1m-n22m, 1m--norecurse22m, 1m--no-recursion0m Do not operate recursively on the content of directories. 1m--newer 4m22mdate0m (c, r, u modes only) Only include files and directories newer than the specified date. This compares ctime entries. 1m--newer-mtime 4m22mdate0m (c, r, u modes only) Like 1m--newer22m, except it compares mtime en‐ tries instead of ctime entries. 1m--newer-than 4m22mfile0m (c, r, u modes only) Only include files and directories newer than the specified file. This compares ctime entries. 1m--newer-mtime-than 4m22mfile0m (c, r, u modes only) Like 1m--newer-than22m, except it compares mtime entries instead of ctime entries. 1m--nodump0m (c and r modes only) Honor the nodump file flag by skipping this file. 1m--nopreserveHFSCompression0m (x mode only) Mac OS X specific (v10.6 or later). Do not com‐ press extracted regular files which were compressed with HFS+ compression before archived. By default, compress the regular files again with HFS+ compression. 1m--null 22m(use with 1m-I 22mor 1m-T22m) Filenames or patterns are separated by null characters, not by newlines. This is often used to read file‐ names output by the 1m-print0 22moption to 4mfind24m(1). 1m--no-acls0m (c, r, u, x modes only) Do not archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of 1m--acls 22mand the default be‐ havior if 1mtar 22mis run as non-root in x mode (on Mac OS X as any user in c, r, u and x modes). 1m--no-fflags0m (c, r, u, x modes only) Do not archive or extract file attrib‐ utes or file flags. This is the reverse of 1m--fflags 22mand the default behavior if 1mtar 22mis run as non-root in x mode. 1m--no-mac-metadata0m (x mode only) Mac OS X specific. Do not archive or extract ACLs and extended file attributes using 4mcopyfile24m(3) in Apple‐ Double format. This is the reverse of 1m--mac-metadata22m. and the default behavior if 1mtar 22mis run as non-root in x mode. 1m--no-read-sparse0m (c, r, u modes only) Do not read sparse file information from disk. This is the reverse of 1m--read-sparse22m. 1m--no-safe-writes0m (x mode only) Do not create temporary files and use 4mrename24m(2) to replace the original ones. This is the reverse of 1m--safe-writes22m. 1m--no-same-owner0m (x mode only) Do not extract owner and group IDs. This is the reverse of 1m--same-owner 22mand the default behavior if 1mtar 22mis run as non-root. 1m--no-same-permissions0m (x mode only) Do not extract full permissions (SGID, SUID, sticky bit, file attributes or file flags, extended file at‐ tributes and ACLs). This is the reverse of 1m-p 22mand the default behavior if 1mtar 22mis run as non-root. 1m--no-xattrs0m (c, r, u, x modes only) Do not archive or extract extended file attributes. This is the reverse of 1m--xattrs 22mand the default behavior if 1mtar 22mis run as non-root in x mode. 1m--numeric-owner0m This is equivalent to 1m--uname 22m"" 1m--gname 22m"". On extract, it causes user and group names in the archive to be ignored in fa‐ vor of the numeric user and group ids. On create, it causes user and group names to not be stored in the archive. 1m-O22m, 1m--to-stdout0m (x, t modes only) In extract (-x) mode, files will be written to standard out rather than being extracted to disk. In list (-t) mode, the file listing will be written to stderr rather than the usual stdout. 1m-o 22m(x mode) Use the user and group of the user running the program rather than those specified in the archive. Note that this has no significance unless 1m-p 22mis specified, and the program is be‐ ing run by the root user. In this case, the file modes and flags from the archive will be restored, but ACLs or owner in‐ formation in the archive will be discarded. 1m-o 22m(c, r, u mode) A synonym for 1m--format 4m22mustar0m 1m--older 4m22mdate0m (c, r, u modes only) Only include files and directories older than the specified date. This compares ctime entries. 1m--older-mtime 4m22mdate0m (c, r, u modes only) Like 1m--older22m, except it compares mtime en‐ tries instead of ctime entries. 1m--older-than 4m22mfile0m (c, r, u modes only) Only include files and directories older than the specified file. This compares ctime entries. 1m--older-mtime-than 4m22mfile0m (c, r, u modes only) Like 1m--older-than22m, except it compares mtime entries instead of ctime entries. 1m--one-file-system0m (c, r, and u modes) Do not cross mount points. 1m--options 4m22moptions0m Select optional behaviors for particular modules. The argument is a text string containing comma-separated keywords and val‐ ues. These are passed to the modules that handle particular formats to control how those formats will behave. Each option has one of the following forms: 4mkey=value0m The key will be set to the specified value in every module that supports it. Modules that do not support this key will ignore it. 4mkey24m The key will be enabled in every module that supports it. This is equivalent to 4mkey24m1m=122m. 4m!key24m The key will be disabled in every module that supports it. 4mmodule:key=value24m, 4mmodule:key24m, 4mmodule:!key0m As above, but the corresponding key and value will be provided only to modules whose name matches 4mmodule24m. The complete list of supported modules and keys for create and append modes is in 4marchive_write_set_options24m(3) and for extract and list modes in 4marchive_read_set_options24m(3). Examples of supported options: 1miso9660:joliet0m Support Joliet extensions. This is enabled by default, use 1m!joliet 22mor 1miso9660:!joliet 22mto disable. 1miso9660:rockridge0m Support Rock Ridge extensions. This is enabled by de‐ fault, use 1m!rockridge 22mor 1miso9660:!rockridge 22mto disable. 1mgzip:compression-level0m A decimal integer from 1 to 9 specifying the gzip com‐ pression level. 1mgzip:timestamp0m Store timestamp. This is enabled by default, use 1m!timestamp 22mor 1mgzip:!timestamp 22mto disable. 1mlrzip:compression22m=4mtype0m Use 4mtype24m as compression method. Supported values are bzip2, gzip, lzo (ultra fast), and zpaq (best, ex‐ tremely slow). 1mlrzip:compression-level0m A decimal integer from 1 to 9 specifying the lrzip com‐ pression level. 1mlz4:compression-level0m A decimal integer from 1 to 9 specifying the lzop com‐ pression level. 1mlz4:stream-checksum0m Enable stream checksum. This is by default, use 1mlz4:!stream-checksum 22mto disable. 1mlz4:block-checksum0m Enable block checksum (Disabled by default). 1mlz4:block-size0m A decimal integer from 4 to 7 specifying the lz4 com‐ pression block size (7 is set by default). 1mlz4:block-dependence0m Use the previous block of the block being compressed for a compression dictionary to improve compression ra‐ tio. 1mzstd:compression-level22m=4mN0m A decimal integer specifying the zstd compression level. Supported values depend on the library version, common values are from 1 to 22. 1mzstd:threads22m=4mN0m Specify the number of worker threads to use, or 0 to use as many threads as there are CPU cores in the sys‐ tem. 1mzstd:frame-per-file0m Start a new compression frame at the beginning of each file in the archive. 1mzstd:min-frame-in22m=4mN0m In combination with 1mzstd:frame-per-file22m, do not start a new compression frame unless the uncompressed size of the current frame is at least 4mN24m bytes. The number may be followed by 1mk / kB22m, 1mM / MB22m, or 1mG / GB 22mto indicate kilobytes, megabytes or gigabytes respectively. 1mzstd:min-frame-out22m=4mN24m, 1mzstd:min-frame-size22m=4mN0m In combination with 1mzstd:frame-per-file22m, do not start a new compression frame unless the compressed size of the current frame is at least 4mN24m bytes. The number may be followed by 1mk / kB22m, 1mM / MB22m, or 1mG / GB 22mto indicate kilo‐ bytes, megabytes or gigabytes respectively. 1mzstd:max-frame-in22m=4mN24m, 1mzstd:max-frame-size22m=4mN0m Start a new compression frame as soon as possible after the uncompressed size of the current frame exceeds 4mN0m bytes. The number may be followed by 1mk / kB22m, 1mM / MB22m, or 1mG / GB 22mto indicate kilobytes, megabytes or gigabytes respectively. Values less than 1,024 will be rejected. 1mzstd:max-frame-out22m=4mN0m Start a new compression frame as soon as possible after the compressed size of the current frame exceeds 4mN0m bytes. The number may be followed by 1mk / kB22m, 1mM / MB22m, or 1mG / GB 22mto indicate kilobytes, megabytes or gigabytes respectively. Values less than 1,024 will be rejected. 1mlzop:compression-level0m A decimal integer from 1 to 9 specifying the lzop com‐ pression level. 1mxz:compression-level0m A decimal integer from 0 to 9 specifying the xz com‐ pression level. 1mxz:threads0m Specify the number of worker threads to use. Setting threads to a special value 0 makes 4mxz24m(1) use as many threads as there are CPU cores on the system. 1mmtree:4m22mkeyword0m The mtree writer module allows you to specify which mtree keywords will be included in the output. Sup‐ ported keywords include: 1mcksum22m, 1mdevice22m, 1mflags22m, 1mgid22m, 1mgname22m, 1mindent22m, 1mlink22m, 1mmd522m, 1mmode22m, 1mnlink22m, 1mrmd16022m, 1msha122m, 1msha25622m, 1msha38422m, 1msha51222m, 1msize22m, 1mtime22m, 1muid22m, 1muname22m. The default is equivalent to: “device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname”. 1mmtree:all0m Enables all of the above keywords. You can also use 1mmtree:!all 22mto disable all keywords. 1mmtree:use-set0m Enable generation of 1m/set 22mlines in the output. 1mmtree:indent0m Produce human-readable output by indenting options and splitting lines to fit into 80 columns. 1mzip:compression22m=4mtype0m Use 4mtype24m as compression method. Supported values are store (uncompressed) and deflate (gzip algorithm). 1mzip:encryption0m Enable encryption using traditional zip encryption. 1mzip:encryption22m=4mtype0m Use 4mtype24m as encryption type. Supported values are zipcrypt (traditional zip encryption), aes128 (WinZip AES-128 encryption) and aes256 (WinZip AES-256 encryp‐ tion). 1mread_concatenated_archives0m Ignore zeroed blocks in the archive, which occurs when multiple tar archives have been concatenated together. Without this option, only the contents of the first concatenated archive would be read. This option is comparable to the 1m-i22m, 1m--ignore-zeros 22moption of GNU tar. If a provided option is not supported by any module, that is a fatal error. 1m-P22m, 1m--absolute-paths0m Preserve pathnames. By default, absolute pathnames (those that begin with a / character) have the leading slash removed both when creating archives and extracting from them. Also, 1mtar0m will refuse to extract archive entries whose pathnames contain 4m..24m or whose target directory would be altered by a symlink. This option suppresses these behaviors. 1m-p22m, 1m--insecure22m, 1m--preserve-permissions0m (x mode only) Preserve file permissions. Attempt to restore the full permissions, including file modes, file attributes or file flags, extended file attributes and ACLs, if available, for each item extracted from the archive. This is the reverse of 1m--no-same-permissions 22mand the default if 1mtar 22mis being run as root. It can be partially overridden by also specifying 1m--no-acls22m, 1m--no-fflags22m, 1m--no-mac-metadata 22mor 1m--no-xattrs22m. 1m--passphrase 4m22mpassphrase0m The 4mpassphrase24m is used to extract or create an encrypted archive. Currently, zip is the only supported format that sup‐ ports encryption. You shouldn't use this option unless you re‐ alize how insecure use of this option is. 1m--posix0m (c, r, u mode only) Synonym for 1m--format 4m22mpax0m 1m-q22m, 1m--fast-read0m (x and t mode only) Extract or list only the first archive en‐ try that matches each pattern or filename operand. Exit as soon as each specified pattern or filename has been matched. By default, the archive is always read to the very end, since there can be multiple entries with the same name and, by con‐ vention, later entries overwrite earlier entries. This option is provided as a performance optimization. 1m--read-sparse0m (c, r, u modes only) Read sparse file information from disk. This is the reverse of 1m--no-read-sparse 22mand the default behav‐ ior. 1m-S 22m(x mode only) Extract files as sparse files. For every block on disk, check first if it contains only NULL bytes and seek over it otherwise. This works similar to the conv=sparse op‐ tion of dd. 1m-s 4m22mpattern0m Modify file or archive member names according to 4mpattern24m. The pattern has the format 4m/old/new/24m[bghHprRsS] where 4mold24m is a ba‐ sic regular expression, 4mnew24m is the replacement string of the matched part, and the optional trailing letters modify how the replacement is handled. If 4mold24m is not matched, the pattern is skipped. Within 4mnew24m, ~ is substituted with the match, \1 to \9 with the content of the corresponding captured group. The op‐ tional trailing g specifies that matching should continue after the matched part and stop on the first unmatched pattern. The optional trailing s specifies that the pattern applies to the value of symbolic links. The optional trailing p specifies that after a successful substitution the original path name and the new path name should be printed to standard error. The op‐ tional trailing b specifies that the substitution should be matched from the beginning of the string rather than from right after the position at which the previous matching substitution ended. Optional trailing H, R, or S characters suppress sub‐ stitutions for hardlink targets, regular filenames, or symlink targets, respectively. Optional trailing h, r, or s characters enable substitutions for hardlink targets, regular filenames, or symlink targets, respectively. The default is 4mhrs24m which ap‐ plies substitutions to all names. In particular, it is never necessary to specify h, r, or s. 1m--safe-writes0m (x mode only) Extract files atomically. By default 1mtar 22munlinks the original file with the same name as the extracted file (if it exists), and then creates it immediately under the same name and writes to it. For a short period of time, applications trying to access the file might not find it, or see incomplete results. If 1m--safe-writes 22mis enabled, 1mtar 22mfirst creates a unique temporary file, then writes the new contents to the tem‐ porary file, and finally renames the temporary file to its fi‐ nal name atomically using 4mrename24m(2). This guarantees that an application accessing the file, will either see the old con‐ tents or the new contents at all times. 1m--same-owner0m (x mode only) Extract owner and group IDs. This is the reverse of 1m--no-same-owner 22mand the default behavior if 1mtar 22mis run as root. 1m--strip-components 4m22mcount0m Remove the specified number of leading path elements. Path‐ names with fewer elements will be silently skipped. Note that the pathname is edited after checking inclusion/exclusion pat‐ terns but before security checks. 1m-T 4m22mfilename24m, 1m--files-from 4m22mfilename0m In x or t mode, 1mtar 22mwill read the list of names to be extracted from 4mfilename24m. In c mode, 1mtar 22mwill read names to be archived from 4mfilename24m. The special name “-C” on a line by itself will cause the current directory to be changed to the directory specified on the following line. Names are terminated by new‐ lines unless 1m--null 22mis specified. Note that 1m--null 22malso dis‐ ables the special handling of lines containing “-C”. Note: If you are generating lists of files using 4mfind24m(1), you probably want to use 1m-n 22mas well. 1m--totals0m (c, r, u modes only) After archiving all files, print a summary to stderr. 1m-U22m, 1m--unlink22m, 1m--unlink-first0m (x mode only) Unlink files before creating them. This can be a minor performance optimization if most files already exist, but can make things slower if most files do not already exist. This flag also causes 1mtar 22mto remove intervening directory sym‐ links instead of reporting an error. See the SECURITY section below for more details. 1m--uid 4m22mid0m Use the provided user id number and ignore the user name from the archive. On create, if 1m--uname 22mis not also specified, the user name will be set to match the user id. 1m--uname 4m22mname0m Use the provided user name. On extract, this overrides the user name in the archive; if the provided user name does not exist on the system, it will be ignored and the user id (from the archive or from the 1m--uid 22moption) will be used instead. On create, this sets the user name that will be stored in the archive; the name is not verified against the system user data‐ base. 1m--use-compress-program 4m22mprogram0m Pipe the input (in x or t mode) or the output (in c mode) through 4mprogram24m instead of using the builtin compression sup‐ port. 1m--owner 4m22mname24m[:4muid24m] Use the provided user, if 4muid24m is not provided, 4mname24m can be ei‐ ther an username or numeric id. See the 1m--uname 22moption for de‐ tails. 1m-v22m, 1m--verbose0m Produce verbose output. In create and extract modes, 1mtar 22mwill list each file name as it is read from or written to the archive. In list mode, 1mtar 22mwill produce output similar to that of 4mls24m(1). An additional 1m-v 22moption will also provide ls-like details in create and extract mode. 1m--version0m Print version of 1mtar 22mand 1mlibarchive22m, and exit. 1m-w22m, 1m--confirmation22m, 1m--interactive0m Ask for confirmation for every action. 1m-X 4m22mfilename24m, 1m--exclude-from 4m22mfilename0m Read a list of exclusion patterns from the specified file. See 1m--exclude 22mfor more information about the handling of exclu‐ sions. 1m--xattrs0m (c, r, u, x modes only) Archive or extract extended file at‐ tributes. This is the reverse of 1m--no-xattrs 22mand the default behavior in c, r, and u modes or if 1mtar 22mis run in x mode as root. 1m-y 22m(c mode only) Compress the resulting archive with 4mbzip224m(1). In extract or list modes, this option is ignored. Note that this 1mtar 22mimplementation recognizes bzip2 compression automatically when reading archives. 1m-Z22m, 1m--compress22m, 1m--uncompress0m (c mode only) Compress the resulting archive with 4mcompress24m(1). In extract or list modes, this option is ignored. Note that this 1mtar 22mimplementation recognizes compress compression auto‐ matically when reading archives. 1m-z22m, 1m--gunzip22m, 1m--gzip0m (c mode only) Compress the resulting archive with 4mgzip24m(1). In extract or list modes, this option is ignored. Note that this 1mtar 22mimplementation recognizes gzip compression automatically when reading archives. 1mENVIRONMENT0m The following environment variables affect the execution of 1mtar22m: TAR_READER_OPTIONS The default options for format readers and compression readers. The 1m--options 22moption overrides this. TAR_WRITER_OPTIONS The default options for format writers and compression writers. The 1m--options 22moption overrides this. LANG The locale to use. See 4menviron24m(7) for more information. TAPE The default device. The 1m-f 22moption overrides this. Please see the description of the 1m-f 22moption above for more details. TZ The timezone to use when displaying dates. See 4menviron24m(7) for more information. 1mEXIT STATUS0m The 1mtar 22mutility exits 0 on success, and >0 if an error occurs. 1mEXAMPLES0m The following creates a new archive called 4mfile.tar.gz24m that contains two files 4msource.c24m and 4msource.h24m: 1mtar -czf 4m22mfile.tar.gz24m 4msource.c24m 4msource.h0m To view a detailed table of contents for this archive: 1mtar -tvf 4m22mfile.tar.gz0m To extract all entries from the archive on the default tape drive: 1mtar -x0m To examine the contents of an ISO 9660 cdrom image: 1mtar -tf 4m22mimage.iso0m To move file hierarchies, invoke 1mtar 22mas 1mtar -cf 4m22m-24m 1m-C 4m22msrcdir24m 4m.24m | 1mtar -xpf 4m22m-24m 1m-C 4m22mdestdir0m or more traditionally 1mcd srcdir ; tar -cf 4m22m-24m 4m.24m | (4mcd24m 4mdestdir24m 4m;24m 1mtar -xpf 4m22m-24m) In create mode, the list of files and directories to be archived can also include directory change instructions of the form 1m-C4m22mfoo/baz24m and archive inclusions of the form 1m@4m22marchive-file24m. For example, the command line 1mtar -c -f 4m22mnew.tar24m 4mfoo124m 1m@4m22mold.tgz24m 1m-C4m22m/tmp24m 4mfoo20m will create a new archive 4mnew.tar24m. 1mtar 22mwill read the file 4mfoo124m from the current directory and add it to the output archive. It will then read each entry from 4mold.tgz24m and add those entries to the output archive. Finally, it will switch to the 4m/tmp24m directory and add 4mfoo224m to the output archive. An input file in 4mmtree24m(5) format can be used to create an output archive with arbitrary ownership, permissions, or names that differ from existing data on disk: $ cat input.mtree #mtree usr/bin uid=0 gid=0 mode=0755 type=dir usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls $ tar -cvf output.tar @input.mtree The 1m--newer 22mand 1m--newer-mtime 22mswitches accept a variety of common date and time specifications, including “12 Mar 2005 7:14:29pm”, “2005-03-12 19:14”, “5 minutes ago”, and “19:14 PST May 1”. The 1m--options 22margument can be used to control various details of archive generation or reading. For example, you can generate mtree output which only contains 1mtype22m, 1mtime22m, and 1muid 22mkeywords: 1mtar -cf 4m22mfile.tar24m 1m--format=mtree --options='!all,type,time,uid'0m 4mdir0m or you can set the compression level used by gzip or xz compression: 1mtar -czf 4m22mfile.tar24m 1m--options='compression-level=9'22m. For more details, see the explanation of the 1marchive_read_set_options22m() and 1marchive_write_set_options22m() API calls that are described in 4marchive_read24m(3) and 4marchive_write24m(3). 1mCOMPATIBILITY0m The bundled-arguments format is supported for compatibility with his‐ toric implementations. It consists of an initial word (with no leading - character) in which each character indicates an option. Arguments follow as separate words. The order of the arguments must match the order of the corresponding characters in the bundled command word. For example, 1mtar tbf 32 4m22mfile.tar0m specifies three flags 1mt22m, 1mb22m, and 1mf22m. The 1mb 22mand 1mf 22mflags both require ar‐ guments, so there must be two additional items on the command line. The 4m3224m is the argument to the 1mb 22mflag, and 4mfile.tar24m is the argument to the 1mf 22mflag. The mode options c, r, t, u, and x and the options b, f, l, m, o, v, and w comply with SUSv2. For maximum portability, scripts that invoke 1mtar 22mshould use the bun‐ dled-argument format above, should limit themselves to the 1mc22m, 1mt22m, and 1mx0m modes, and the 1mb22m, 1mf22m, 1mm22m, 1mv22m, and 1mw 22moptions. Additional long options are provided to improve compatibility with other tar implementations. 1mSECURITY0m Certain security issues are common to many archiving programs, includ‐ ing 1mtar22m. In particular, carefully-crafted archives can request that 1mtar 22mextract files to locations outside of the target directory. This can potentially be used to cause unwitting users to overwrite files they did not intend to overwrite. If the archive is being extracted by the superuser, any file on the system can potentially be overwritten. There are three ways this can happen. Although 1mtar 22mhas mechanisms to protect against each one, savvy users should be aware of the implica‐ tions: 1m• 22mArchive entries can have absolute pathnames. By default, 1mtar0m removes the leading 4m/24m character from filenames before restoring them to guard against this problem. 1m• 22mArchive entries can have pathnames that include 4m..24m components. By default, 1mtar 22mwill not extract files containing 4m..24m components in their pathname. 1m• 22mArchive entries can exploit symbolic links to restore files to other directories. An archive can restore a symbolic link to another directory, then use that link to restore a file into that directory. To guard against this, 1mtar 22mchecks each ex‐ tracted path for symlinks. If the final path element is a sym‐ link, it will be removed and replaced with the archive entry. If 1m-U 22mis specified, any intermediate symlink will also be un‐ conditionally removed. If neither 1m-U 22mnor 1m-P 22mis specified, 1mtar0m will refuse to extract the entry. To protect yourself, you should be wary of any archives that come from untrusted sources. You should examine the contents of an archive with 1mtar -tf 4m22mfilename0m before extraction. You should use the 1m-k 22moption to ensure that 1mtar0m will not overwrite any existing files or the 1m-U 22moption to remove any pre-existing files. You should generally not extract archives while running with super-user privileges. Note that the 1m-P 22moption to 1mtar0m disables the security checks above and allows you to extract an archive while preserving any absolute pathnames, 4m..24m components, or symlinks to other directories. 1mSEE ALSO0m 4mbzip224m(1), 4mcompress24m(1), 4mcpio24m(1), 4mgzip24m(1), 4mmt24m(1), 4mpax24m(1), 4mshar24m(1), 4mxz24m(1), 4mlibarchive24m(3), 4mlibarchive-formats24m(5), 4mtar24m(5) 1mSTANDARDS0m There is no current POSIX standard for the tar command; it appeared in ISO/IEC 9945-1:1996 (“POSIX.1”) but was dropped from IEEE Std 1003.1-2001 (“POSIX.1”). The options supported by this implementation were developed by surveying a number of existing tar implementations as well as the old POSIX specification for tar and the current POSIX spec‐ ification for pax. The ustar and pax interchange file formats are defined by IEEE Std 1003.1-2001 (“POSIX.1”) for the pax command. 1mHISTORY0m A 1mtar 22mcommand appeared in Seventh Edition Unix, which was released in January, 1979. There have been numerous other implementations, many of which extended the file format. John Gilmore's 1mpdtar 22mpublic-domain im‐ plementation (circa November, 1987) was quite influential, and formed the basis of GNU tar. GNU tar was included as the standard system tar in FreeBSD beginning with FreeBSD 1.0. This is a complete re-implementation based on the 4mlibarchive24m(3) li‐ brary. It was first released with FreeBSD 5.4 in May, 2005. 1mBUGS0m This program follows ISO/IEC 9945-1:1996 (“POSIX.1”) for the definition of the 1m-l 22moption. Note that GNU tar prior to version 1.15 treated 1m-l0m as a synonym for the 1m--one-file-system 22moption. The 1m-C 4m22mdir24m option may differ from historic implementations. All archive output is written in correctly-sized blocks, even if the output is being compressed. Whether or not the last output block is padded to a full block size varies depending on the format and the out‐ put device. For tar and cpio formats, the last block of output is padded to a full block size if the output is being written to standard output or to a character or block device such as a tape drive. If the output is being written to a regular file, the last block will not be padded. Many compressors, including 4mgzip24m(1) and 4mbzip224m(1), complain about the null padding when decompressing an archive created by 1mtar22m, although they still extract it correctly. The compression and decompression is implemented internally, so there may be insignificant differences between the compressed output gener‐ ated by 1mtar -czf 4m22m-24m 4mfile0m and that generated by 1mtar -cf 4m22m-24m 4mfile24m | 1mgzip0m The default should be to read and write archives to the standard I/O paths, but tradition (and POSIX) dictates otherwise. The 1mr 22mand 1mu 22mmodes require that the archive be uncompressed and located in a regular file on disk. Other archives can be modified using 1mc 22mmode with the 4m@archive-file24m extension. To archive a file called 4m@foo24m or 4m-foo24m you must specify it as 4m./@foo24m or 4m./-foo24m, respectively. In create mode, a leading 4m./24m is always removed. A leading 4m/24m is stripped unless the 1m-P 22moption is specified. There needs to be better support for file selection on both create and extract. There is not yet any support for multi-volume archives. Converting between dissimilar archive formats (such as tar and cpio) using the 1m@4m22m-24m convention can cause hard link information to be lost. (This is a consequence of the incompatible ways that different archive formats store hardlink information.) Debian April 23, 2024 4mTAR24m(1)