1 .\" Copyright (c) 2003-2007 Tim Kientzle
2 .\" Copyright (c) 2017 Martin Matuska
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
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.
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
33 .Nd manipulate tape archives
36 .Op Ar bundled-flags Ao args Ac
37 .Op Ao Ar file Ac | Ao Ar pattern Ac ...
41 .Op Ar files | Ar directories
46 .Op Ar files | Ar directories
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.
58 The first synopsis form shows a
61 This usage is provided for compatibility with historical implementations.
62 See COMPATIBILITY below for details.
64 The other synopsis forms show the preferred usage.
67 is a mode indicator from the following list:
68 .Bl -tag -compact -width indent
70 Create a new archive containing the specified items.
71 The long option form is
76 but new entries are appended to the archive.
77 Note that this only works on uncompressed archives stored in regular files.
81 The long option form is
84 List archive contents to stdout.
85 The long option form is
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.
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)
103 The long option form is
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.
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
124 Unless specifically stated otherwise, options are applicable in
126 .Bl -tag -width indent
127 .It Cm @ Ns Pa archive
129 The specified archive is opened and the entries
130 in it will be appended to the current archive.
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
135 and all of the entries from
138 .Dl Nm Fl c Fl f Pa - Pa newfile Pa original.tar
139 creates a new archive with only two entries.
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.
147 can be used to convert archives from one format to another.
148 .It Fl a , Fl Fl auto-compress
150 Use the archive suffix to decide a set of the format and
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
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.
169 (c, r, u, x modes only)
170 Archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of
172 and the default behavior in c, r, and u modes (except on Mac OS X) or if
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
178 .It Fl B , Fl Fl read-full-blocks
179 Ignored for compatibility with other
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
190 In x mode, change directories after opening the archive
191 but before extracting entries from the archive.
195 to the current directory after processing any
197 options and before extracting any files.
198 .It Fl Fl clear-nochange-fflags
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
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
220 (c, r, u, x modes only)
221 Archive or extract platform-specific file attributes or file flags.
222 This is the reverse of
224 and the default behavior in c, r, and u modes or if
226 is run in x mode as root.
227 .It Fl Fl format Ar format
229 Use the specified format for the created archive.
230 Supported formats include
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.
245 for standard input or standard output.
246 The default varies by system;
251 on Linux, the default is
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;
260 is not also specified, the group name will be set to
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,
267 (from the archive or from the
270 will be used instead.
271 On create, this sets the group name that will be stored
273 the name will not be verified against the system group database.
276 Symbolic links named on the command line will be followed; the
277 target of the link will be archived, not the link itself.
287 .It Fl Fl hfsCompression
289 Mac OS X specific (v10.6 or later). Compress extracted regular files with HFS+
291 .It Fl Fl ignore-zeros
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
299 take precedence over inclusions.
300 If no inclusions are explicitly specified, all entries are processed by
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
309 containing only the entries from
311 containing the string
315 Compress the resulting archive with
317 In extract or list modes, this option is ignored.
320 implementation recognizes XZ compression automatically when reading archives.
321 .It Fl j , Fl Fl bzip , Fl Fl bzip2 , Fl Fl bunzip2
323 Compress the resulting archive with
325 In extract or list modes, this option is ignored.
328 implementation recognizes bzip2 compression automatically when reading
330 .It Fl k , Fl Fl keep-old-files
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
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
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
346 Issue a warning message unless all links to each file are archived.
349 Compress the resulting archive with
351 In extract or list modes, this option is ignored.
354 implementation recognizes lrzip compression automatically when reading
358 Compress the archive with lz4-compatible compression before writing it.
359 In extract or list modes, this option is ignored.
362 implementation recognizes lz4 compression automatically when reading archives.
365 Compress the archive with zstd-compatible compression before writing it.
366 In extract or list modes, this option is ignored.
369 implementation recognizes zstd compression automatically when reading archives.
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
378 implementation recognizes LZMA compression automatically when reading archives.
381 Compress the resulting archive with
383 In extract or list modes, this option is ignored.
386 implementation recognizes LZO compression automatically when reading archives.
387 .It Fl m , Fl Fl modification-time
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
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
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
405 Only include files and directories newer than the specified date.
406 This compares ctime entries.
407 .It Fl Fl newer-mtime Ar date
411 except it compares mtime entries instead of ctime entries.
412 .It Fl Fl newer-than Pa file
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
420 except it compares mtime entries instead of ctime entries.
423 Honor the nodump file flag by skipping this file.
424 .It Fl Fl nopreserveHFSCompression
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.
434 Filenames or patterns are separated by null characters,
436 This is often used to read filenames output by the
441 (c, r, u, x modes only)
442 Do not archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of
444 and the default behavior if
446 is run as non-root in x mode (on Mac OS X as any user in c, r, u and x modes).
448 (c, r, u, x modes only)
449 Do not archive or extract file attributes or file flags. This is the reverse of
451 and the default behavior if
453 is run as non-root in x mode.
454 .It Fl Fl no-mac-metadata
456 Mac OS X specific. Do not archive or extract ACLs and extended file attributes
459 in AppleDouble format. This is the reverse of
460 .Fl Fl mac-metadata .
461 and the default behavior if
463 is run as non-root in x mode.
464 .It Fl Fl no-same-owner
466 Do not extract owner and group IDs.
467 This is the reverse of
469 and the default behavior if
472 .It Fl Fl no-same-permissions
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
478 and the default behavior if
482 (c, r, u, x modes only)
483 Do not archive or extract extended file attributes. This is the reverse of
485 and the default behavior if
487 is run as non-root in x mode.
488 .It Fl Fl numeric-owner
489 This is equivalent to
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
498 .It Fl O , Fl Fl to-stdout
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
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
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.
517 .Fl Fl format Ar ustar
518 .It Fl Fl older Ar date
520 Only include files and directories older than the specified date.
521 This compares ctime entries.
522 .It Fl Fl older-mtime Ar date
526 except it compares mtime entries instead of ctime entries.
527 .It Fl Fl older-than Pa file
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
535 except it compares mtime entries instead of ctime entries.
536 .It Fl Fl one-file-system
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
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
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.
551 The key will be enabled in every module that supports it.
552 This is equivalent to
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
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
570 .It Cm iso9660:rockridge
571 Support Rock Ridge extensions.
572 This is enabled by default, use
575 .Cm iso9660:!rockridge
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
585 .It Cm lrzip:compression Ns = Ns 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
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 .
623 Enables all of the above keywords.
626 to disable all keywords.
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
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
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
652 .Fl i , Fl Fl ignore-zeros
655 If a provided option is not supported by any module, that
657 .It Fl P , Fl Fl absolute-paths
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.
664 will refuse to extract archive entries whose pathnames contain
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
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
677 is being run as root. It can be partially overridden by also specifying
680 .Fl Fl no-mac-metadata
683 .It Fl Fl passphrase Ar 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.
694 .It Fl q , Fl Fl fast-read
696 Extract or list only the first archive entry that matches each pattern
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.
705 Extract files as sparse files.
706 For every block on disk, check first if it contains only NULL bytes and seek
708 This works similar to the conv=sparse option of dd.
710 Modify file or archive member names according to
712 The pattern has the format
713 .Ar /old/new/ Ns Op ghHprRsS
716 is a basic regular expression,
718 is the replacement string of the matched part,
719 and the optional trailing letters modify
720 how the replacement is handled.
723 is not matched, the pattern is skipped.
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
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
735 Optional trailing H, R, or S characters suppress substitutions
736 for hardlink targets, regular filenames, or symlink targets,
738 Optional trailing h, r, or s characters enable substitutions
739 for hardlink targets, regular filenames, or symlink targets,
743 which applies substitutions to all names.
744 In particular, it is never necessary to specify h, r, or s.
747 Extract owner and group IDs.
748 This is the reverse of
750 and the default behavior if
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
761 will read the list of names to be extracted from
765 will read names to be archived from
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
776 also disables the special handling of lines containing
778 Note: If you are generating lists of files using
780 you probably want to use
785 After archiving all files, print a summary to stderr.
786 .It Fl U , Fl Fl unlink , Fl Fl unlink-first
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
794 to remove intervening directory symlinks instead of
796 See the SECURITY section below for more details.
798 Use the provided user id number and ignore the user
799 name from the archive.
802 is not also specified, the user name will be set to
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
812 will be used instead.
813 On create, this sets the user name that will be stored
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
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,
824 will list each file name as it is read from or written to
828 will produce output similar to that of
832 option will also provide ls-like details in create and extract mode.
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.
845 for more information about the handling of exclusions.
847 (c, r, u, x modes only)
848 Archive or extract extended file attributes. This is the reverse of
850 and the default behavior in c, r, and u modes or if
852 is run in x mode as root.
855 Compress the resulting archive with
857 In extract or list modes, this option is ignored.
860 implementation recognizes bzip2 compression automatically when reading
862 .It Fl Z , Fl Fl compress , Fl Fl uncompress
864 Compress the resulting archive with
866 In extract or list modes, this option is ignored.
869 implementation recognizes compress compression automatically when reading
871 .It Fl z , Fl Fl gunzip , Fl Fl gzip
873 Compress the resulting archive with
875 In extract or list modes, this option is ignored.
878 implementation recognizes gzip compression automatically when reading
882 The following environment variables affect the execution of
884 .Bl -tag -width ".Ev BLOCKSIZE"
885 .It Ev TAR_READER_OPTIONS
886 The default options for format readers and compression readers.
889 option overrides this.
890 .It Ev TAR_WRITER_OPTIONS
891 The default options for format writers and compression writers.
894 option overrides this.
899 for more information.
904 option overrides this.
905 Please see the description of the
907 option above for more details.
909 The timezone to use when displaying dates.
912 for more information.
917 The following creates a new archive
920 that contains two files
924 .Dl Nm Fl czf Pa file.tar.gz Pa source.c Pa source.h
926 To view a detailed table of contents for this
928 .Dl Nm Fl tvf Pa file.tar.gz
930 To extract all entries from the archive on
931 the default tape drive:
934 To examine the contents of an ISO 9660 cdrom image:
935 .Dl Nm Fl tf Pa image.iso
937 To move file hierarchies, invoke
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 - )
944 In create mode, the list of files and directories to be archived
945 can also include directory change instructions of the form
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
956 from the current directory and add it to the output archive.
957 It will then read each entry from
959 and add those entries to the output archive.
960 Finally, it will switch to the
964 to the output archive.
968 format can be used to create an output archive with arbitrary ownership,
969 permissions, or names that differ from existing data on disk:
971 .Bd -literal -offset indent
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
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 ,
988 .Dq 19:14 PST May 1 .
992 argument can be used to control various details of archive generation
994 For example, you can generate mtree output which only contains
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
1005 .Fn archive_write_set_options
1006 API calls that are described in
1009 .Xr archive_write 3 .
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.
1019 .Dl Nm Cm tbf 32 Pa file.tar
1020 specifies three flags
1029 flags both require arguments,
1030 so there must be two additional items
1031 on the command line.
1034 is the argument to the
1038 is the argument to the
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.
1045 For maximum portability, scripts that invoke
1047 should use the bundled-argument format above, should limit
1062 Additional long options are provided to improve compatibility with other
1063 tar implementations.
1065 Certain security issues are common to many archiving programs, including
1067 In particular, carefully-crafted archives can request that
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.
1077 has mechanisms to protect against each one,
1078 savvy users should be aware of the implications:
1079 .Bl -bullet -width indent
1081 Archive entries can have absolute pathnames.
1086 character from filenames before restoring them to guard against this problem.
1088 Archive entries can have pathnames that include
1093 will not extract files containing
1095 components in their pathname.
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,
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.
1108 is specified, any intermediate symlink will also be unconditionally removed.
1115 will refuse to extract the entry.
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
1124 option to ensure that
1126 will not overwrite any existing files or the
1128 option to remove any pre-existing files.
1129 You should generally not extract archives while running with super-user
1135 disables the security checks above and allows you to extract
1136 an archive while preserving any absolute pathnames,
1138 components, or symlinks to other directories.
1149 .Xr libarchive-formats 5 ,
1152 There is no current POSIX standard for the tar command; it appeared
1155 but was dropped from
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.
1161 The ustar and pax interchange file formats are defined by
1163 for the pax command.
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.
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
1180 This is a complete re-implementation based on the
1183 It was first released with
1187 This program follows
1189 for the definition of the
1192 Note that GNU tar prior to version 1.15 treated
1194 as a synonym for the
1195 .Fl Fl one-file-system
1200 option may differ from historic implementations.
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
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
1211 If the output is being written to a regular file, the last block
1213 Many compressors, including
1217 complain about the null padding when decompressing an archive created by
1219 although they still extract it correctly.
1221 The compression and decompression is implemented internally, so
1222 there may be insignificant differences between the compressed output
1224 .Dl Nm Fl czf Pa - file
1225 and that generated by
1226 .Dl Nm Fl cf Pa - file | Nm gzip
1228 The default should be to read and write archives to the standard I/O paths,
1229 but tradition (and POSIX) dictates otherwise.
1235 modes require that the archive be uncompressed
1236 and located in a regular file on disk.
1237 Other archives can be modified using
1243 To archive a file called
1247 you must specify it as
1253 In create mode, a leading
1258 is stripped unless the
1260 option is specified.
1262 There needs to be better support for file selection on both create
1265 There is not yet any support for multi-volume archives.
1267 Converting between dissimilar archive formats (such as tar and cpio) using the
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.)