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