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