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