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