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