1.\" Copyright (c) 2003-2007 Tim Kientzle 2.\" Copyright (c) 2017 Martin Matuska 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd October 1, 2017 29.Dt TAR 1 30.Os 31.Sh NAME 32.Nm tar 33.Nd manipulate tape archives 34.Sh SYNOPSIS 35.Nm 36.Op Ar bundled-flags Ao args Ac 37.Op Ao Ar file Ac | Ao Ar pattern Ac ... 38.Nm 39.Brq Fl c 40.Op Ar options 41.Op Ar files | Ar directories 42.Nm 43.Brq Fl r | Fl u 44.Fl f Ar archive-file 45.Op Ar options 46.Op Ar files | Ar directories 47.Nm 48.Brq Fl t | Fl x 49.Op Ar options 50.Op Ar patterns 51.Sh DESCRIPTION 52.Nm 53creates and manipulates streaming archive files. 54This implementation can extract from tar, pax, cpio, zip, jar, ar, xar, 55rpm, 7-zip, and ISO 9660 cdrom images and can create tar, pax, cpio, ar, zip, 567-zip, and shar archives. 57.Pp 58The first synopsis form shows a 59.Dq bundled 60option word. 61This usage is provided for compatibility with historical implementations. 62See COMPATIBILITY below for details. 63.Pp 64The other synopsis forms show the preferred usage. 65The first option to 66.Nm 67is a mode indicator from the following list: 68.Bl -tag -compact -width indent 69.It Fl c 70Create a new archive containing the specified items. 71The long option form is 72.Fl Fl create . 73.It Fl r 74Like 75.Fl c , 76but new entries are appended to the archive. 77Note that this only works on uncompressed archives stored in regular files. 78The 79.Fl f 80option is required. 81The long option form is 82.Fl Fl append . 83.It Fl t 84List archive contents to stdout. 85The long option form is 86.Fl Fl list . 87.It Fl u 88Like 89.Fl r , 90but new entries are added only if they have a modification date 91newer than the corresponding entry in the archive. 92Note that this only works on uncompressed archives stored in regular files. 93The 94.Fl f 95option is required. 96The long form is 97.Fl Fl update . 98.It Fl x 99Extract to disk from the archive. 100If a file with the same name appears more than once in the archive, 101each copy will be extracted, with later copies overwriting (replacing) 102earlier copies. 103The long option form is 104.Fl Fl extract . 105.El 106.Pp 107In 108.Fl c , 109.Fl r , 110or 111.Fl u 112mode, each specified file or directory is added to the 113archive in the order specified on the command line. 114By default, the contents of each directory are also archived. 115.Pp 116In extract or list mode, the entire command line 117is read and parsed before the archive is opened. 118The pathnames or patterns on the command line indicate 119which items in the archive should be processed. 120Patterns are shell-style globbing patterns as 121documented in 122.Xr tcsh 1 . 123.Sh OPTIONS 124Unless specifically stated otherwise, options are applicable in 125all operating modes. 126.Bl -tag -width indent 127.It Cm @ Ns Pa archive 128(c and r modes only) 129The specified archive is opened and the entries 130in it will be appended to the current archive. 131As a simple example, 132.Dl Nm Fl c Fl f Pa - Pa newfile Cm @ Ns Pa original.tar 133writes a new archive to standard output containing a file 134.Pa newfile 135and all of the entries from 136.Pa original.tar . 137In contrast, 138.Dl Nm Fl c Fl f Pa - Pa newfile Pa original.tar 139creates a new archive with only two entries. 140Similarly, 141.Dl Nm Fl czf Pa - Fl Fl format Cm pax Cm @ Ns Pa - 142reads an archive from standard input (whose format will be determined 143automatically) and converts it into a gzip-compressed 144pax-format archive on stdout. 145In this way, 146.Nm 147can be used to convert archives from one format to another. 148.It Fl a , Fl Fl auto-compress 149(c mode only) 150Use the archive suffix to decide a set of the format and 151the compressions. 152As a simple example, 153.Dl Nm Fl a Fl cf Pa archive.tgz source.c source.h 154creates a new archive with restricted pax format and gzip compression, 155.Dl Nm Fl a Fl cf Pa archive.tar.bz2.uu source.c source.h 156creates a new archive with restricted pax format and bzip2 compression 157and uuencode compression, 158.Dl Nm Fl a Fl cf Pa archive.zip source.c source.h 159creates a new archive with zip format, 160.Dl Nm Fl a Fl jcf Pa archive.tgz source.c source.h 161ignores the 162.Dq -j 163option, and creates a new archive with restricted pax format 164and gzip compression, 165.Dl Nm Fl a Fl jcf Pa archive.xxx source.c source.h 166if it is unknown suffix or no suffix, creates a new archive with 167restricted pax format and bzip2 compression. 168.It Fl Fl acls 169(c, r, u, x modes only) 170Archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of 171.Fl Fl no-acls 172and the default behavior in c, r, and u modes (except on Mac OS X) or if 173.Nm 174is run in x mode as root. On Mac OS X this option translates extended ACLs 175to NFSv4 ACLs. To store extended ACLs the 176.Fl Fl mac-metadata 177option is preferred. 178.It Fl B , Fl Fl read-full-blocks 179Ignored for compatibility with other 180.Xr tar 1 181implementations. 182.It Fl b Ar blocksize , Fl Fl block-size Ar blocksize 183Specify the block size, in 512-byte records, for tape drive I/O. 184As a rule, this argument is only needed when reading from or writing 185to tape drives, and usually not even then as the default block size of 18620 records (10240 bytes) is very common. 187.It Fl C Ar directory , Fl Fl cd Ar directory , Fl Fl directory Ar directory 188In c and r mode, this changes the directory before adding 189the following files. 190In x mode, change directories after opening the archive 191but before extracting entries from the archive. 192.It Fl Fl chroot 193(x mode only) 194.Fn chroot 195to the current directory after processing any 196.Fl C 197options and before extracting any files. 198.It Fl Fl clear-nochange-fflags 199(x mode only) 200Before removing file system objects to replace them, clear platform-specific 201file flags that might prevent removal. 202.It Fl Fl exclude Ar pattern 203Do not process files or directories that match the 204specified pattern. 205Note that exclusions take precedence over patterns or filenames 206specified on the command line. 207.It Fl Fl exclude-vcs 208Do not process files or directories internally used by the 209version control systems 210.Sq CVS , 211.Sq RCS , 212.Sq SCCS , 213.Sq SVN , 214.Sq Arch , 215.Sq Bazaar , 216.Sq Mercurial 217and 218.Sq Darcs . 219.It Fl Fl fflags 220(c, r, u, x modes only) 221Archive or extract file flags. This is the reverse of 222.Fl Fl no-fflags 223and the default behavior in c, r, and u modes or if 224.Nm 225is run in x mode as root. 226.It Fl Fl format Ar format 227(c, r, u mode only) 228Use the specified format for the created archive. 229Supported formats include 230.Dq cpio , 231.Dq pax , 232.Dq shar , 233and 234.Dq ustar . 235Other formats may also be supported; see 236.Xr libarchive-formats 5 237for more information about currently-supported formats. 238In r and u modes, when extending an existing archive, the format specified 239here must be compatible with the format of the existing archive on disk. 240.It Fl f Ar file , Fl Fl file Ar file 241Read the archive from or write the archive to the specified file. 242The filename can be 243.Pa - 244for standard input or standard output. 245The default varies by system; 246on 247.Fx , 248the default is 249.Pa /dev/sa0 ; 250on Linux, the default is 251.Pa /dev/st0 . 252.It Fl Fl gid Ar id 253Use the provided group id number. 254On extract, this overrides the group id in the archive; 255the group name in the archive will be ignored. 256On create, this overrides the group id read from disk; 257if 258.Fl Fl gname 259is not also specified, the group name will be set to 260match the group id. 261.It Fl Fl gname Ar name 262Use the provided group name. 263On extract, this overrides the group name in the archive; 264if the provided group name does not exist on the system, 265the group id 266(from the archive or from the 267.Fl Fl gid 268option) 269will be used instead. 270On create, this sets the group name that will be stored 271in the archive; 272the name will not be verified against the system group database. 273.It Fl H 274(c and r modes only) 275Symbolic links named on the command line will be followed; the 276target of the link will be archived, not the link itself. 277.It Fl h 278(c and r modes only) 279Synonym for 280.Fl L . 281.It Fl I 282Synonym for 283.Fl T . 284.It Fl Fl help 285Show usage. 286.It Fl Fl hfsCompression 287(x mode only) 288Mac OS X specific (v10.6 or later). Compress extracted regular files with HFS+ 289compression. 290.It Fl Fl ignore-zeros 291An alias of 292.Fl Fl options Cm read_concatenated_archives 293for compatibility with GNU tar. 294.It Fl Fl include Ar pattern 295Process only files or directories that match the specified pattern. 296Note that exclusions specified with 297.Fl Fl exclude 298take precedence over inclusions. 299If no inclusions are explicitly specified, all entries are processed by 300default. 301The 302.Fl Fl include 303option is especially useful when filtering archives. 304For example, the command 305.Dl Nm Fl c Fl f Pa new.tar Fl Fl include='*foo*' Cm @ Ns Pa old.tgz 306creates a new archive 307.Pa new.tar 308containing only the entries from 309.Pa old.tgz 310containing the string 311.Sq foo . 312.It Fl J , Fl Fl xz 313(c mode only) 314Compress the resulting archive with 315.Xr xz 1 . 316In extract or list modes, this option is ignored. 317Note that this 318.Nm tar 319implementation recognizes XZ compression automatically when reading archives. 320.It Fl j , Fl Fl bzip , Fl Fl bzip2 , Fl Fl bunzip2 321(c mode only) 322Compress the resulting archive with 323.Xr bzip2 1 . 324In extract or list modes, this option is ignored. 325Note that this 326.Nm tar 327implementation recognizes bzip2 compression automatically when reading 328archives. 329.It Fl k , Fl Fl keep-old-files 330(x mode only) 331Do not overwrite existing files. 332In particular, if a file appears more than once in an archive, 333later copies will not overwrite earlier copies. 334.It Fl Fl keep-newer-files 335(x mode only) 336Do not overwrite existing files that are newer than the 337versions appearing in the archive being extracted. 338.It Fl L , Fl Fl dereference 339(c and r modes only) 340All symbolic links will be followed. 341Normally, symbolic links are archived as such. 342With this option, the target of the link will be archived instead. 343.It Fl l , Fl Fl check-links 344(c and r modes only) 345Issue a warning message unless all links to each file are archived. 346.It Fl Fl lrzip 347(c mode only) 348Compress the resulting archive with 349.Xr lrzip 1 . 350In extract or list modes, this option is ignored. 351Note that this 352.Nm tar 353implementation recognizes lrzip compression automatically when reading 354archives. 355.It Fl Fl lz4 356(c mode only) 357Compress the archive with lz4-compatible compression before writing it. 358In extract or list modes, this option is ignored. 359Note that this 360.Nm tar 361implementation recognizes lz4 compression automatically when reading archives. 362.It Fl Fl zstd 363(c mode only) 364Compress the archive with zstd-compatible compression before writing it. 365In extract or list modes, this option is ignored. 366Note that this 367.Nm tar 368implementation recognizes zstd compression automatically when reading archives. 369.It Fl Fl lzma 370(c mode only) Compress the resulting archive with the original LZMA algorithm. 371In extract or list modes, this option is ignored. 372Use of this option is discouraged and new archives should be created with 373.Fl Fl xz 374instead. 375Note that this 376.Nm tar 377implementation recognizes LZMA compression automatically when reading archives. 378.It Fl Fl lzop 379(c mode only) 380Compress the resulting archive with 381.Xr lzop 1 . 382In extract or list modes, this option is ignored. 383Note that this 384.Nm tar 385implementation recognizes LZO compression automatically when reading archives. 386.It Fl m , Fl Fl modification-time 387(x mode only) 388Do not extract modification time. 389By default, the modification time is set to the time stored in the archive. 390.It Fl Fl mac-metadata 391(c, r, u and x mode only) 392Mac OS X specific. Archive or extract extended ACLs and extended attributes 393using 394.Xr copyfile 3 395in AppleDouble format. This is the reverse of 396.Fl Fl no-mac-metadata . 397and the default behavior in c, r, and u modes or if 398.Nm 399is run in x mode as root. 400.It Fl n , Fl Fl norecurse , Fl Fl no-recursion 401Do not operate recursively on the content of directories. 402.It Fl Fl newer Ar date 403(c, r, u modes only) 404Only include files and directories newer than the specified date. 405This compares ctime entries. 406.It Fl Fl newer-mtime Ar date 407(c, r, u modes only) 408Like 409.Fl Fl newer , 410except it compares mtime entries instead of ctime entries. 411.It Fl Fl newer-than Pa file 412(c, r, u modes only) 413Only include files and directories newer than the specified file. 414This compares ctime entries. 415.It Fl Fl newer-mtime-than Pa file 416(c, r, u modes only) 417Like 418.Fl Fl newer-than , 419except it compares mtime entries instead of ctime entries. 420.It Fl Fl nodump 421(c and r modes only) 422Honor the nodump file flag by skipping this file. 423.It Fl Fl nopreserveHFSCompression 424(x mode only) 425Mac OS X specific (v10.6 or later). Do not compress extracted regular files 426which were compressed with HFS+ compression before archived. 427By default, compress the regular files again with HFS+ compression. 428.It Fl Fl null 429(use with 430.Fl I 431or 432.Fl T ) 433Filenames or patterns are separated by null characters, 434not by newlines. 435This is often used to read filenames output by the 436.Fl print0 437option to 438.Xr find 1 . 439.It Fl Fl no-acls 440(c, r, u, x modes only) 441Do not archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of 442.Fl Fl acls 443and the default behavior if 444.Nm 445is run as non-root in x mode (on Mac OS X as any user in c, r, u and x modes). 446.It Fl Fl no-fflags 447(c, r, u, x modes only) 448Do not archive or extract file flags. This is the reverse of 449.Fl Fl fflags 450and the default behavior if 451.Nm 452is run as non-root in x mode. 453.It Fl Fl no-mac-metadata 454(x mode only) 455Mac OS X specific. Do not archive or extract ACLs and extended attributes using 456.Xr copyfile 3 457in AppleDouble format. This is the reverse of 458.Fl Fl mac-metadata . 459and the default behavior if 460.Nm 461is run as non-root in x mode. 462.It Fl n , Fl Fl norecurse , Fl Fl no-recursion 463.It Fl Fl no-same-owner 464(x mode only) 465Do not extract owner and group IDs. 466This is the reverse of 467.Fl Fl same-owner 468and the default behavior if 469.Nm 470is run as non-root. 471.It Fl Fl no-same-permissions 472(x mode only) 473Do not extract full permissions (SGID, SUID, sticky bit, ACLs, 474extended attributes or extended file flags). 475This is the reverse of 476.Fl p 477and the default behavior if 478.Nm 479is run as non-root. 480.It Fl Fl no-xattrs 481(c, r, u, x modes only) 482Do not archive or extract extended attributes. This is the reverse of 483.Fl Fl xattrs 484and the default behavior if 485.Nm 486is run as non-root in x mode. 487.It Fl Fl numeric-owner 488This is equivalent to 489.Fl Fl uname 490.Qq 491.Fl Fl gname 492.Qq . 493On extract, it causes user and group names in the archive 494to be ignored in favor of the numeric user and group ids. 495On create, it causes user and group names to not be stored 496in the archive. 497.It Fl O , Fl Fl to-stdout 498(x, t modes only) 499In extract (-x) mode, files will be written to standard out rather than 500being extracted to disk. 501In list (-t) mode, the file listing will be written to stderr rather than 502the usual stdout. 503.It Fl o 504(x mode) 505Use the user and group of the user running the program rather 506than those specified in the archive. 507Note that this has no significance unless 508.Fl p 509is specified, and the program is being run by the root user. 510In this case, the file modes and flags from 511the archive will be restored, but ACLs or owner information in 512the archive will be discarded. 513.It Fl o 514(c, r, u mode) 515A synonym for 516.Fl Fl format Ar ustar 517.It Fl Fl older Ar date 518(c, r, u modes only) 519Only include files and directories older than the specified date. 520This compares ctime entries. 521.It Fl Fl older-mtime Ar date 522(c, r, u modes only) 523Like 524.Fl Fl older , 525except it compares mtime entries instead of ctime entries. 526.It Fl Fl older-than Pa file 527(c, r, u modes only) 528Only include files and directories older than the specified file. 529This compares ctime entries. 530.It Fl Fl older-mtime-than Pa file 531(c, r, u modes only) 532Like 533.Fl Fl older-than , 534except it compares mtime entries instead of ctime entries. 535.It Fl Fl one-file-system 536(c, r, and u modes) 537Do not cross mount points. 538.It Fl Fl options Ar options 539Select optional behaviors for particular modules. 540The argument is a text string containing comma-separated 541keywords and values. 542These are passed to the modules that handle particular 543formats to control how those formats will behave. 544Each option has one of the following forms: 545.Bl -tag -compact -width indent 546.It Ar key=value 547The key will be set to the specified value in every module that supports it. 548Modules that do not support this key will ignore it. 549.It Ar key 550The key will be enabled in every module that supports it. 551This is equivalent to 552.Ar key Ns Cm =1 . 553.It Ar !key 554The key will be disabled in every module that supports it. 555.It Ar module:key=value , Ar module:key , Ar module:!key 556As above, but the corresponding key and value will be provided 557only to modules whose name matches 558.Ar module . 559.El 560The currently supported modules and keys are: 561.Bl -tag -compact -width indent 562.It Cm iso9660:joliet 563Support Joliet extensions. 564This is enabled by default, use 565.Cm !joliet 566or 567.Cm iso9660:!joliet 568to disable. 569.It Cm iso9660:rockridge 570Support Rock Ridge extensions. 571This is enabled by default, use 572.Cm !rockridge 573or 574.Cm iso9660:!rockridge 575to disable. 576.It Cm gzip:compression-level 577A decimal integer from 1 to 9 specifying the gzip compression level. 578.It Cm gzip:timestamp 579Store timestamp. This is enabled by default, use 580.Cm !timestamp 581or 582.Cm gzip:!timestamp 583to disable. 584.It Cm lrzip:compression Ns = Ns Ar type 585Use 586.Ar type 587as compression method. 588Supported values are bzip2, gzip, lzo (ultra fast), 589and zpaq (best, extremely slow). 590.It Cm lrzip:compression-level 591A decimal integer from 1 to 9 specifying the lrzip compression level. 592.It Cm lz4:compression-level 593A decimal integer from 1 to 9 specifying the lzop compression level. 594.It Cm lz4:stream-checksum 595Enable stream checksum. This is by default, use 596.Cm lz4:!stream-checksum 597to disable. 598.It Cm lz4:block-checksum 599Enable block checksum (Disabled by default). 600.It Cm lz4:block-size 601A decimal integer from 4 to 7 specifying the lz4 compression block size 602(7 is set by default). 603.It Cm lz4:block-dependence 604Use the previous block of the block being compressed for 605a compression dictionary to improve compression ratio. 606.It Cm zstd:compression-level 607A decimal integer from 1 to 22 specifying the zstd compression level. 608.It Cm lzop:compression-level 609A decimal integer from 1 to 9 specifying the lzop compression level. 610.It Cm xz:compression-level 611A decimal integer from 0 to 9 specifying the xz compression level. 612.It Cm mtree: Ns Ar keyword 613The mtree writer module allows you to specify which mtree keywords 614will be included in the output. 615Supported keywords include: 616.Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent , 617.Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 , 618.Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname . 619The default is equivalent to: 620.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname . 621.It Cm mtree:all 622Enables all of the above keywords. 623You can also use 624.Cm mtree:!all 625to disable all keywords. 626.It Cm mtree:use-set 627Enable generation of 628.Cm /set 629lines in the output. 630.It Cm mtree:indent 631Produce human-readable output by indenting options and splitting lines 632to fit into 80 columns. 633.It Cm zip:compression Ns = Ns Ar type 634Use 635.Ar type 636as compression method. 637Supported values are store (uncompressed) and deflate (gzip algorithm). 638.It Cm zip:encryption 639Enable encryption using traditional zip encryption. 640.It Cm zip:encryption Ns = Ns Ar type 641Use 642.Ar type 643as encryption type. 644Supported values are zipcrypt (traditional zip encryption), 645aes128 (WinZip AES-128 encryption) and aes256 (WinZip AES-256 encryption). 646.It Cm read_concatenated_archives 647Ignore zeroed blocks in the archive, which occurs when multiple tar archives 648have been concatenated together. Without this option, only the contents of 649the first concatenated archive would be read. This option is comparable to 650the 651.Fl i , Fl Fl ignore-zeros 652option of GNU tar. 653.El 654If a provided option is not supported by any module, that 655is a fatal error. 656.It Fl P , Fl Fl absolute-paths 657Preserve pathnames. 658By default, absolute pathnames (those that begin with a / 659character) have the leading slash removed both when creating archives 660and extracting from them. 661Also, 662.Nm 663will refuse to extract archive entries whose pathnames contain 664.Pa .. 665or whose target directory would be altered by a symlink. 666This option suppresses these behaviors. 667.It Fl p , Fl Fl insecure , Fl Fl preserve-permissions 668(x mode only) 669Preserve file permissions. 670Attempt to restore the full permissions, including owner, file modes, ACLs, 671extended attributes and extended file flags, if available, for each item 672extracted from the archive. This is te reverse of 673.Fl Fl no-same-permissions 674and the default if 675.Nm 676is being run by root and can be partially overridden by also specifying 677.Fl Fl no-acls , 678.Fl Fl no-fflags , 679.Fl Fl no-mac-metadata 680or 681.Fl Fl no-xattrs . 682.It Fl Fl passphrase Ar passphrase 683The 684.Pa passphrase 685is used to extract or create an encrypted archive. 686Currently, zip is the only supported format that supports encryption. 687You shouldn't use this option unless you realize how insecure 688use of this option is. 689.It Fl Fl posix 690(c, r, u mode only) 691Synonym for 692.Fl Fl format Ar pax 693.It Fl q , Fl Fl fast-read 694(x and t mode only) 695Extract or list only the first archive entry that matches each pattern 696or filename operand. 697Exit as soon as each specified pattern or filename has been matched. 698By default, the archive is always read to the very end, since 699there can be multiple entries with the same name and, by convention, 700later entries overwrite earlier entries. 701This option is provided as a performance optimization. 702.It Fl S 703(x mode only) 704Extract files as sparse files. 705For every block on disk, check first if it contains only NULL bytes and seek 706over it otherwise. 707This works similar to the conv=sparse option of dd. 708.It Fl s Ar pattern 709Modify file or archive member names according to 710.Pa pattern . 711The pattern has the format 712.Ar /old/new/ Ns Op ghHprRsS 713where 714.Ar old 715is a basic regular expression, 716.Ar new 717is the replacement string of the matched part, 718and the optional trailing letters modify 719how the replacement is handled. 720If 721.Ar old 722is not matched, the pattern is skipped. 723Within 724.Ar new , 725~ is substituted with the match, \e1 to \e9 with the content of 726the corresponding captured group. 727The optional trailing g specifies that matching should continue 728after the matched part and stop on the first unmatched pattern. 729The optional trailing s specifies that the pattern applies to the value 730of symbolic links. 731The optional trailing p specifies that after a successful substitution 732the original path name and the new path name should be printed to 733standard error. 734Optional trailing H, R, or S characters suppress substitutions 735for hardlink targets, regular filenames, or symlink targets, 736respectively. 737Optional trailing h, r, or s characters enable substitutions 738for hardlink targets, regular filenames, or symlink targets, 739respectively. 740The default is 741.Ar hrs 742which applies substitutions to all names. 743In particular, it is never necessary to specify h, r, or s. 744.It Fl Fl same-owner 745(x mode only) 746Extract owner and group IDs. 747This is the reverse of 748.Fl Fl no-same-owner 749and the default behavior if 750.Nm 751is run as root. 752.It Fl Fl strip-components Ar count 753Remove the specified number of leading path elements. 754Pathnames with fewer elements will be silently skipped. 755Note that the pathname is edited after checking inclusion/exclusion patterns 756but before security checks. 757.It Fl T Ar filename , Fl Fl files-from Ar filename 758In x or t mode, 759.Nm 760will read the list of names to be extracted from 761.Pa filename . 762In c mode, 763.Nm 764will read names to be archived from 765.Pa filename . 766The special name 767.Dq -C 768on a line by itself will cause the current directory to be changed to 769the directory specified on the following line. 770Names are terminated by newlines unless 771.Fl Fl null 772is specified. 773Note that 774.Fl Fl null 775also disables the special handling of lines containing 776.Dq -C . 777Note: If you are generating lists of files using 778.Xr find 1 , 779you probably want to use 780.Fl n 781as well. 782.It Fl Fl totals 783(c, r, u modes only) 784After archiving all files, print a summary to stderr. 785.It Fl U , Fl Fl unlink , Fl Fl unlink-first 786(x mode only) 787Unlink files before creating them. 788This can be a minor performance optimization if most files 789already exist, but can make things slower if most files 790do not already exist. 791This flag also causes 792.Nm 793to remove intervening directory symlinks instead of 794reporting an error. 795See the SECURITY section below for more details. 796.It Fl Fl uid Ar id 797Use the provided user id number and ignore the user 798name from the archive. 799On create, if 800.Fl Fl uname 801is not also specified, the user name will be set to 802match the user id. 803.It Fl Fl uname Ar name 804Use the provided user name. 805On extract, this overrides the user name in the archive; 806if the provided user name does not exist on the system, 807it will be ignored and the user id 808(from the archive or from the 809.Fl Fl uid 810option) 811will be used instead. 812On create, this sets the user name that will be stored 813in the archive; 814the name is not verified against the system user database. 815.It Fl Fl use-compress-program Ar program 816Pipe the input (in x or t mode) or the output (in c mode) through 817.Pa program 818instead of using the builtin compression support. 819.It Fl v , Fl Fl verbose 820Produce verbose output. 821In create and extract modes, 822.Nm 823will list each file name as it is read from or written to 824the archive. 825In list mode, 826.Nm 827will produce output similar to that of 828.Xr ls 1 . 829An additional 830.Fl v 831option will also provide ls-like details in create and extract mode. 832.It Fl Fl version 833Print version of 834.Nm 835and 836.Nm libarchive , 837and exit. 838.It Fl w , Fl Fl confirmation , Fl Fl interactive 839Ask for confirmation for every action. 840.It Fl X Ar filename , Fl Fl exclude-from Ar filename 841Read a list of exclusion patterns from the specified file. 842See 843.Fl Fl exclude 844for more information about the handling of exclusions. 845.It Fl Fl xattrs 846(c, r, u, x modes only) 847Archive or extract extended attributes. This is the reverse of 848.Fl Fl no-xattrs 849and the default behavior in c, r, and u modes or if 850.Nm 851is run in x mode as root. 852.It Fl y 853(c mode only) 854Compress the resulting archive with 855.Xr bzip2 1 . 856In extract or list modes, this option is ignored. 857Note that this 858.Nm tar 859implementation recognizes bzip2 compression automatically when reading 860archives. 861.It Fl Z , Fl Fl compress , Fl Fl uncompress 862(c mode only) 863Compress the resulting archive with 864.Xr compress 1 . 865In extract or list modes, this option is ignored. 866Note that this 867.Nm tar 868implementation recognizes compress compression automatically when reading 869archives. 870.It Fl z , Fl Fl gunzip , Fl Fl gzip 871(c mode only) 872Compress the resulting archive with 873.Xr gzip 1 . 874In extract or list modes, this option is ignored. 875Note that this 876.Nm tar 877implementation recognizes gzip compression automatically when reading 878archives. 879.El 880.Sh ENVIRONMENT 881The following environment variables affect the execution of 882.Nm : 883.Bl -tag -width ".Ev BLOCKSIZE" 884.It Ev TAR_READER_OPTIONS 885The default options for format readers and compression readers. 886The 887.Fl Fl options 888option overrides this. 889.It Ev TAR_WRITER_OPTIONS 890The default options for format writers and compression writers. 891The 892.Fl Fl options 893option overrides this. 894.It Ev LANG 895The locale to use. 896See 897.Xr environ 7 898for more information. 899.It Ev TAPE 900The default device. 901The 902.Fl f 903option overrides this. 904Please see the description of the 905.Fl f 906option above for more details. 907.It Ev TZ 908The timezone to use when displaying dates. 909See 910.Xr environ 7 911for more information. 912.El 913.Sh EXIT STATUS 914.Ex -std 915.Sh EXAMPLES 916The following creates a new archive 917called 918.Ar file.tar.gz 919that contains two files 920.Ar source.c 921and 922.Ar source.h : 923.Dl Nm Fl czf Pa file.tar.gz Pa source.c Pa source.h 924.Pp 925To view a detailed table of contents for this 926archive: 927.Dl Nm Fl tvf Pa file.tar.gz 928.Pp 929To extract all entries from the archive on 930the default tape drive: 931.Dl Nm Fl x 932.Pp 933To examine the contents of an ISO 9660 cdrom image: 934.Dl Nm Fl tf Pa image.iso 935.Pp 936To move file hierarchies, invoke 937.Nm 938as 939.Dl Nm Fl cf Pa - Fl C Pa srcdir\ . | Nm Fl xpf Pa - Fl C Pa destdir 940or more traditionally 941.Dl cd srcdir \&; Nm Fl cf Pa -\ . | ( cd destdir \&; Nm Fl xpf Pa - ) 942.Pp 943In create mode, the list of files and directories to be archived 944can also include directory change instructions of the form 945.Cm -C Ns Pa foo/baz 946and archive inclusions of the form 947.Cm @ Ns Pa archive-file . 948For example, the command line 949.Dl Nm Fl c Fl f Pa new.tar Pa foo1 Cm @ Ns Pa old.tgz Cm -C Ns Pa /tmp Pa foo2 950will create a new archive 951.Pa new.tar . 952.Nm 953will read the file 954.Pa foo1 955from the current directory and add it to the output archive. 956It will then read each entry from 957.Pa old.tgz 958and add those entries to the output archive. 959Finally, it will switch to the 960.Pa /tmp 961directory and add 962.Pa foo2 963to the output archive. 964.Pp 965An input file in 966.Xr mtree 5 967format can be used to create an output archive with arbitrary ownership, 968permissions, or names that differ from existing data on disk: 969.Pp 970.Bd -literal -offset indent 971$ cat input.mtree 972#mtree 973usr/bin uid=0 gid=0 mode=0755 type=dir 974usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls 975$ tar -cvf output.tar @input.mtree 976.Ed 977.Pp 978The 979.Fl Fl newer 980and 981.Fl Fl newer-mtime 982switches accept a variety of common date and time specifications, including 983.Dq 12 Mar 2005 7:14:29pm , 984.Dq 2005-03-12 19:14 , 985.Dq 5 minutes ago , 986and 987.Dq 19:14 PST May 1 . 988.Pp 989The 990.Fl Fl options 991argument can be used to control various details of archive generation 992or reading. 993For example, you can generate mtree output which only contains 994.Cm type , Cm time , 995and 996.Cm uid 997keywords: 998.Dl Nm Fl cf Pa file.tar Fl Fl format=mtree Fl Fl options='!all,type,time,uid' Pa dir 999or you can set the compression level used by gzip or xz compression: 1000.Dl Nm Fl czf Pa file.tar Fl Fl options='compression-level=9' . 1001For more details, see the explanation of the 1002.Fn archive_read_set_options 1003and 1004.Fn archive_write_set_options 1005API calls that are described in 1006.Xr archive_read 3 1007and 1008.Xr archive_write 3 . 1009.Sh COMPATIBILITY 1010The bundled-arguments format is supported for compatibility 1011with historic implementations. 1012It consists of an initial word (with no leading - character) in which 1013each character indicates an option. 1014Arguments follow as separate words. 1015The order of the arguments must match the order 1016of the corresponding characters in the bundled command word. 1017For example, 1018.Dl Nm Cm tbf 32 Pa file.tar 1019specifies three flags 1020.Cm t , 1021.Cm b , 1022and 1023.Cm f . 1024The 1025.Cm b 1026and 1027.Cm f 1028flags both require arguments, 1029so there must be two additional items 1030on the command line. 1031The 1032.Ar 32 1033is the argument to the 1034.Cm b 1035flag, and 1036.Ar file.tar 1037is the argument to the 1038.Cm f 1039flag. 1040.Pp 1041The mode options c, r, t, u, and x and the options 1042b, f, l, m, o, v, and w comply with SUSv2. 1043.Pp 1044For maximum portability, scripts that invoke 1045.Nm tar 1046should use the bundled-argument format above, should limit 1047themselves to the 1048.Cm c , 1049.Cm t , 1050and 1051.Cm x 1052modes, and the 1053.Cm b , 1054.Cm f , 1055.Cm m , 1056.Cm v , 1057and 1058.Cm w 1059options. 1060.Pp 1061Additional long options are provided to improve compatibility with other 1062tar implementations. 1063.Sh SECURITY 1064Certain security issues are common to many archiving programs, including 1065.Nm . 1066In particular, carefully-crafted archives can request that 1067.Nm 1068extract files to locations outside of the target directory. 1069This can potentially be used to cause unwitting users to overwrite 1070files they did not intend to overwrite. 1071If the archive is being extracted by the superuser, any file 1072on the system can potentially be overwritten. 1073There are three ways this can happen. 1074Although 1075.Nm 1076has mechanisms to protect against each one, 1077savvy users should be aware of the implications: 1078.Bl -bullet -width indent 1079.It 1080Archive entries can have absolute pathnames. 1081By default, 1082.Nm 1083removes the leading 1084.Pa / 1085character from filenames before restoring them to guard against this problem. 1086.It 1087Archive entries can have pathnames that include 1088.Pa .. 1089components. 1090By default, 1091.Nm 1092will not extract files containing 1093.Pa .. 1094components in their pathname. 1095.It 1096Archive entries can exploit symbolic links to restore 1097files to other directories. 1098An archive can restore a symbolic link to another directory, 1099then use that link to restore a file into that directory. 1100To guard against this, 1101.Nm 1102checks each extracted path for symlinks. 1103If the final path element is a symlink, it will be removed 1104and replaced with the archive entry. 1105If 1106.Fl U 1107is specified, any intermediate symlink will also be unconditionally removed. 1108If neither 1109.Fl U 1110nor 1111.Fl P 1112is specified, 1113.Nm 1114will refuse to extract the entry. 1115.El 1116To protect yourself, you should be wary of any archives that 1117come from untrusted sources. 1118You should examine the contents of an archive with 1119.Dl Nm Fl tf Pa filename 1120before extraction. 1121You should use the 1122.Fl k 1123option to ensure that 1124.Nm 1125will not overwrite any existing files or the 1126.Fl U 1127option to remove any pre-existing files. 1128You should generally not extract archives while running with super-user 1129privileges. 1130Note that the 1131.Fl P 1132option to 1133.Nm 1134disables the security checks above and allows you to extract 1135an archive while preserving any absolute pathnames, 1136.Pa .. 1137components, or symlinks to other directories. 1138.Sh SEE ALSO 1139.Xr bzip2 1 , 1140.Xr compress 1 , 1141.Xr cpio 1 , 1142.Xr gzip 1 , 1143.Xr mt 1 , 1144.Xr pax 1 , 1145.Xr shar 1 , 1146.Xr xz 1 , 1147.Xr libarchive 3 , 1148.Xr libarchive-formats 5 , 1149.Xr tar 5 1150.Sh STANDARDS 1151There is no current POSIX standard for the tar command; it appeared 1152in 1153.St -p1003.1-96 1154but was dropped from 1155.St -p1003.1-2001 . 1156The options supported by this implementation were developed by surveying a 1157number of existing tar implementations as well as the old POSIX specification 1158for tar and the current POSIX specification for pax. 1159.Pp 1160The ustar and pax interchange file formats are defined by 1161.St -p1003.1-2001 1162for the pax command. 1163.Sh HISTORY 1164A 1165.Nm tar 1166command appeared in Seventh Edition Unix, which was released in January, 1979. 1167There have been numerous other implementations, 1168many of which extended the file format. 1169John Gilmore's 1170.Nm pdtar 1171public-domain implementation (circa November, 1987) 1172was quite influential, and formed the basis of GNU tar. 1173GNU tar was included as the standard system tar 1174in 1175.Fx 1176beginning with 1177.Fx 1.0 . 1178.Pp 1179This is a complete re-implementation based on the 1180.Xr libarchive 3 1181library. 1182It was first released with 1183.Fx 5.4 1184in May, 2005. 1185.Sh BUGS 1186This program follows 1187.St -p1003.1-96 1188for the definition of the 1189.Fl l 1190option. 1191Note that GNU tar prior to version 1.15 treated 1192.Fl l 1193as a synonym for the 1194.Fl Fl one-file-system 1195option. 1196.Pp 1197The 1198.Fl C Pa dir 1199option may differ from historic implementations. 1200.Pp 1201All archive output is written in correctly-sized blocks, even 1202if the output is being compressed. 1203Whether or not the last output block is padded to a full 1204block size varies depending on the format and the 1205output device. 1206For tar and cpio formats, the last block of output is padded 1207to a full block size if the output is being 1208written to standard output or to a character or block device such as 1209a tape drive. 1210If the output is being written to a regular file, the last block 1211will not be padded. 1212Many compressors, including 1213.Xr gzip 1 1214and 1215.Xr bzip2 1 , 1216complain about the null padding when decompressing an archive created by 1217.Nm , 1218although they still extract it correctly. 1219.Pp 1220The compression and decompression is implemented internally, so 1221there may be insignificant differences between the compressed output 1222generated by 1223.Dl Nm Fl czf Pa - file 1224and that generated by 1225.Dl Nm Fl cf Pa - file | Nm gzip 1226.Pp 1227The default should be to read and write archives to the standard I/O paths, 1228but tradition (and POSIX) dictates otherwise. 1229.Pp 1230The 1231.Cm r 1232and 1233.Cm u 1234modes require that the archive be uncompressed 1235and located in a regular file on disk. 1236Other archives can be modified using 1237.Cm c 1238mode with the 1239.Pa @archive-file 1240extension. 1241.Pp 1242To archive a file called 1243.Pa @foo 1244or 1245.Pa -foo 1246you must specify it as 1247.Pa ./@foo 1248or 1249.Pa ./-foo , 1250respectively. 1251.Pp 1252In create mode, a leading 1253.Pa ./ 1254is always removed. 1255A leading 1256.Pa / 1257is stripped unless the 1258.Fl P 1259option is specified. 1260.Pp 1261There needs to be better support for file selection on both create 1262and extract. 1263.Pp 1264There is not yet any support for multi-volume archives. 1265.Pp 1266Converting between dissimilar archive formats (such as tar and cpio) using the 1267.Cm @ Ns Pa - 1268convention can cause hard link information to be lost. 1269(This is a consequence of the incompatible ways that different archive 1270formats store hardlink information.) 1271