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