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