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