Import libarchive-2.4.17. See NEWS for details.
[dragonfly.git] / contrib / libarchive-2 / tar / bsdtar.1
blobec22160d998a89a7beedfb21a41eef37cea5ede1
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: src/usr.bin/tar/bsdtar.1,v 1.37 2008/01/22 07:23:44 kientzle Exp $
26 .\"
27 .Dd April 13, 2004
28 .Dt BSDTAR 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 | directories
41 .Nm
42 .Brq Fl r | Fl u
43 .Fl f Ar archive-file
44 .Op Ar options
45 .Op Ar files | directories
46 .Nm
47 .Brq Fl t | Fl x
48 .Op Ar options
49 .Op Ar patterns
50 .Sh DESCRIPTION
51 .Nm
52 creates and manipulates streaming archive files.
53 This implementation can extract from tar, pax, cpio, zip, jar, ar,
54 and ISO 9660 cdrom images and can create tar, pax, cpio, ar,
55 and shar archives.
56 .Pp
57 The first synopsis form shows a
58 .Dq bundled
59 option word.
60 This usage is provided for compatibility with historical implementations.
61 See COMPATIBILITY below for details.
62 .Pp
63 The other synopsis forms show the preferred usage.
64 The first option to
65 .Nm
66 is a mode indicator from the following list:
67 .Bl -tag -compact -width indent
68 .It Fl c
69 Create a new archive containing the specified items.
70 .It Fl r
71 Like
72 .Fl c ,
73 but new entries are appended to the archive.
74 Note that this only works on uncompressed archives stored in regular files.
75 The
76 .Fl f
77 option is required.
78 .It Fl t
79 List archive contents to stdout.
80 .It Fl u
81 Like
82 .Fl r ,
83 but new entries are added only if they have a modification date
84 newer than the corresponding entry in the archive.
85 Note that this only works on uncompressed archives stored in regular files.
86 The
87 .Fl f
88 option is required.
89 .It Fl x
90 Extract to disk from the archive.
91 If a file with the same name appears more than once in the archive,
92 each copy will be extracted, with later copies overwriting (replacing)
93 earlier copies.
94 .El
95 .Pp
97 .Fl c ,
98 .Fl r ,
100 .Fl u
101 mode, each specified file or directory is added to the
102 archive in the order specified on the command line.
103 By default, the contents of each directory are also archived.
105 In extract or list mode, the entire command line
106 is read and parsed before the archive is opened.
107 The pathnames or patterns on the command line indicate
108 which items in the archive should be processed.
109 Patterns are shell-style globbing patterns as
110 documented in
111 .Xr tcsh 1 .
112 .Sh OPTIONS
113 Unless specifically stated otherwise, options are applicable in
114 all operating modes.
115 .Bl -tag -width indent
116 .It Cm @ Ns Pa archive
117 (c and r mode only)
118 The specified archive is opened and the entries
119 in it will be appended to the current archive.
120 As a simple example,
121 .Dl Nm Fl c Fl f Pa - Pa newfile Cm @ Ns Pa original.tar
122 writes a new archive to standard output containing a file
123 .Pa newfile
124 and all of the entries from
125 .Pa original.tar .
126 In contrast,
127 .Dl Nm Fl c Fl f Pa - Pa newfile Pa original.tar
128 creates a new archive with only two entries.
129 Similarly,
130 .Dl Nm Fl czf Pa - Fl -format Cm pax Cm @ Ns Pa -
131 reads an archive from standard input (whose format will be determined
132 automatically) and converts it into a gzip-compressed
133 pax-format archive on stdout.
134 In this way,
136 can be used to convert archives from one format to another.
137 .It Fl b Ar blocksize
138 Specify the block size, in 512-byte records, for tape drive I/O.
139 As a rule, this argument is only needed when reading from or writing
140 to tape drives, and usually not even then as the default block size of
141 20 records (10240 bytes) is very common.
142 .It Fl C Ar directory
143 In c and r mode, this changes the directory before adding
144 the following files.
145 In x mode, change directories after opening the archive
146 but before extracting entries from the archive.
147 .It Fl -check-links ( Fl W Cm check-links )
148 (c and r modes only)
149 Issue a warning message unless all links to each file are archived.
150 .It Fl -exclude Ar pattern ( Fl W Cm exclude Ns = Ns Ar pattern )
151 Do not process files or directories that match the
152 specified pattern.
153 Note that exclusions take precedence over patterns or filenames
154 specified on the command line.
155 .It Fl -format Ar format ( Fl W Cm format Ns = Ns Ar format )
156 (c mode only)
157 Use the specified format for the created archive.
158 Supported formats include
159 .Dq cpio ,
160 .Dq pax ,
161 .Dq shar ,
163 .Dq ustar .
164 Other formats may also be supported; see
165 .Xr libarchive-formats 5
166 for more information about currently-supported formats.
167 .It Fl f Ar file
168 Read the archive from or write the archive to the specified file.
169 The filename can be
170 .Pa -
171 for standard input or standard output.
172 If not specified, the default tape device will be used.
174 .Fx ,
175 the default tape device is
176 .Pa /dev/sa0 . )
177 .It Fl -fast-read ( Fl W Cm fast-read )
178 (x and t mode only)
179 Extract or list only the first archive entry that matches each pattern
180 or filename operand.
181 Exit as soon as each specified pattern or filename has been matched.
182 By default, the archive is always read to the very end, since
183 there can be multiple entries with the same name and, by convention,
184 later entries overwrite earlier entries.
185 This option is provided as a performance optimization.
186 .It Fl H
187 (c and r mode only)
188 Symbolic links named on the command line will be followed; the
189 target of the link will be archived, not the link itself.
190 .It Fl h
191 (c and r mode only)
192 Synonym for
193 .Fl L .
194 .It Fl I
195 Synonym for
196 .Fl T .
197 .It Fl -include Ar pattern ( Fl W Cm include Ns = Ns Ar pattern )
198 Process only files or directories that match the specified pattern.
199 Note that exclusions specified with
200 .Fl -exclude
201 take precedence over inclusions.
202 If no inclusions are explicitly specified, all entries are processed by
203 default.
205 .Fl -include
206 option is especially useful when filtering archives.
207 For example, the command
208 .Dl Nm Fl c Fl f Pa new.tar Fl -include='*foo*' Cm @ Ns Pa old.tgz
209 creates a new archive
210 .Pa new.tar
211 containing only the entries from
212 .Pa old.tgz
213 containing the string
214 .Sq foo .
215 .It Fl j
216 (c mode only)
217 Compress the resulting archive with
218 .Xr bzip2 1 .
219 In extract or list modes, this option is ignored.
220 Note that, unlike other
221 .Nm tar
222 implementations, this implementation recognizes bzip2 compression
223 automatically when reading archives.
224 .It Fl k
225 (x mode only)
226 Do not overwrite existing files.
227 In particular, if a file appears more than once in an archive,
228 later copies will not overwrite earlier copies.
229 .It Fl L
230 (c and r mode only)
231 All symbolic links will be followed.
232 Normally, symbolic links are archived as such.
233 With this option, the target of the link will be archived instead.
234 .It Fl l
235 This is a synonym for the
236 .Fl -check-links
237 option.
238 .It Fl m
239 (x mode only)
240 Do not extract modification time.
241 By default, the modification time is set to the time stored in the archive.
242 .It Fl n
243 (c, r, u modes only)
244 Do not recursively archive the contents of directories.
245 .It Fl -newer Ar date ( Fl W Cm newer Ns = Ns Ar date )
246 (c, r, u modes only)
247 Only include files and directories newer than the specified date.
248 This compares ctime entries.
249 .It Fl -newer-mtime Ar date ( Fl W Cm newer-mtime Ns = Ns Ar date )
250 (c, r, u modes only)
251 Like
252 .Fl -newer ,
253 except it compares mtime entries instead of ctime entries.
254 .It Fl -newer-than Pa file ( Fl W Cm newer-than Ns = Ns Pa file )
255 (c, r, u modes only)
256 Only include files and directories newer than the specified file.
257 This compares ctime entries.
258 .It Fl -newer-mtime-than Pa file ( Fl W Cm newer-mtime-than Ns = Ns Pa file )
259 (c, r, u modes only)
260 Like
261 .Fl -newer-than ,
262 except it compares mtime entries instead of ctime entries.
263 .It Fl -nodump ( Fl W Cm nodump )
264 (c and r modes only)
265 Honor the nodump file flag by skipping this file.
266 .It Fl -null ( Fl W Cm null )
267 (use with
268 .Fl I ,
269 .Fl T ,
271 .Fl X )
272 Filenames or patterns are separated by null characters,
273 not by newlines.
274 This is often used to read filenames output by the
275 .Fl print0
276 option to
277 .Xr find 1 .
278 .It Fl O
279 (x, t modes only)
280 In extract (-x) mode, files will be written to standard out rather than
281 being extracted to disk.
282 In list (-t) mode, the file listing will be written to stderr rather than
283 the usual stdout.
284 .It Fl o
285 (x mode only)
286 Use the user and group of the user running the program rather
287 than those specified in the archive.
288 Note that this has no significance unless
289 .Fl p
290 is specified, and the program is being run by the root user.
291 In this case, the file modes and flags from
292 the archive will be restored, but ACLs or owner information in
293 the archive will be discarded.
294 .It Fl -one-file-system ( Fl W Cm one-file-system )
295 (c, r, and u modes)
296 Do not cross mount points.
297 .It Fl P
298 Preserve pathnames.
299 By default, absolute pathnames (those that begin with a /
300 character) have the leading slash removed both when creating archives
301 and extracting from them.
302 Also,
304 will refuse to extract archive entries whose pathnames contain
305 .Pa ..
306 or whose target directory would be altered by a symlink.
307 This option suppresses these behaviors.
308 .It Fl p
309 (x mode only)
310 Preserve file permissions.
311 Attempt to restore the full permissions, including owner, file modes, file
312 flags and ACLs, if available, for each item extracted from the archive.
313 By default, newly-created files are owned by the user running
314 .Nm ,
315 the file mode is restored for newly-created regular files, and
316 all other types of entries receive default permissions.
319 is being run by root, the default is to restore the owner unless the
320 .Fl o
321 option is also specified.
322 .It Fl -strip-components Ar count ( Fl W Cm strip-components Ns = Ns Ar count )
323 (x and t mode only)
324 Remove the specified number of leading path elements.
325 Pathnames with fewer elements will be silently skipped.
326 Note that the pathname is edited after checking inclusion/exclusion patterns
327 but before security checks.
328 .It Fl T Ar filename
329 In x or t mode,
331 will read the list of names to be extracted from
332 .Pa filename .
333 In c mode,
335 will read names to be archived from
336 .Pa filename .
337 The special name
338 .Dq -C
339 on a line by itself will cause the current directory to be changed to
340 the directory specified on the following line.
341 Names are terminated by newlines unless
342 .Fl -null
343 is specified.
344 Note that
345 .Fl -null
346 also disables the special handling of lines containing
347 .Dq -C .
348 .It Fl U
349 (x mode only)
350 Unlink files before creating them.
351 Without this option,
353 overwrites existing files, which preserves existing hardlinks.
354 With this option, existing hardlinks will be broken, as will any
355 symlink that would affect the location of an extracted file.
356 .It Fl -use-compress-program Ar program
357 Pipe the input (in x or t mode) or the output (in c mode) through
358 .Pa program
359 instead of using the builtin compression support.
360 .It Fl v
361 Produce verbose output.
362 In create and extract modes,
364 will list each file name as it is read from or written to
365 the archive.
366 In list mode,
368 will produce output similar to that of
369 .Xr ls 1 .
370 Additional
371 .Fl v
372 options will provide additional detail.
373 .It Fl W Ar longopt=value
374 Long options (preceded by
375 .Fl - )
376 are only supported directly on systems that have the
377 .Xr getopt_long 3
378 function.
380 .Fl W
381 option can be used to access long options on systems that
382 do not support this function.
383 .It Fl w
384 Ask for confirmation for every action.
385 .It Fl X Ar filename
386 Read a list of exclusion patterns from the specified file.
388 .Fl -exclude
389 for more information about the handling of exclusions.
390 .It Fl y
391 (c mode only)
392 Compress the resulting archive with
393 .Xr bzip2 1 .
394 In extract or list modes, this option is ignored.
395 Note that, unlike other
396 .Nm tar
397 implementations, this implementation recognizes bzip2 compression
398 automatically when reading archives.
399 .It Fl z
400 (c mode only)
401 Compress the resulting archive with
402 .Xr gzip 1 .
403 In extract or list modes, this option is ignored.
404 Note that, unlike other
405 .Nm tar
406 implementations, this implementation recognizes gzip compression
407 automatically when reading archives.
409 .Sh ENVIRONMENT
410 The following environment variables affect the execution of
411 .Nm :
412 .Bl -tag -width ".Ev BLOCKSIZE"
413 .It Ev LANG
414 The locale to use.
416 .Xr environ 7
417 for more information.
418 .It Ev TAPE
419 The default tape device.
421 .Fl f
422 option overrides this.
423 .It Ev TZ
424 The timezone to use when displaying dates.
426 .Xr environ 7
427 for more information.
429 .Sh FILES
430 .Bl -tag -width ".Ev BLOCKSIZE"
431 .It Pa /dev/sa0
432 The default tape device, if not overridden by the
433 .Ev TAPE
434 environment variable or the
435 .Fl f
436 option.
438 .Sh EXIT STATUS
439 .Ex -std
440 .Sh EXAMPLES
441 The following creates a new archive
442 called
443 .Ar file.tar.gz
444 that contains two files
445 .Ar source.c
447 .Ar source.h :
448 .Dl Nm Fl czf Pa file.tar.gz Pa source.c Pa source.h
450 To view a detailed table of contents for this
451 archive:
452 .Dl Nm Fl tvf Pa file.tar.gz
454 To extract all entries from the archive on
455 the default tape drive:
456 .Dl Nm Fl x
458 To examine the contents of an ISO 9660 cdrom image:
459 .Dl Nm Fl tf Pa image.iso
461 To move file hierarchies, invoke
464 .Dl Nm Fl cf Pa - Fl C Pa srcdir\ . | Nm Fl xpf Pa - Fl C Pa destdir
465 or more traditionally
466 .Dl cd srcdir \&; Nm Fl cf Pa -\ . | ( cd destdir \&; Nm Fl xpf Pa - )
468 In create mode, the list of files and directories to be archived
469 can also include directory change instructions of the form
470 .Cm -C Ns Pa foo/baz
471 and archive inclusions of the form
472 .Cm @ Ns Pa archive-file .
473 For example, the command line
474 .Dl Nm Fl c Fl f Pa new.tar Pa foo1 Cm @ Ns Pa old.tgz Cm -C Ns Pa /tmp Pa foo2
475 will create a new archive
476 .Pa new.tar .
478 will read the file
479 .Pa foo1
480 from the current directory and add it to the output archive.
481 It will then read each entry from
482 .Pa old.tgz
483 and add those entries to the output archive.
484 Finally, it will switch to the
485 .Pa /tmp
486 directory and add
487 .Pa foo2
488 to the output archive.
491 .Fl -newer
493 .Fl -newer-mtime
494 switches accept a variety of common date and time specifications, including
495 .Dq 12 Mar 2005 7:14:29pm ,
496 .Dq 2005-03-12 19:14 ,
497 .Dq 5 minutes ago ,
499 .Dq 19:14 PST May 1 .
500 .Sh COMPATIBILITY
501 The bundled-arguments format is supported for compatibility
502 with historic implementations.
503 It consists of an initial word (with no leading - character) in which
504 each character indicates an option.
505 Arguments follow as separate words.
506 The order of the arguments must match the order
507 of the corresponding characters in the bundled command word.
508 For example,
509 .Dl Nm Cm tbf 32 Pa file.tar
510 specifies three flags
511 .Cm t ,
512 .Cm b ,
514 .Cm f .
516 .Cm b
518 .Cm f
519 flags both require arguments,
520 so there must be two additional items
521 on the command line.
523 .Ar 32
524 is the argument to the
525 .Cm b
526 flag, and
527 .Ar file.tar
528 is the argument to the
529 .Cm f
530 flag.
532 The mode options c, r, t, u, and x and the options
533 b, f, l, m, o, v, and w comply with SUSv2.
535 For maximum portability, scripts that invoke
536 .Nm tar
537 should use the bundled-argument format above, should limit
538 themselves to the
539 .Cm c ,
540 .Cm t ,
542 .Cm x
543 modes, and the
544 .Cm b ,
545 .Cm f ,
546 .Cm m ,
547 .Cm v ,
549 .Cm w
550 options.
552 On systems that support getopt_long(), additional long options
553 are available to improve compatibility with other tar implementations.
554 .Sh SECURITY
555 Certain security issues are common to many archiving programs, including
556 .Nm .
557 In particular, carefully-crafted archives can request that
559 extract files to locations outside of the target directory.
560 This can potentially be used to cause unwitting users to overwrite
561 files they did not intend to overwrite.
562 If the archive is being extracted by the superuser, any file
563 on the system can potentially be overwritten.
564 There are three ways this can happen.
565 Although
567 has mechanisms to protect against each one,
568 savvy users should be aware of the implications:
569 .Bl -bullet -width indent
571 Archive entries can have absolute pathnames.
572 By default,
574 removes the leading
575 .Pa /
576 character from filenames before restoring them to guard against this problem.
578 Archive entries can have pathnames that include
579 .Pa ..
580 components.
581 By default,
583 will not extract files containing
584 .Pa ..
585 components in their pathname.
587 Archive entries can exploit symbolic links to restore
588 files to other directories.
589 An archive can restore a symbolic link to another directory,
590 then use that link to restore a file into that directory.
591 To guard against this,
593 checks each extracted path for symlinks.
594 If the final path element is a symlink, it will be removed
595 and replaced with the archive entry.
597 .Fl U
598 is specified, any intermediate symlink will also be unconditionally removed.
599 If neither
600 .Fl U
602 .Fl P
603 is specified,
605 will refuse to extract the entry.
607 To protect yourself, you should be wary of any archives that
608 come from untrusted sources.
609 You should examine the contents of an archive with
610 .Dl Nm Fl tf Pa filename
611 before extraction.
612 You should use the
613 .Fl k
614 option to ensure that
616 will not overwrite any existing files or the
617 .Fl U
618 option to remove any pre-existing files.
619 You should generally not extract archives while running with super-user
620 privileges.
621 Note that the
622 .Fl P
623 option to
625 disables the security checks above and allows you to extract
626 an archive while preserving any absolute pathnames,
627 .Pa ..
628 components, or symlinks to other directories.
629 .Sh SEE ALSO
630 .Xr bzip2 1 ,
631 .Xr cpio 1 ,
632 .Xr gzip 1 ,
633 .Xr mt 1 ,
634 .Xr pax 1 ,
635 .Xr shar 1 ,
636 .Xr libarchive 3 ,
637 .Xr libarchive-formats 5 ,
638 .Xr tar 5
639 .Sh STANDARDS
640 There is no current POSIX standard for the tar command; it appeared
642 .St -p1003.1-96
643 but was dropped from
644 .St -p1003.1-2001 .
645 The options used by this implementation were developed by surveying a
646 number of existing tar implementations as well as the old POSIX specification
647 for tar and the current POSIX specification for pax.
649 The ustar and pax interchange file formats are defined by
650 .St -p1003.1-2001
651 for the pax command.
652 .Sh HISTORY
654 .Nm tar
655 command appeared in Seventh Edition Unix, which was released in January, 1979.
656 There have been numerous other implementations,
657 many of which extended the file format.
658 John Gilmore's
659 .Nm pdtar
660 public-domain implementation (circa November, 1987)
661 was quite influential, and formed the basis of GNU tar.
662 GNU tar was included as the standard system tar
665 beginning with
666 .Fx 1.0 .
668 This is a complete re-implementation based on the
669 .Xr libarchive 3
670 library.
671 .Sh BUGS
672 This program follows
673 .St -p1003.1-96
674 for the definition of the
675 .Fl l
676 option.
677 Note that GNU tar prior to version 1.15 treated
678 .Fl l
679 as a synonym for the
680 .Fl -one-file-system
681 option.
684 .Fl C Pa dir
685 option may differ from historic implementations.
687 All archive output is written in correctly-sized blocks, even
688 if the output is being compressed.
689 Whether or not the last output block is padded to a full
690 block size varies depending on the format and the
691 output device.
692 For tar and cpio formats, the last block of output is padded
693 to a full block size if the output is being
694 written to standard output or to a character or block device such as
695 a tape drive.
696 If the output is being written to a regular file, the last block
697 will not be padded.
698 Many compressors, including
699 .Xr gzip 1
701 .Xr bzip2 1 ,
702 complain about the null padding when decompressing an archive created by
703 .Nm ,
704 although they still extract it correctly.
706 The compression and decompression is implemented internally, so
707 there may be insignificant differences between the compressed output
708 generated by
709 .Dl Nm Fl czf Pa - file
710 and that generated by
711 .Dl Nm Fl cf Pa - file | Nm gzip
713 The default should be to read and write archives to the standard I/O paths,
714 but tradition (and POSIX) dictates otherwise.
717 .Cm r
719 .Cm u
720 modes require that the archive be uncompressed
721 and located in a regular file on disk.
722 Other archives can be modified using
723 .Cm c
724 mode with the
725 .Pa @archive-file
726 extension.
728 To archive a file called
729 .Pa @foo
731 .Pa -foo
732 you must specify it as
733 .Pa ./@foo
735 .Pa ./-foo ,
736 respectively.
738 In create mode, a leading
739 .Pa ./
740 is always removed.
741 A leading
742 .Pa /
743 is stripped unless the
744 .Fl P
745 option is specified.
747 There needs to be better support for file selection on both create
748 and extract.
750 There is not yet any support for multi-volume archives or for archiving
751 sparse files.
753 Converting between dissimilar archive formats (such as tar and cpio) using the
754 .Cm @ Ns Pa -
755 convention can cause hard link information to be lost.
756 (This is a consequence of the incompatible ways that different archive
757 formats store hardlink information.)
759 There are alternative long options for many of the short options that
760 are deliberately not documented.