1.\" $NetBSD: tar.1,v 1.11 2003/04/10 06:07:40 grant 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.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by SigmaSoft, Th. Lockert. 17.\" 4. The name of the author may not be used to endorse or promote products 18.\" derived from this software without specific prior written permission 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30.\" 31.\" OpenBSD: tar.1,v 1.28 2000/11/09 23:58:56 aaron Exp 32.\" 33.Dd April 4, 2003 34.Dt TAR 1 35.Os 36.Sh NAME 37.Nm tar 38.Nd tape archiver 39.Sh SYNOPSIS 40.Nm tar 41.Sm off 42.Oo \&- Oc {crtux} Op Fl befhjklmopqvwzHLOPXZ014578 43.Sm on 44.Op Ar archive 45.Op Ar blocksize 46.\" XXX how to do this right? 47.Op Fl C Ar directory 48.Op Fl T Ar file 49.Op Fl s Ar replstr 50.Op Ar file ... 51.Sh DESCRIPTION 52The 53.Nm 54command creates, adds files to, or extracts files from an 55archive file in 56.Dq tar 57format. 58A tar archive is often stored on a magnetic tape, but can be 59stored equally well on a floppy, CD-ROM, or in a regular disk file. 60.Pp 61One of the following flags must be present: 62.Bl -tag -width Ar 63.It Fl c , -create 64Create new archive, or overwrite an existing archive, 65adding the specified files to it. 66.It Fl r , -append 67Append the named new files to existing archive. 68Note that this will only work on media on which an end-of-file mark 69can be overwritten. 70.It Fl t , -list 71List contents of archive. 72If any files are named on the 73command line, only those files will be listed. 74.It Fl u , -update 75Alias for 76.Fl r . 77.It Fl x , -extract , -get 78Extract files from archive. 79If any files are named on the 80command line, only those files will be extracted from the 81archive. 82If more than one copy of a file exists in the 83archive, later copies will overwrite earlier copies during 84extraction. 85The file mode and modification time are preserved 86if possible. 87The file mode is subject to modification by the 88.Xr umask 2 . 89.El 90.Pp 91In addition to the flags mentioned above, any of the following 92flags may be used: 93.Bl -tag -width Ar 94.It Fl b Ar "blocking factor" , Fl -block-size Ar "blocking factor" 95Set blocking factor to use for the archive. 96.Nm 97uses 512 byte blocks. 98The default is 20, the maximum is 126. 99Archives with a blocking factor larger 63 violate the 100.Tn POSIX 101standard and will not be portable to all systems. 102.It Fl e 103Stop after first error. 104.It Fl f Ar archive , Fl -file Ar archive 105Filename where the archive is stored. 106Defaults to 107.Pa /dev/rst0 . 108If the archive is of the form: 109.Ar [[user@]host:]file 110then the archive will be processed using 111.Xr rmt 8 . 112.It Fl h , -dereference 113Follow symbolic links as if they were normal files 114or directories. 115.It Fl j, -bzip2, -bunzip2 116Use 117.Xr bzip2 1 118for compression of the archive. 119This option is a GNU extension. 120.It Fl k , -keep-old-files 121Keep existing files; don't overwrite them from archive. 122.It Fl l , -one-file-system 123Do not cross filesystems. 124.It Fl m , -modification-time 125Do not preserve modification time. 126.It Fl O 127Write old-style (non-POSIX) archives. 128.It Fl o , -portability , -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 , -preserve-permissions , -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 , -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 Ar replstr 153Modify the file or archive member names specified by the 154.Ar pattern 155or 156.Ar file 157operands according to the substitution expression 158.Ar replstr , 159using the syntax of the 160.Xr ed 1 161utility regular expressions. 162The format of these regular expressions are: 163.Dl /old/new/[gp] 164As in 165.Xr ed 1 , 166.Cm old 167is a basic regular expression and 168.Cm new 169can contain an ampersand (\*[Am]), \\n (where n is a digit) back-references, 170or subexpression matching. 171The 172.Cm old 173string may also contain 174.Aq Dv newline 175characters. 176Any non-null character can be used as a delimiter (/ is shown here). 177Multiple 178.Fl s 179expressions can be specified. 180The expressions are applied in the order they are specified on the 181command line, terminating with the first successful substitution. 182The optional trailing 183.Cm g 184continues to apply the substitution expression to the pathname substring 185which starts with the first character following the end of the last successful 186substitution. 187The first unsuccessful substitution stops the operation of the 188.Cm g 189option. 190The optional trailing 191.Cm p 192will cause the final result of a successful substitution to be written to 193.Dv standard error 194in the following format: 195.Dl \*[Lt]original pathname\*[Gt] \*[Gt]\*[Gt] \*[Lt]new pathname\*[Gt] 196File or archive member names that substitute to the empty string 197are not selected and will be skipped. 198.It Fl v 199Verbose operation mode. 200.It Fl w , -interactive , -confirmation 201Interactively rename files. 202This option causes 203.Nm 204to prompt the user for the filename to use when storing or 205extracting files in an archive. 206.It Fl z , -gzip , -gunzip 207Compress archive using gzip. 208.It Fl B , -read-full-blocks 209Reassemble small reads into full blocks (For reading from 4.2BSD pipes). 210.It Fl C Ar directory , Fl -directory Ar directory 211This is a positional argument which sets the working directory for the 212following files. 213When extracting, files will be extracted into 214the specified directory; when creating, the specified files will be matched 215from the directory. 216This argument and its parameter may also appear in a file list specified by 217.Fl T . 218.It Fl H 219Follow symlinks given on command line only. 220.It Fl P , -absolute-paths 221Do not strip leading slashes 222.Pq Sq / 223from pathnames. 224The default is to strip leading slashes. 225.It Fl T Ar file , Fl -files-from Ar file 226Read the names of files to archive or extract from the given file, one 227per line. 228A line may also specify the positional argument 229.Dq Fl C Ar directory . 230.It Fl X Ar file , Fl -exclude-from Ar file 231Exclude files listed in the given file. 232.It Fl Z , -compress , -uncompress 233Compress archive using compress. 234.It Fl -strict 235Do not enable GNU tar extensions such as long filenames and long link names. 236.It Fl -atime-preserve 237Preserve file access times. 238.It Fl -unlink 239Remove files before creating them. 240.It Fl -use-compress-program Ar program 241Use the named program as the program to decompress the input. 242.It Fl -force-local 243Do not interpret filenames that contain a 244.Sq \&: 245as remote files. 246.It Fl -insecure 247Normally 248.Nm 249ignores filenames that contain 250.Sq .. 251as a path component. 252With this option, files that contain 253.Sq .. 254can be processed. 255.El 256.Pp 257The options 258.Op Fl 014578 259can be used to select one of the compiled-in backup devices, 260.Pa /dev/rstN . 261.Sh FILES 262.Bl -tag -width "/dev/rst0" 263.It Pa /dev/rst0 264default archive name 265.El 266.Sh DIAGNOSTICS 267.Nm 268will exit with one of the following values: 269.Bl -tag -width 2n 270.It 0 271All files were processed successfully. 272.It 1 273An error occurred. 274.El 275.Pp 276Whenever 277.Nm 278cannot create a file or a link when extracting an archive or cannot 279find a file while writing an archive, or cannot preserve the user 280ID, group ID, file mode, or access and modification times when the 281.Fl p 282option is specified, a diagnostic message is written to standard 283error and a non-zero exit value will be returned, but processing 284will continue. 285In the case where 286.Nm 287cannot create a link to a file, 288.Nm 289will not create a second copy of the file. 290.Pp 291If the extraction of a file from an archive is prematurely terminated 292by a signal or error, 293.Nm 294may have only partially extracted the file the user wanted. 295Additionally, the file modes of extracted files and directories may 296have incorrect file bits, and the modification and access times may 297be wrong. 298.Pp 299If the creation of an archive is prematurely terminated by a signal 300or error, 301.Nm 302may have only partially created the archive which may violate the 303specific archive format specification. 304.Sh SEE ALSO 305.Xr cpio 1 , 306.Xr pax 1 307.Sh HISTORY 308A 309.Nm 310command first appeared in 311.At v7 . 312.Sh AUTHORS 313Keith Muller at the University of California, San Diego. 314