1.\" $NetBSD: tar.1,v 1.39 2019/03/19 10:14:46 wiz Exp $ 2.\" 3.\" Copyright (c) 1996 SigmaSoft, Th. Lockert 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25.\" 26.\" OpenBSD: tar.1,v 1.28 2000/11/09 23:58:56 aaron Exp 27.\" 28.Dd March 19, 2019 29.Dt TAR 1 30.Os 31.Sh NAME 32.Nm tar 33.Nd tape archiver 34.Sh SYNOPSIS 35.Nm tar 36.Sm off 37.Oo \&- Oc {crtux} Op Fl 014578befHhJjklmOoPpqSvwXZz 38.Sm on 39.Op Ar archive 40.Op Ar blocksize 41.\" XXX how to do this right? 42.Op Fl C Ar directory 43.Op Fl s Ar replstr 44.Op Fl T Ar file 45.Op Ar file ... 46.Sh DESCRIPTION 47The 48.Nm 49command creates, adds files to, or extracts files from an 50archive file in 51.Dq tar 52format. 53A tar archive is often stored on a magnetic tape, but can be 54stored equally well on a floppy, CD-ROM, or in a regular disk file. 55.Pp 56One of the following flags must be present: 57.Bl -tag -width Ar 58.It Fl c , Fl Fl create 59Create new archive, or overwrite an existing archive, 60adding the specified files to it. 61.It Fl r , Fl Fl append 62Append the named new files to existing archive. 63Note that this will only work on media on which an end-of-file mark 64can be overwritten. 65.It Fl t , Fl Fl list 66List contents of archive. 67If any files are named on the 68command line, only those files will be listed. 69.It Fl u , Fl Fl update 70Alias for 71.Fl r . 72.It Fl x , Fl Fl extract , Fl Fl get 73Extract files from archive. 74If any files are named on the 75command line, only those files will be extracted from the 76archive. 77If more than one copy of a file exists in the 78archive, later copies will overwrite earlier copies during 79extraction. 80The file mode and modification time are preserved 81if possible. 82The file mode is subject to modification by the 83.Xr umask 2 . 84.El 85.Pp 86In addition to the flags mentioned above, any of the following 87flags may be used: 88.Bl -tag -width Ar 89.It Fl b Ar "blocking factor" , Fl Fl block-size Ar "blocking factor" 90Set blocking factor to use for the archive. 91.Nm 92uses 512 byte blocks. 93The default is 20, the maximum is 126. 94Archives with a blocking factor larger 63 violate the 95.Tn POSIX 96standard and will not be portable to all systems. 97.It Fl e 98Stop after first error. 99.It Fl f Ar archive , Fl Fl file Ar archive 100Filename where the archive is stored. 101Defaults to 102.Pa /dev/rst0 . 103If the archive is of the form: 104.Ar [[user@]host:]file 105then the archive will be processed using 106.Xr rmt 8 . 107.It Fl h , Fl Fl dereference 108Follow symbolic links as if they were normal files 109or directories. 110.It Fl J , Fl Fl xz 111Compress/decompress archive using 112.Xr xz 1 . 113.It Fl j , Fl Fl bzip2 , Fl Fl bunzip2 114Use 115.Xr bzip2 1 116for compression of the archive. 117This option is a GNU extension. 118.It Fl k , Fl Fl keep-old-files 119Keep existing files; don't overwrite them from archive. 120.It Fl l , Fl Fl one-file-system 121Do not descend across mount points. 122.\" should be '-X' 123.It Fl m , Fl Fl modification-time 124Do not preserve modification time. 125.It Fl O 126When creating and appending to an archive, write old-style (non-POSIX) archives. 127When extracting from an archive, extract to standard output. 128.It Fl o , Fl Fl portability , Fl Fl old-archive 129Don't write directory information that the older (V7) style 130.Nm 131is unable to decode. 132This implies the 133.Fl O 134flag. 135.It Fl p , Fl Fl preserve-permissions , Fl Fl preserve 136Preserve user and group ID as well as file mode regardless of 137the current 138.Xr umask 2 . 139The setuid and setgid bits are only preserved if the user is 140the superuser. 141Only meaningful in conjunction with the 142.Fl x 143flag. 144.It Fl q , Fl Fl fast-read 145Select the first archive member that matches each 146.Ar pattern 147operand. 148No more than one archive member is matched for each 149.Ar pattern . 150When members of type directory are matched, the file hierarchy rooted at that 151directory is also matched. 152.It Fl S , Fl Fl sparse 153This flag has no effect as 154.Nm 155always generates sparse files. 156.It Fl s Ar replstr 157Modify the file or archive member names specified by the 158.Ar pattern 159or 160.Ar file 161operands according to the substitution expression 162.Ar replstr , 163using the syntax of the 164.Xr ed 1 165utility regular expressions. 166The format of these regular expressions are: 167.Dl /old/new/[gps] 168As in 169.Xr ed 1 , 170.Cm old 171is a basic regular expression and 172.Cm new 173can contain an ampersand (&), \en (where n is a digit) back-references, 174or subexpression matching. 175The 176.Cm old 177string may also contain 178.Aq Dv newline 179characters. 180Any non-null character except a backslash (\\) can be used as a delimiter 181(/ is shown here). 182Multiple 183.Fl s 184expressions can be specified. 185The expressions are applied in the order they are specified on the 186command line, terminating with the first successful substitution. 187The optional trailing 188.Cm g 189continues to apply the substitution expression to the pathname substring 190which starts with the first character following the end of the last successful 191substitution. 192The first unsuccessful substitution stops the operation of the 193.Cm g 194option. 195The optional trailing 196.Cm p 197will cause the final result of a successful substitution to be written to 198.Dv standard error 199in the following format: 200.Dl Ao "original pathname" Ac >> Ao "new pathname" Ac 201File or archive member names that substitute to the empty string 202are not selected and will be skipped. 203The substitutions are applied by default to the destination hard and symbolic 204links. 205The optional trailing 206.Cm s 207prevents the substitutions from being performed on symbolic link destinations. 208.It Fl v 209Verbose operation mode. 210.It Fl w , Fl Fl interactive , Fl Fl confirmation 211Interactively rename files. 212This option causes 213.Nm 214to prompt the user for the filename to use when storing or 215extracting files in an archive. 216.It Fl z , Fl Fl gzip , Fl Fl gunzip 217Compress/decompress archive using 218.Xr gzip 1 . 219.It Fl B , Fl Fl read-full-blocks 220Reassemble small reads into full blocks (For reading from 4.2BSD pipes). 221.It Fl C Ar directory , Fl Fl directory Ar directory 222This is a positional argument which sets the working directory for the 223following files. 224When extracting, files will be extracted into 225the specified directory; when creating, the specified files will be matched 226from the directory. 227This argument and its parameter may also appear in a file list specified by 228.Fl T . 229.It Fl H 230Only follow symlinks given on command line. 231.Pp 232Note SysVr3/i386 picked up ISC/SCO UNIX compatibility which implemented 233.Dq Fl F Ar file 234which was defined as obtaining a list of command line switches and files 235on which to operate from the specified file, 236but SunOS-5 uses 237.Dq Fl I Ar file 238because they use 239.Sq Fl F 240to mean something else. 241We might someday provide SunOS-5 compatibility 242but it makes little sense to confuse things with ISC/SCO compatibility. 243.\".It Fl L 244.\"Do not follow any symlinks (do the opposite of 245.\".Fl h ). 246.It Fl P , Fl Fl absolute-paths 247Do not strip leading slashes 248.Pq Sq / 249from pathnames. 250The default is to strip leading slashes. 251.It Fl T Ar file , Fl Fl files-from Ar file 252Read the names of files to archive or extract from the given file, one 253per line. 254A line may also specify the positional argument 255.Dq Fl C Ar directory . 256.It Fl X Ar file , Fl Fl exclude-from Ar file 257Exclude files matching the shell glob patterns listed in the given file. 258.\" exclude should be '-E' and '-X' should be one-file-system 259.Pp 260Note that it would be more standard to use this option to mean ``do not 261cross filesystem mount points.'' 262.It Fl Z , Fl Fl compress , Fl Fl uncompress 263Compress archive using compress. 264.It Fl Fl strict 265Do not enable GNU tar extensions such as long filenames and long link names. 266.It Fl Fl atime-preserve 267Preserve file access times. 268.It Fl Fl chroot 269.Fn chroot 270to the current directory before extracting files. 271Use with 272.Fl x 273and 274.Fl h 275to make absolute symlinks relative to the current directory. 276.It Fl Fl unlink 277Ignored, only accepted for compatibility with other 278.Nm 279implementations. 280.Nm 281always unlinks files before creating them. 282.It Fl Fl use-compress-program Ar program 283Use the named program as the program to decompress the input. 284.It Fl Fl force-local 285Do not interpret filenames that contain a 286.Sq \&: 287as remote files. 288.It Fl Fl insecure 289Normally 290.Nm 291ignores filenames that contain 292.Dq .. 293as a path component. 294With this option, files that contain 295.Dq .. 296can be processed. 297.It Fl Fl no-recursion 298Cause files of type directory being copied or archived, or archive members of 299type directory being extracted, to match only the directory file or archive 300member and not the file hierarchy rooted at the directory. 301.It Fl Fl timestamp Ar timestamp 302Store all modification times in the archive with the 303.Ar timestamp 304given instead of the actual modification time of the individual archive member 305so that repeatable builds are possible. 306The 307.Ar timestamp 308can be a 309.Pa pathname , 310where the timestamps are derived from that file, a parseable date for 311.Xr parsedate 3 312(this option is not yet available in the tools build), or an integer value 313interpreted as the number of seconds from the Epoch. 314.El 315.Pp 316The options 317.Op Fl 014578 318can be used to select one of the compiled-in backup devices, 319.Pa /dev/rstN . 320.Sh FILES 321.Bl -tag -width "/dev/rst0" 322.It Pa /dev/rst0 323default archive name 324.El 325.Sh DIAGNOSTICS 326.Nm 327will exit with one of the following values: 328.Bl -tag -width 2n 329.It 0 330All files were processed successfully. 331.It 1 332An error occurred. 333.El 334.Pp 335Whenever 336.Nm 337cannot create a file or a link when extracting an archive or cannot 338find a file while writing an archive, or cannot preserve the user 339ID, group ID, file mode, or access and modification times when the 340.Fl p 341option is specified, a diagnostic message is written to standard 342error and a non-zero exit value will be returned, but processing 343will continue. 344In the case where 345.Nm 346cannot create a link to a file, 347.Nm 348will not create a second copy of the file. 349.Pp 350If the extraction of a file from an archive is prematurely terminated 351by a signal or error, 352.Nm 353may have only partially extracted the file the user wanted. 354Additionally, the file modes of extracted files and directories may 355have incorrect file bits, and the modification and access times may 356be wrong. 357.Pp 358If the creation of an archive is prematurely terminated by a signal 359or error, 360.Nm 361may have only partially created the archive which may violate the 362specific archive format specification. 363.Sh SEE ALSO 364.Xr cpio 1 , 365.Xr pax 1 366.Sh HISTORY 367A 368.Nm 369command first appeared in 370.At v7 . 371.Sh AUTHORS 372.An Keith Muller 373at the University of California, San Diego. 374