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 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 file flags. This is the reverse of
223 and the default behavior in c, r, and u modes or if
225 is run in x mode as root.
226 .It Fl Fl format Ar format
228 Use the specified format for the created archive.
229 Supported formats include
235 Other formats may also be supported; see
236 .Xr libarchive-formats 5
237 for more information about currently-supported formats.
238 In r and u modes, when extending an existing archive, the format specified
239 here must be compatible with the format of the existing archive on disk.
240 .It Fl f Ar file , Fl Fl file Ar file
241 Read the archive from or write the archive to the specified file.
244 for standard input or standard output.
245 The default varies by system;
250 on Linux, the default is
253 Use the provided group id number.
254 On extract, this overrides the group id in the archive;
255 the group name in the archive will be ignored.
256 On create, this overrides the group id read from disk;
259 is not also specified, the group name will be set to
261 .It Fl Fl gname Ar name
262 Use the provided group name.
263 On extract, this overrides the group name in the archive;
264 if the provided group name does not exist on the system,
266 (from the archive or from the
269 will be used instead.
270 On create, this sets the group name that will be stored
272 the name will not be verified against the system group database.
275 Symbolic links named on the command line will be followed; the
276 target of the link will be archived, not the link itself.
286 .It Fl Fl hfsCompression
288 Mac OS X specific (v10.6 or later). Compress extracted regular files with HFS+
290 .It Fl Fl ignore-zeros
292 .Fl Fl options Cm read_concatenated_archives
293 for compatibility with GNU tar.
294 .It Fl Fl include Ar pattern
295 Process only files or directories that match the specified pattern.
296 Note that exclusions specified with
298 take precedence over inclusions.
299 If no inclusions are explicitly specified, all entries are processed by
303 option is especially useful when filtering archives.
304 For example, the command
305 .Dl Nm Fl c Fl f Pa new.tar Fl Fl include='*foo*' Cm @ Ns Pa old.tgz
306 creates a new archive
308 containing only the entries from
310 containing the string
314 Compress the resulting archive with
316 In extract or list modes, this option is ignored.
319 implementation recognizes XZ compression automatically when reading archives.
320 .It Fl j , Fl Fl bzip , Fl Fl bzip2 , Fl Fl bunzip2
322 Compress the resulting archive with
324 In extract or list modes, this option is ignored.
327 implementation recognizes bzip2 compression automatically when reading
329 .It Fl k , Fl Fl keep-old-files
331 Do not overwrite existing files.
332 In particular, if a file appears more than once in an archive,
333 later copies will not overwrite earlier copies.
334 .It Fl Fl keep-newer-files
336 Do not overwrite existing files that are newer than the
337 versions appearing in the archive being extracted.
338 .It Fl L , Fl Fl dereference
340 All symbolic links will be followed.
341 Normally, symbolic links are archived as such.
342 With this option, the target of the link will be archived instead.
343 .It Fl l , Fl Fl check-links
345 Issue a warning message unless all links to each file are archived.
348 Compress the resulting archive with
350 In extract or list modes, this option is ignored.
353 implementation recognizes lrzip compression automatically when reading
357 Compress the archive with lz4-compatible compression before writing it.
358 In extract or list modes, this option is ignored.
361 implementation recognizes lz4 compression automatically when reading archives.
364 Compress the archive with zstd-compatible compression before writing it.
365 In extract or list modes, this option is ignored.
368 implementation recognizes zstd compression automatically when reading archives.
370 (c mode only) Compress the resulting archive with the original LZMA algorithm.
371 In extract or list modes, this option is ignored.
372 Use of this option is discouraged and new archives should be created with
377 implementation recognizes LZMA compression automatically when reading archives.
380 Compress the resulting archive with
382 In extract or list modes, this option is ignored.
385 implementation recognizes LZO compression automatically when reading archives.
386 .It Fl m , Fl Fl modification-time
388 Do not extract modification time.
389 By default, the modification time is set to the time stored in the archive.
390 .It Fl Fl mac-metadata
391 (c, r, u and x mode only)
392 Mac OS X specific. Archive or extract extended ACLs and extended attributes
395 in AppleDouble format. This is the reverse of
396 .Fl Fl no-mac-metadata .
397 and the default behavior in c, r, and u modes or if
399 is run in x mode as root.
400 .It Fl n , Fl Fl norecurse , Fl Fl no-recursion
401 Do not operate recursively on the content of directories.
402 .It Fl Fl newer Ar date
404 Only include files and directories newer than the specified date.
405 This compares ctime entries.
406 .It Fl Fl newer-mtime Ar date
410 except it compares mtime entries instead of ctime entries.
411 .It Fl Fl newer-than Pa file
413 Only include files and directories newer than the specified file.
414 This compares ctime entries.
415 .It Fl Fl newer-mtime-than Pa file
419 except it compares mtime entries instead of ctime entries.
422 Honor the nodump file flag by skipping this file.
423 .It Fl Fl nopreserveHFSCompression
425 Mac OS X specific (v10.6 or later). Do not compress extracted regular files
426 which were compressed with HFS+ compression before archived.
427 By default, compress the regular files again with HFS+ compression.
433 Filenames or patterns are separated by null characters,
435 This is often used to read filenames output by the
440 (c, r, u, x modes only)
441 Do not archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of
443 and the default behavior if
445 is run as non-root in x mode (on Mac OS X as any user in c, r, u and x modes).
447 (c, r, u, x modes only)
448 Do not archive or extract file flags. This is the reverse of
450 and the default behavior if
452 is run as non-root in x mode.
453 .It Fl Fl no-mac-metadata
455 Mac OS X specific. Do not archive or extract ACLs and extended attributes using
457 in AppleDouble format. This is the reverse of
458 .Fl Fl mac-metadata .
459 and the default behavior if
461 is run as non-root in x mode.
462 .It Fl n , Fl Fl norecurse , Fl Fl no-recursion
463 .It Fl Fl no-same-owner
465 Do not extract owner and group IDs.
466 This is the reverse of
468 and the default behavior if
471 .It Fl Fl no-same-permissions
473 Do not extract full permissions (SGID, SUID, sticky bit, ACLs,
474 extended attributes or extended file flags).
475 This is the reverse of
477 and the default behavior if
481 (c, r, u, x modes only)
482 Do not archive or extract extended attributes. This is the reverse of
484 and the default behavior if
486 is run as non-root in x mode.
487 .It Fl Fl numeric-owner
488 This is equivalent to
493 On extract, it causes user and group names in the archive
494 to be ignored in favor of the numeric user and group ids.
495 On create, it causes user and group names to not be stored
497 .It Fl O , Fl Fl to-stdout
499 In extract (-x) mode, files will be written to standard out rather than
500 being extracted to disk.
501 In list (-t) mode, the file listing will be written to stderr rather than
505 Use the user and group of the user running the program rather
506 than those specified in the archive.
507 Note that this has no significance unless
509 is specified, and the program is being run by the root user.
510 In this case, the file modes and flags from
511 the archive will be restored, but ACLs or owner information in
512 the archive will be discarded.
516 .Fl Fl format Ar ustar
517 .It Fl Fl older Ar date
519 Only include files and directories older than the specified date.
520 This compares ctime entries.
521 .It Fl Fl older-mtime Ar date
525 except it compares mtime entries instead of ctime entries.
526 .It Fl Fl older-than Pa file
528 Only include files and directories older than the specified file.
529 This compares ctime entries.
530 .It Fl Fl older-mtime-than Pa file
534 except it compares mtime entries instead of ctime entries.
535 .It Fl Fl one-file-system
537 Do not cross mount points.
538 .It Fl Fl options Ar options
539 Select optional behaviors for particular modules.
540 The argument is a text string containing comma-separated
542 These are passed to the modules that handle particular
543 formats to control how those formats will behave.
544 Each option has one of the following forms:
545 .Bl -tag -compact -width indent
547 The key will be set to the specified value in every module that supports it.
548 Modules that do not support this key will ignore it.
550 The key will be enabled in every module that supports it.
551 This is equivalent to
554 The key will be disabled in every module that supports it.
555 .It Ar module:key=value , Ar module:key , Ar module:!key
556 As above, but the corresponding key and value will be provided
557 only to modules whose name matches
560 The currently supported modules and keys are:
561 .Bl -tag -compact -width indent
562 .It Cm iso9660:joliet
563 Support Joliet extensions.
564 This is enabled by default, use
569 .It Cm iso9660:rockridge
570 Support Rock Ridge extensions.
571 This is enabled by default, use
574 .Cm iso9660:!rockridge
576 .It Cm gzip:compression-level
577 A decimal integer from 1 to 9 specifying the gzip compression level.
578 .It Cm gzip:timestamp
579 Store timestamp. This is enabled by default, use
584 .It Cm lrzip:compression Ns = Ns Ar type
587 as compression method.
588 Supported values are bzip2, gzip, lzo (ultra fast),
589 and zpaq (best, extremely slow).
590 .It Cm lrzip:compression-level
591 A decimal integer from 1 to 9 specifying the lrzip compression level.
592 .It Cm lz4:compression-level
593 A decimal integer from 1 to 9 specifying the lzop compression level.
594 .It Cm lz4:stream-checksum
595 Enable stream checksum. This is by default, use
596 .Cm lz4:!stream-checksum
598 .It Cm lz4:block-checksum
599 Enable block checksum (Disabled by default).
600 .It Cm lz4:block-size
601 A decimal integer from 4 to 7 specifying the lz4 compression block size
602 (7 is set by default).
603 .It Cm lz4:block-dependence
604 Use the previous block of the block being compressed for
605 a compression dictionary to improve compression ratio.
606 .It Cm zstd:compression-level
607 A decimal integer from 1 to 22 specifying the zstd compression level.
608 .It Cm lzop:compression-level
609 A decimal integer from 1 to 9 specifying the lzop compression level.
610 .It Cm xz:compression-level
611 A decimal integer from 0 to 9 specifying the xz compression level.
612 .It Cm mtree: Ns Ar keyword
613 The mtree writer module allows you to specify which mtree keywords
614 will be included in the output.
615 Supported keywords include:
616 .Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent ,
617 .Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 ,
618 .Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname .
619 The default is equivalent to:
620 .Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname .
622 Enables all of the above keywords.
625 to disable all keywords.
631 Produce human-readable output by indenting options and splitting lines
632 to fit into 80 columns.
633 .It Cm zip:compression Ns = Ns Ar type
636 as compression method.
637 Supported values are store (uncompressed) and deflate (gzip algorithm).
638 .It Cm zip:encryption
639 Enable encryption using traditional zip encryption.
640 .It Cm zip:encryption Ns = Ns Ar type
644 Supported values are zipcrypt (traditional zip encryption),
645 aes128 (WinZip AES-128 encryption) and aes256 (WinZip AES-256 encryption).
646 .It Cm read_concatenated_archives
647 Ignore zeroed blocks in the archive, which occurs when multiple tar archives
648 have been concatenated together. Without this option, only the contents of
649 the first concatenated archive would be read. This option is comparable to
651 .Fl i , Fl Fl ignore-zeros
654 If a provided option is not supported by any module, that
656 .It Fl P , Fl Fl absolute-paths
658 By default, absolute pathnames (those that begin with a /
659 character) have the leading slash removed both when creating archives
660 and extracting from them.
663 will refuse to extract archive entries whose pathnames contain
665 or whose target directory would be altered by a symlink.
666 This option suppresses these behaviors.
667 .It Fl p , Fl Fl insecure , Fl Fl preserve-permissions
669 Preserve file permissions.
670 Attempt to restore the full permissions, including owner, file modes, ACLs,
671 extended attributes and extended file flags, if available, for each item
672 extracted from the archive. This is te reverse of
673 .Fl Fl no-same-permissions
676 is being run by root and can be partially overridden by also specifying
679 .Fl Fl no-mac-metadata
682 .It Fl Fl passphrase Ar passphrase
685 is used to extract or create an encrypted archive.
686 Currently, zip is the only supported format that supports encryption.
687 You shouldn't use this option unless you realize how insecure
688 use of this option is.
693 .It Fl q , Fl Fl fast-read
695 Extract or list only the first archive entry that matches each pattern
697 Exit as soon as each specified pattern or filename has been matched.
698 By default, the archive is always read to the very end, since
699 there can be multiple entries with the same name and, by convention,
700 later entries overwrite earlier entries.
701 This option is provided as a performance optimization.
704 Extract files as sparse files.
705 For every block on disk, check first if it contains only NULL bytes and seek
707 This works similar to the conv=sparse option of dd.
709 Modify file or archive member names according to
711 The pattern has the format
712 .Ar /old/new/ Ns Op ghHprRsS
715 is a basic regular expression,
717 is the replacement string of the matched part,
718 and the optional trailing letters modify
719 how the replacement is handled.
722 is not matched, the pattern is skipped.
725 ~ is substituted with the match, \e1 to \e9 with the content of
726 the corresponding captured group.
727 The optional trailing g specifies that matching should continue
728 after the matched part and stop on the first unmatched pattern.
729 The optional trailing s specifies that the pattern applies to the value
731 The optional trailing p specifies that after a successful substitution
732 the original path name and the new path name should be printed to
734 Optional trailing H, R, or S characters suppress substitutions
735 for hardlink targets, regular filenames, or symlink targets,
737 Optional trailing h, r, or s characters enable substitutions
738 for hardlink targets, regular filenames, or symlink targets,
742 which applies substitutions to all names.
743 In particular, it is never necessary to specify h, r, or s.
746 Extract owner and group IDs.
747 This is the reverse of
749 and the default behavior if
752 .It Fl Fl strip-components Ar count
753 Remove the specified number of leading path elements.
754 Pathnames with fewer elements will be silently skipped.
755 Note that the pathname is edited after checking inclusion/exclusion patterns
756 but before security checks.
757 .It Fl T Ar filename , Fl Fl files-from Ar filename
760 will read the list of names to be extracted from
764 will read names to be archived from
768 on a line by itself will cause the current directory to be changed to
769 the directory specified on the following line.
770 Names are terminated by newlines unless
775 also disables the special handling of lines containing
777 Note: If you are generating lists of files using
779 you probably want to use
784 After archiving all files, print a summary to stderr.
785 .It Fl U , Fl Fl unlink , Fl Fl unlink-first
787 Unlink files before creating them.
788 This can be a minor performance optimization if most files
789 already exist, but can make things slower if most files
790 do not already exist.
791 This flag also causes
793 to remove intervening directory symlinks instead of
795 See the SECURITY section below for more details.
797 Use the provided user id number and ignore the user
798 name from the archive.
801 is not also specified, the user name will be set to
803 .It Fl Fl uname Ar name
804 Use the provided user name.
805 On extract, this overrides the user name in the archive;
806 if the provided user name does not exist on the system,
807 it will be ignored and the user id
808 (from the archive or from the
811 will be used instead.
812 On create, this sets the user name that will be stored
814 the name is not verified against the system user database.
815 .It Fl Fl use-compress-program Ar program
816 Pipe the input (in x or t mode) or the output (in c mode) through
818 instead of using the builtin compression support.
819 .It Fl v , Fl Fl verbose
820 Produce verbose output.
821 In create and extract modes,
823 will list each file name as it is read from or written to
827 will produce output similar to that of
831 option will also provide ls-like details in create and extract mode.
838 .It Fl w , Fl Fl confirmation , Fl Fl interactive
839 Ask for confirmation for every action.
840 .It Fl X Ar filename , Fl Fl exclude-from Ar filename
841 Read a list of exclusion patterns from the specified file.
844 for more information about the handling of exclusions.
846 (c, r, u, x modes only)
847 Archive or extract extended attributes. This is the reverse of
849 and the default behavior in c, r, and u modes or if
851 is run in x mode as root.
854 Compress the resulting archive with
856 In extract or list modes, this option is ignored.
859 implementation recognizes bzip2 compression automatically when reading
861 .It Fl Z , Fl Fl compress , Fl Fl uncompress
863 Compress the resulting archive with
865 In extract or list modes, this option is ignored.
868 implementation recognizes compress compression automatically when reading
870 .It Fl z , Fl Fl gunzip , Fl Fl gzip
872 Compress the resulting archive with
874 In extract or list modes, this option is ignored.
877 implementation recognizes gzip compression automatically when reading
881 The following environment variables affect the execution of
883 .Bl -tag -width ".Ev BLOCKSIZE"
884 .It Ev TAR_READER_OPTIONS
885 The default options for format readers and compression readers.
888 option overrides this.
889 .It Ev TAR_WRITER_OPTIONS
890 The default options for format writers and compression writers.
893 option overrides this.
898 for more information.
903 option overrides this.
904 Please see the description of the
906 option above for more details.
908 The timezone to use when displaying dates.
911 for more information.
916 The following creates a new archive
919 that contains two files
923 .Dl Nm Fl czf Pa file.tar.gz Pa source.c Pa source.h
925 To view a detailed table of contents for this
927 .Dl Nm Fl tvf Pa file.tar.gz
929 To extract all entries from the archive on
930 the default tape drive:
933 To examine the contents of an ISO 9660 cdrom image:
934 .Dl Nm Fl tf Pa image.iso
936 To move file hierarchies, invoke
939 .Dl Nm Fl cf Pa - Fl C Pa srcdir\ . | Nm Fl xpf Pa - Fl C Pa destdir
940 or more traditionally
941 .Dl cd srcdir \&; Nm Fl cf Pa -\ . | ( cd destdir \&; Nm Fl xpf Pa - )
943 In create mode, the list of files and directories to be archived
944 can also include directory change instructions of the form
946 and archive inclusions of the form
947 .Cm @ Ns Pa archive-file .
948 For example, the command line
949 .Dl Nm Fl c Fl f Pa new.tar Pa foo1 Cm @ Ns Pa old.tgz Cm -C Ns Pa /tmp Pa foo2
950 will create a new archive
955 from the current directory and add it to the output archive.
956 It will then read each entry from
958 and add those entries to the output archive.
959 Finally, it will switch to the
963 to the output archive.
967 format can be used to create an output archive with arbitrary ownership,
968 permissions, or names that differ from existing data on disk:
970 .Bd -literal -offset indent
973 usr/bin uid=0 gid=0 mode=0755 type=dir
974 usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls
975 $ tar -cvf output.tar @input.mtree
982 switches accept a variety of common date and time specifications, including
983 .Dq 12 Mar 2005 7:14:29pm ,
984 .Dq 2005-03-12 19:14 ,
987 .Dq 19:14 PST May 1 .
991 argument can be used to control various details of archive generation
993 For example, you can generate mtree output which only contains
998 .Dl Nm Fl cf Pa file.tar Fl Fl format=mtree Fl Fl options='!all,type,time,uid' Pa dir
999 or you can set the compression level used by gzip or xz compression:
1000 .Dl Nm Fl czf Pa file.tar Fl Fl options='compression-level=9' .
1001 For more details, see the explanation of the
1002 .Fn archive_read_set_options
1004 .Fn archive_write_set_options
1005 API calls that are described in
1008 .Xr archive_write 3 .
1010 The bundled-arguments format is supported for compatibility
1011 with historic implementations.
1012 It consists of an initial word (with no leading - character) in which
1013 each character indicates an option.
1014 Arguments follow as separate words.
1015 The order of the arguments must match the order
1016 of the corresponding characters in the bundled command word.
1018 .Dl Nm Cm tbf 32 Pa file.tar
1019 specifies three flags
1028 flags both require arguments,
1029 so there must be two additional items
1030 on the command line.
1033 is the argument to the
1037 is the argument to the
1041 The mode options c, r, t, u, and x and the options
1042 b, f, l, m, o, v, and w comply with SUSv2.
1044 For maximum portability, scripts that invoke
1046 should use the bundled-argument format above, should limit
1061 Additional long options are provided to improve compatibility with other
1062 tar implementations.
1064 Certain security issues are common to many archiving programs, including
1066 In particular, carefully-crafted archives can request that
1068 extract files to locations outside of the target directory.
1069 This can potentially be used to cause unwitting users to overwrite
1070 files they did not intend to overwrite.
1071 If the archive is being extracted by the superuser, any file
1072 on the system can potentially be overwritten.
1073 There are three ways this can happen.
1076 has mechanisms to protect against each one,
1077 savvy users should be aware of the implications:
1078 .Bl -bullet -width indent
1080 Archive entries can have absolute pathnames.
1085 character from filenames before restoring them to guard against this problem.
1087 Archive entries can have pathnames that include
1092 will not extract files containing
1094 components in their pathname.
1096 Archive entries can exploit symbolic links to restore
1097 files to other directories.
1098 An archive can restore a symbolic link to another directory,
1099 then use that link to restore a file into that directory.
1100 To guard against this,
1102 checks each extracted path for symlinks.
1103 If the final path element is a symlink, it will be removed
1104 and replaced with the archive entry.
1107 is specified, any intermediate symlink will also be unconditionally removed.
1114 will refuse to extract the entry.
1116 To protect yourself, you should be wary of any archives that
1117 come from untrusted sources.
1118 You should examine the contents of an archive with
1119 .Dl Nm Fl tf Pa filename
1123 option to ensure that
1125 will not overwrite any existing files or the
1127 option to remove any pre-existing files.
1128 You should generally not extract archives while running with super-user
1134 disables the security checks above and allows you to extract
1135 an archive while preserving any absolute pathnames,
1137 components, or symlinks to other directories.
1148 .Xr libarchive-formats 5 ,
1151 There is no current POSIX standard for the tar command; it appeared
1154 but was dropped from
1156 The options supported by this implementation were developed by surveying a
1157 number of existing tar implementations as well as the old POSIX specification
1158 for tar and the current POSIX specification for pax.
1160 The ustar and pax interchange file formats are defined by
1162 for the pax command.
1166 command appeared in Seventh Edition Unix, which was released in January, 1979.
1167 There have been numerous other implementations,
1168 many of which extended the file format.
1171 public-domain implementation (circa November, 1987)
1172 was quite influential, and formed the basis of GNU tar.
1173 GNU tar was included as the standard system tar
1179 This is a complete re-implementation based on the
1182 It was first released with
1186 This program follows
1188 for the definition of the
1191 Note that GNU tar prior to version 1.15 treated
1193 as a synonym for the
1194 .Fl Fl one-file-system
1199 option may differ from historic implementations.
1201 All archive output is written in correctly-sized blocks, even
1202 if the output is being compressed.
1203 Whether or not the last output block is padded to a full
1204 block size varies depending on the format and the
1206 For tar and cpio formats, the last block of output is padded
1207 to a full block size if the output is being
1208 written to standard output or to a character or block device such as
1210 If the output is being written to a regular file, the last block
1212 Many compressors, including
1216 complain about the null padding when decompressing an archive created by
1218 although they still extract it correctly.
1220 The compression and decompression is implemented internally, so
1221 there may be insignificant differences between the compressed output
1223 .Dl Nm Fl czf Pa - file
1224 and that generated by
1225 .Dl Nm Fl cf Pa - file | Nm gzip
1227 The default should be to read and write archives to the standard I/O paths,
1228 but tradition (and POSIX) dictates otherwise.
1234 modes require that the archive be uncompressed
1235 and located in a regular file on disk.
1236 Other archives can be modified using
1242 To archive a file called
1246 you must specify it as
1252 In create mode, a leading
1257 is stripped unless the
1259 option is specified.
1261 There needs to be better support for file selection on both create
1264 There is not yet any support for multi-volume archives.
1266 Converting between dissimilar archive formats (such as tar and cpio) using the
1268 convention can cause hard link information to be lost.
1269 (This is a consequence of the incompatible ways that different archive
1270 formats store hardlink information.)