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