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