| 1 | .\" $MirOS: src/bin/pax/tar.1,v 1.6 2006/06/19 20:31:05 tg Exp $
|
|---|
| 2 | .\" $OpenBSD: tar.1,v 1.47 2005/05/24 16:33:45 jaredy Exp $
|
|---|
| 3 | .\"
|
|---|
| 4 | .\" Copyright (c) 1996 SigmaSoft, Th. Lockert
|
|---|
| 5 | .\" All rights reserved.
|
|---|
| 6 | .\"
|
|---|
| 7 | .\" Redistribution and use in source and binary forms, with or without
|
|---|
| 8 | .\" modification, are permitted provided that the following conditions
|
|---|
| 9 | .\" are met:
|
|---|
| 10 | .\" 1. Redistributions of source code must retain the above copyright
|
|---|
| 11 | .\" notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | .\" 2. Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | .\" notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | .\" documentation and/or other materials provided with the distribution.
|
|---|
| 15 | .\"
|
|---|
| 16 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 17 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 18 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 19 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 20 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 21 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 22 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 23 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 24 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 25 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 26 | .\"
|
|---|
| 27 | .\" $OpenBSD: tar.1,v 1.47 2005/05/24 16:33:45 jaredy Exp $
|
|---|
| 28 | .\"
|
|---|
| 29 | .Dd February 7, 2001
|
|---|
| 30 | .Dt TAR 1
|
|---|
| 31 | .Os
|
|---|
| 32 | .Sh NAME
|
|---|
| 33 | .Nm tar
|
|---|
| 34 | .Nd tape archiver
|
|---|
| 35 | .Sh SYNOPSIS
|
|---|
| 36 | .Nm tar
|
|---|
| 37 | .Sm off
|
|---|
| 38 | .No { Cm crtux No } Op Cm 014578befHhLmOoPRSpqsvwXZz
|
|---|
| 39 | .Sm on
|
|---|
| 40 | .Bk -words
|
|---|
| 41 | .Op Ar blocking-factor | archive | replstr
|
|---|
| 42 | .Op Fl C Ar directory
|
|---|
| 43 | .Op Fl I Ar file
|
|---|
| 44 | .Op Ar file ...
|
|---|
| 45 | .Ek
|
|---|
| 46 | .Pp
|
|---|
| 47 | .Nm tar
|
|---|
| 48 | .No { Ns Fl crtux Ns }
|
|---|
| 49 | .Op Fl 014578eHhLmOoPpqvwXZz
|
|---|
| 50 | .Op Fl b Ar blocking-factor
|
|---|
| 51 | .Op Fl C Ar directory
|
|---|
| 52 | .Op Fl f Ar archive
|
|---|
| 53 | .Op Fl I Ar file
|
|---|
| 54 | .Op Fl M Ar value
|
|---|
| 55 | .Op Fl s Ar replstr
|
|---|
| 56 | .Op Ar file ...
|
|---|
| 57 | .Sh DESCRIPTION
|
|---|
| 58 | The
|
|---|
| 59 | .Nm
|
|---|
| 60 | command creates, adds files to, or extracts files from an
|
|---|
| 61 | archive file in
|
|---|
| 62 | .Dq tar
|
|---|
| 63 | format.
|
|---|
| 64 | A tar archive is often stored on a magnetic tape, but can be
|
|---|
| 65 | stored equally well on a floppy, CD-ROM, or in a regular disk file.
|
|---|
| 66 | .Pp
|
|---|
| 67 | In the first (legacy) form, all option flags except for
|
|---|
| 68 | .Fl C
|
|---|
| 69 | and
|
|---|
| 70 | .Fl I
|
|---|
| 71 | must be contained within the first argument to
|
|---|
| 72 | .Nm
|
|---|
| 73 | and must not be prefixed by a hyphen
|
|---|
| 74 | .Pq Sq - .
|
|---|
| 75 | Option arguments, if any, are processed as subsequent arguments to
|
|---|
| 76 | .Nm
|
|---|
| 77 | and are processed in the order in which their corresponding option
|
|---|
| 78 | flags have been presented on the command line.
|
|---|
| 79 | .Pp
|
|---|
| 80 | In the second and preferred form, option flags may be given in any order
|
|---|
| 81 | and are immediately followed by their corresponding option argument
|
|---|
| 82 | values.
|
|---|
| 83 | .Pp
|
|---|
| 84 | One of the following flags must be present:
|
|---|
| 85 | .Bl -tag -width Ds
|
|---|
| 86 | .It Fl c
|
|---|
| 87 | Create new archive, or overwrite an existing archive,
|
|---|
| 88 | adding the specified files to it.
|
|---|
| 89 | .It Fl r
|
|---|
| 90 | Append the named new files to existing archive.
|
|---|
| 91 | Note that this will only work on media on which an end-of-file mark
|
|---|
| 92 | can be overwritten.
|
|---|
| 93 | .It Fl t
|
|---|
| 94 | List contents of archive.
|
|---|
| 95 | If any files are named on the
|
|---|
| 96 | command line, only those files will be listed.
|
|---|
| 97 | The
|
|---|
| 98 | .Ar file
|
|---|
| 99 | arguments may be specified as glob patterns (see
|
|---|
| 100 | .Xr glob 3
|
|---|
| 101 | for more information), in which case
|
|---|
| 102 | .Nm
|
|---|
| 103 | will list all archive members that match each pattern.
|
|---|
| 104 | .It Fl u
|
|---|
| 105 | Alias for
|
|---|
| 106 | .Fl r .
|
|---|
| 107 | .It Fl x
|
|---|
| 108 | Extract files from archive.
|
|---|
| 109 | If any files are named on the
|
|---|
| 110 | command line, only those files will be extracted from the
|
|---|
| 111 | archive.
|
|---|
| 112 | The
|
|---|
| 113 | .Ar file
|
|---|
| 114 | arguments may be specified as glob patterns (see
|
|---|
| 115 | .Xr glob 3
|
|---|
| 116 | for more information), in which case
|
|---|
| 117 | .Nm
|
|---|
| 118 | will extract all archive members that match each pattern.
|
|---|
| 119 | .Pp
|
|---|
| 120 | If more than one copy of a file exists in the
|
|---|
| 121 | archive, later copies will overwrite earlier copies during
|
|---|
| 122 | extraction.
|
|---|
| 123 | The file mode and modification time are preserved
|
|---|
| 124 | if possible.
|
|---|
| 125 | The file mode is subject to modification by the
|
|---|
| 126 | .Xr umask 2 .
|
|---|
| 127 | .El
|
|---|
| 128 | .Pp
|
|---|
| 129 | In addition to the flags mentioned above, any of the following
|
|---|
| 130 | flags may be used:
|
|---|
| 131 | .Bl -tag -width Ds
|
|---|
| 132 | .It Fl b Ar blocking-factor
|
|---|
| 133 | Set blocking factor to use for the archive.
|
|---|
| 134 | .Nm
|
|---|
| 135 | uses 512-byte blocks.
|
|---|
| 136 | The default is 20, the maximum is 126.
|
|---|
| 137 | Archives with a blocking factor larger than 63 violate the
|
|---|
| 138 | .Tn POSIX
|
|---|
| 139 | standard and will not be portable to all systems.
|
|---|
| 140 | .It Fl C Ar directory
|
|---|
| 141 | This is a positional argument which sets the working directory for the
|
|---|
| 142 | following files.
|
|---|
| 143 | When extracting, files will be extracted into
|
|---|
| 144 | the specified directory; when creating, the specified files will be matched
|
|---|
| 145 | from the directory.
|
|---|
| 146 | .It Fl e
|
|---|
| 147 | Stop after the first error.
|
|---|
| 148 | .It Fl f Ar archive
|
|---|
| 149 | Filename where the archive is stored.
|
|---|
| 150 | Defaults to
|
|---|
| 151 | .Pa /dev/rst0 .
|
|---|
| 152 | .It Fl H
|
|---|
| 153 | Follow symlinks given on the command line only.
|
|---|
| 154 | .It Fl h
|
|---|
| 155 | Follow symbolic links as if they were normal files
|
|---|
| 156 | or directories.
|
|---|
| 157 | In extract mode this means that a directory entry in the archive
|
|---|
| 158 | will not overwrite an existing symbolic link, but rather what the
|
|---|
| 159 | link ultimately points to.
|
|---|
| 160 | .It Fl I Ar file
|
|---|
| 161 | This is a positional argument which reads the names of files to
|
|---|
| 162 | archive or extract from the given file, one per line.
|
|---|
| 163 | .It Fl L
|
|---|
| 164 | Synonym for the
|
|---|
| 165 | .Fl h
|
|---|
| 166 | option.
|
|---|
| 167 | .It Fl M Ar value
|
|---|
| 168 | Configure the archive normaliser.
|
|---|
| 169 | .Ar value
|
|---|
| 170 | is either a number or a string, optionally prefixed with
|
|---|
| 171 | .Dq no-
|
|---|
| 172 | to turn the flag off.
|
|---|
| 173 | See
|
|---|
| 174 | .Xr cpio 1
|
|---|
| 175 | for a comprehensive list and compatibility notes.
|
|---|
| 176 | .Pp
|
|---|
| 177 | .Bl -tag -width xxxxxx -compact
|
|---|
| 178 | .It Ar inodes
|
|---|
| 179 | 0x0001: Serialise inodes, zero device info.
|
|---|
| 180 | .It Ar links
|
|---|
| 181 | 0x0002: Store content of hard links only once.
|
|---|
| 182 | .It Ar mtime
|
|---|
| 183 | 0x0004: Zero out the file modification time.
|
|---|
| 184 | .It Ar uidgid
|
|---|
| 185 | 0x0008: Set owner to 0:0 (root:wheel).
|
|---|
| 186 | .El
|
|---|
| 187 | .Pp
|
|---|
| 188 | This option is only implemented for the cpio, sv4cpio,
|
|---|
| 189 | ustar, and sv4crc file format writing routines.
|
|---|
| 190 | For the ustar format, the
|
|---|
| 191 | .Ar inodes
|
|---|
| 192 | and
|
|---|
| 193 | .Ar links
|
|---|
| 194 | specifiers are ignored.
|
|---|
| 195 | .It Fl m
|
|---|
| 196 | Do not preserve modification time.
|
|---|
| 197 | .It Fl O
|
|---|
| 198 | Write old-style (non-POSIX) archives.
|
|---|
| 199 | .It Fl o
|
|---|
| 200 | Don't write directory information that the older (V7) style
|
|---|
| 201 | .Nm
|
|---|
| 202 | is unable to decode.
|
|---|
| 203 | This implies the
|
|---|
| 204 | .Fl O
|
|---|
| 205 | flag.
|
|---|
| 206 | .It Fl P
|
|---|
| 207 | Do not strip leading slashes
|
|---|
| 208 | .Pq Sq /
|
|---|
| 209 | from pathnames.
|
|---|
| 210 | The default is to strip leading slashes.
|
|---|
| 211 | .It Fl p
|
|---|
| 212 | Preserve user and group ID as well as file mode regardless of
|
|---|
| 213 | the current
|
|---|
| 214 | .Xr umask 2 .
|
|---|
| 215 | The setuid and setgid bits are only preserved if the user is
|
|---|
| 216 | the superuser.
|
|---|
| 217 | Only meaningful in conjunction with the
|
|---|
| 218 | .Fl x
|
|---|
| 219 | flag.
|
|---|
| 220 | .It Fl q
|
|---|
| 221 | Select the first archive member that matches each
|
|---|
| 222 | .Ar file
|
|---|
| 223 | operand.
|
|---|
| 224 | No more than one archive member is matched for each
|
|---|
| 225 | .Ar file .
|
|---|
| 226 | When members of type directory are matched, the file hierarchy rooted at that
|
|---|
| 227 | directory is also matched.
|
|---|
| 228 | .It Fl R
|
|---|
| 229 | Write SysVR4 CPIO files instead of tar or POSIX ustar files.
|
|---|
| 230 | Serialise inode numbers, zero out device information.
|
|---|
| 231 | The file content of hard links is stored only once.
|
|---|
| 232 | .It Fl S
|
|---|
| 233 | Write SysVR4 CPIO files with CRC instead of tar or POSIX ustar files.
|
|---|
| 234 | Serialise inode numbers, zero out device information.
|
|---|
| 235 | The file content of hard links is stored only once.
|
|---|
| 236 | .It Fl s Ar replstr
|
|---|
| 237 | Modify the archive member names according to the substitution expression
|
|---|
| 238 | .Ar replstr ,
|
|---|
| 239 | using the syntax of the
|
|---|
| 240 | .Xr ed 1
|
|---|
| 241 | utility regular expressions.
|
|---|
| 242 | .Ar file
|
|---|
| 243 | arguments may be given to restrict the list of archive members to those
|
|---|
| 244 | specified.
|
|---|
| 245 | .Pp
|
|---|
| 246 | The format of these regular expressions is
|
|---|
| 247 | .Pp
|
|---|
| 248 | .Dl /old/new/[gp]
|
|---|
| 249 | .Pp
|
|---|
| 250 | As in
|
|---|
| 251 | .Xr ed 1 ,
|
|---|
| 252 | .Va old
|
|---|
| 253 | is a basic regular expression (see
|
|---|
| 254 | .Xr re_format 7 )
|
|---|
| 255 | and
|
|---|
| 256 | .Va new
|
|---|
| 257 | can contain an ampersand
|
|---|
| 258 | .Pq Ql & ,
|
|---|
| 259 | .Ql \e Ns Em n
|
|---|
| 260 | (where
|
|---|
| 261 | .Em n
|
|---|
| 262 | is a digit) back-references,
|
|---|
| 263 | or subexpression matching.
|
|---|
| 264 | The
|
|---|
| 265 | .Va old
|
|---|
| 266 | string may also contain newline characters.
|
|---|
| 267 | Any non-null character can be used as a delimiter
|
|---|
| 268 | .Po
|
|---|
| 269 | .Ql /
|
|---|
| 270 | is shown here
|
|---|
| 271 | .Pc .
|
|---|
| 272 | Multiple
|
|---|
| 273 | .Fl s
|
|---|
| 274 | expressions can be specified.
|
|---|
| 275 | The expressions are applied in the order they are specified on the
|
|---|
| 276 | command line, terminating with the first successful substitution.
|
|---|
| 277 | .Pp
|
|---|
| 278 | The optional trailing
|
|---|
| 279 | .Cm g
|
|---|
| 280 | continues to apply the substitution expression to the pathname substring,
|
|---|
| 281 | which starts with the first character following the end of the last successful
|
|---|
| 282 | substitution.
|
|---|
| 283 | The first unsuccessful substitution stops the operation of the
|
|---|
| 284 | .Cm g
|
|---|
| 285 | option.
|
|---|
| 286 | The optional trailing
|
|---|
| 287 | .Cm p
|
|---|
| 288 | will cause the final result of a successful substitution to be written to
|
|---|
| 289 | standard error in the following format:
|
|---|
| 290 | .Pp
|
|---|
| 291 | .D1 Em original-pathname No >> Em new-pathname
|
|---|
| 292 | .Pp
|
|---|
| 293 | File or archive member names that substitute to the empty string
|
|---|
| 294 | are not selected and will be skipped.
|
|---|
| 295 | .It Fl v
|
|---|
| 296 | Verbose operation mode.
|
|---|
| 297 | .It Fl w
|
|---|
| 298 | Interactively rename files.
|
|---|
| 299 | This option causes
|
|---|
| 300 | .Nm
|
|---|
| 301 | to prompt the user for the filename to use when storing or
|
|---|
| 302 | extracting files in an archive.
|
|---|
| 303 | .It Fl X
|
|---|
| 304 | Do not cross mount points in the file system.
|
|---|
| 305 | .It Fl Z
|
|---|
| 306 | Compress archive using
|
|---|
| 307 | .Xr compress 1 .
|
|---|
| 308 | .It Fl z
|
|---|
| 309 | Compress archive using
|
|---|
| 310 | .Xr gzip 1 .
|
|---|
| 311 | .El
|
|---|
| 312 | .Pp
|
|---|
| 313 | The options
|
|---|
| 314 | .Op Fl 014578
|
|---|
| 315 | can be used to select one of the compiled-in backup devices,
|
|---|
| 316 | .Pa /dev/rstN .
|
|---|
| 317 | .Sh ENVIRONMENT
|
|---|
| 318 | .Bl -tag -width Fl
|
|---|
| 319 | .It Ev TMPDIR
|
|---|
| 320 | Path in which to store temporary files.
|
|---|
| 321 | .It Ev TAPE
|
|---|
| 322 | Default tape device to use instead of
|
|---|
| 323 | .Pa /dev/rst0 .
|
|---|
| 324 | .El
|
|---|
| 325 | .Sh FILES
|
|---|
| 326 | .Bl -tag -width "/dev/rst0"
|
|---|
| 327 | .It Pa /dev/rst0
|
|---|
| 328 | default archive name
|
|---|
| 329 | .El
|
|---|
| 330 | .Sh EXAMPLES
|
|---|
| 331 | Create an archive on the default tape drive, containing the files named
|
|---|
| 332 | .Pa bonvole
|
|---|
| 333 | and
|
|---|
| 334 | .Pa sekve :
|
|---|
| 335 | .Pp
|
|---|
| 336 | .Dl $ tar c bonvole sekve
|
|---|
| 337 | .Pp
|
|---|
| 338 | Output a
|
|---|
| 339 | .Xr gzip 1
|
|---|
| 340 | compressed archive containing the files
|
|---|
| 341 | .Pa bonvole
|
|---|
| 342 | and
|
|---|
| 343 | .Pa sekve
|
|---|
| 344 | to a file called
|
|---|
| 345 | .Pa foriru.tar.gz :
|
|---|
| 346 | .Pp
|
|---|
| 347 | .Dl $ tar zcf foriru.tar.gz bonvole sekve
|
|---|
| 348 | .Pp
|
|---|
| 349 | Verbosely create an archive, called
|
|---|
| 350 | .Pa backup.tar.gz ,
|
|---|
| 351 | of all files matching the shell
|
|---|
| 352 | .Xr glob 3
|
|---|
| 353 | function
|
|---|
| 354 | .Pa *.c :
|
|---|
| 355 | .Pp
|
|---|
| 356 | .Dl $ tar zcvf backup.tar.gz *.c
|
|---|
| 357 | .Pp
|
|---|
| 358 | Verbosely list, but do not extract, all files ending in
|
|---|
| 359 | .Pa .jpeg
|
|---|
| 360 | from a compressed archive named
|
|---|
| 361 | .Pa backup.tar.gz .
|
|---|
| 362 | Note that the glob pattern has been quoted to avoid expansion by the shell:
|
|---|
| 363 | .Pp
|
|---|
| 364 | .Dl $ tar tvzf backup.tar.gz '*.jpeg'
|
|---|
| 365 | .Pp
|
|---|
| 366 | For more detailed examples, see
|
|---|
| 367 | .Xr pax 1 .
|
|---|
| 368 | .Sh DIAGNOSTICS
|
|---|
| 369 | .Nm
|
|---|
| 370 | will exit with one of the following values:
|
|---|
| 371 | .Bl -tag -width 2n -offset indent
|
|---|
| 372 | .It 0
|
|---|
| 373 | All files were processed successfully.
|
|---|
| 374 | .It 1
|
|---|
| 375 | An error occurred.
|
|---|
| 376 | .El
|
|---|
| 377 | .Pp
|
|---|
| 378 | Whenever
|
|---|
| 379 | .Nm
|
|---|
| 380 | cannot create a file or a link when extracting an archive or cannot
|
|---|
| 381 | find a file while writing an archive, or cannot preserve the user
|
|---|
| 382 | ID, group ID, file mode, or access and modification times when the
|
|---|
| 383 | .Fl p
|
|---|
| 384 | option is specified, a diagnostic message is written to standard
|
|---|
| 385 | error and a non-zero exit value will be returned, but processing
|
|---|
| 386 | will continue.
|
|---|
| 387 | In the case where
|
|---|
| 388 | .Nm
|
|---|
| 389 | cannot create a link to a file,
|
|---|
| 390 | .Nm
|
|---|
| 391 | will not create a second copy of the file.
|
|---|
| 392 | .Pp
|
|---|
| 393 | If the extraction of a file from an archive is prematurely terminated
|
|---|
| 394 | by a signal or error,
|
|---|
| 395 | .Nm
|
|---|
| 396 | may have only partially extracted the file the user wanted.
|
|---|
| 397 | Additionally, the file modes of extracted files and directories may
|
|---|
| 398 | have incorrect file bits, and the modification and access times may
|
|---|
| 399 | be wrong.
|
|---|
| 400 | .Pp
|
|---|
| 401 | If the creation of an archive is prematurely terminated by a signal
|
|---|
| 402 | or error,
|
|---|
| 403 | .Nm
|
|---|
| 404 | may have only partially created the archive, which may violate the
|
|---|
| 405 | specific archive format specification.
|
|---|
| 406 | .Sh SEE ALSO
|
|---|
| 407 | .Xr cpio 1 ,
|
|---|
| 408 | .Xr pax 1
|
|---|
| 409 | .Sh HISTORY
|
|---|
| 410 | A
|
|---|
| 411 | .Nm
|
|---|
| 412 | command first appeared in
|
|---|
| 413 | .At v7 .
|
|---|
| 414 | .Sh AUTHORS
|
|---|
| 415 | Keith Muller at the University of California, San Diego.
|
|---|
| 416 | .Sh CAVEATS
|
|---|
| 417 | The
|
|---|
| 418 | .Fl L
|
|---|
| 419 | flag is not portable to other versions of
|
|---|
| 420 | .Nm
|
|---|
| 421 | where it may have a different meaning.
|
|---|
| 422 | The
|
|---|
| 423 | .Fl R ,
|
|---|
| 424 | .Fl S ,
|
|---|
| 425 | and
|
|---|
| 426 | .Fl M
|
|---|
| 427 | options are extensions specific to
|
|---|
| 428 | .Mx .
|
|---|