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