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.
171 This is the reverse of
173 and the default behavior in c, r, and u modes (except on Mac OS X) or if
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
180 .It Fl B , Fl Fl read-full-blocks
181 Ignored for compatibility with other
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
192 In x mode, change directories after opening the archive
193 but before extracting entries from the archive.
197 to the current directory after processing any
199 options and before extracting any files.
200 .It Fl Fl clear-nochange-fflags
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
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
222 (c, r, u, x modes only)
223 Archive or extract platform-specific file attributes or file flags.
224 This is the reverse of
226 and the default behavior in c, r, and u modes or if
228 is run in x mode as root.
229 .It Fl Fl format Ar format
231 Use the specified format for the created archive.
232 Supported formats include
238 Other formats may also be supported; see
239 .Xr libarchive-formats 5
240 for more information about currently-supported formats.
241 In r and u modes, when extending an existing archive, the format specified
242 here must be compatible with the format of the existing archive on disk.
243 .It Fl f Ar file , Fl Fl file Ar file
244 Read the archive from or write the archive to the specified file.
247 for standard input or standard output.
248 The default varies by system;
253 on Linux, the default is
256 Use the provided group id number.
257 On extract, this overrides the group id in the archive;
258 the group name in the archive will be ignored.
259 On create, this overrides the group id read from disk;
262 is not also specified, the group name will be set to
264 .It Fl Fl gname Ar name
265 Use the provided group name.
266 On extract, this overrides the group name in the archive;
267 if the provided group name does not exist on the system,
269 (from the archive or from the
272 will be used instead.
273 On create, this sets the group name that will be stored
275 the name will not be verified against the system group database.
278 Symbolic links named on the command line will be followed; the
279 target of the link will be archived, not the link itself.
289 .It Fl Fl hfsCompression
291 Mac OS X specific (v10.6 or later). Compress extracted regular files with HFS+
293 .It Fl Fl ignore-zeros
295 .Fl Fl options Cm read_concatenated_archives
296 for compatibility with GNU tar.
297 .It Fl Fl include Ar pattern
298 Process only files or directories that match the specified pattern.
299 Note that exclusions specified with
301 take precedence over inclusions.
302 If no inclusions are explicitly specified, all entries are processed by
306 option is especially useful when filtering archives.
307 For example, the command
308 .Dl Nm Fl c Fl f Pa new.tar Fl Fl include='*foo*' Cm @ Ns Pa old.tgz
309 creates a new archive
311 containing only the entries from
313 containing the string
317 Compress the resulting archive with
319 In extract or list modes, this option is ignored.
322 implementation recognizes XZ compression automatically when reading archives.
323 .It Fl j , Fl Fl bzip , Fl Fl bzip2 , Fl Fl bunzip2
325 Compress the resulting archive with
327 In extract or list modes, this option is ignored.
330 implementation recognizes bzip2 compression automatically when reading
332 .It Fl k , Fl Fl keep-old-files
334 Do not overwrite existing files.
335 In particular, if a file appears more than once in an archive,
336 later copies will not overwrite earlier copies.
337 .It Fl Fl keep-newer-files
339 Do not overwrite existing files that are newer than the
340 versions appearing in the archive being extracted.
341 .It Fl L , Fl Fl dereference
343 All symbolic links will be followed.
344 Normally, symbolic links are archived as such.
345 With this option, the target of the link will be archived instead.
346 .It Fl l , Fl Fl check-links
348 Issue a warning message unless all links to each file are archived.
351 Compress the resulting archive with
353 In extract or list modes, this option is ignored.
356 implementation recognizes lrzip compression automatically when reading
360 Compress the archive with lz4-compatible compression before writing it.
361 In extract or list modes, this option is ignored.
364 implementation recognizes lz4 compression automatically when reading archives.
367 Compress the archive with zstd-compatible compression before writing it.
368 In extract or list modes, this option is ignored.
371 implementation recognizes zstd compression automatically when reading archives.
373 (c mode only) Compress the resulting archive with the original LZMA algorithm.
374 In extract or list modes, this option is ignored.
375 Use of this option is discouraged and new archives should be created with
380 implementation recognizes LZMA compression automatically when reading archives.
383 Compress the resulting archive with
385 In extract or list modes, this option is ignored.
388 implementation recognizes LZO compression automatically when reading archives.
389 .It Fl m , Fl Fl modification-time
391 Do not extract modification time.
392 By default, the modification time is set to the time stored in the archive.
393 .It Fl Fl mac-metadata
394 (c, r, u and x mode only)
396 Archive or extract extended ACLs and extended file
399 in AppleDouble format.
400 This is the reverse of
401 .Fl Fl no-mac-metadata .
402 and the default behavior in c, r, and u modes or if
404 is run in x mode as root.
405 .It Fl n , Fl Fl norecurse , Fl Fl no-recursion
406 Do not operate recursively on the content of directories.
407 .It Fl Fl newer Ar date
409 Only include files and directories newer than the specified date.
410 This compares ctime entries.
411 .It Fl Fl newer-mtime Ar date
415 except it compares mtime entries instead of ctime entries.
416 .It Fl Fl newer-than Pa file
418 Only include files and directories newer than the specified file.
419 This compares ctime entries.
420 .It Fl Fl newer-mtime-than Pa file
424 except it compares mtime entries instead of ctime entries.
427 Honor the nodump file flag by skipping this file.
428 .It Fl Fl nopreserveHFSCompression
430 Mac OS X specific (v10.6 or later). Do not compress extracted regular files
431 which were compressed with HFS+ compression before archived.
432 By default, compress the regular files again with HFS+ compression.
438 Filenames or patterns are separated by null characters,
440 This is often used to read filenames output by the
445 (c, r, u, x modes only)
446 Do not archive or extract POSIX.1e or NFSv4 ACLs.
447 This is the reverse of
449 and the default behavior if
451 is run as non-root in x mode (on Mac OS X as any user in c, r, u and x modes).
453 (c, r, u, x modes only)
454 Do not archive or extract file attributes or file flags.
455 This is the reverse of
457 and the default behavior if
459 is run as non-root in x mode.
460 .It Fl Fl no-mac-metadata
463 Do not archive or extract ACLs and extended file attributes
466 in AppleDouble format.
467 This is the reverse of
468 .Fl Fl mac-metadata .
469 and the default behavior if
471 is run as non-root in x mode.
472 .It Fl Fl no-same-owner
474 Do not extract owner and group IDs.
475 This is the reverse of
477 and the default behavior if
480 .It Fl Fl no-same-permissions
482 Do not extract full permissions (SGID, SUID, sticky bit,
483 file attributes or file flags, extended file attributes and ACLs).
484 This is the reverse of
486 and the default behavior if
490 (c, r, u, x modes only)
491 Do not archive or extract extended file attributes.
492 This is the reverse of
494 and the default behavior if
496 is run as non-root in x mode.
497 .It Fl Fl numeric-owner
498 This is equivalent to
503 On extract, it causes user and group names in the archive
504 to be ignored in favor of the numeric user and group ids.
505 On create, it causes user and group names to not be stored
507 .It Fl O , Fl Fl to-stdout
509 In extract (-x) mode, files will be written to standard out rather than
510 being extracted to disk.
511 In list (-t) mode, the file listing will be written to stderr rather than
515 Use the user and group of the user running the program rather
516 than those specified in the archive.
517 Note that this has no significance unless
519 is specified, and the program is being run by the root user.
520 In this case, the file modes and flags from
521 the archive will be restored, but ACLs or owner information in
522 the archive will be discarded.
526 .Fl Fl format Ar ustar
527 .It Fl Fl older Ar date
529 Only include files and directories older than the specified date.
530 This compares ctime entries.
531 .It Fl Fl older-mtime Ar date
535 except it compares mtime entries instead of ctime entries.
536 .It Fl Fl older-than Pa file
538 Only include files and directories older than the specified file.
539 This compares ctime entries.
540 .It Fl Fl older-mtime-than Pa file
544 except it compares mtime entries instead of ctime entries.
545 .It Fl Fl one-file-system
547 Do not cross mount points.
548 .It Fl Fl options Ar options
549 Select optional behaviors for particular modules.
550 The argument is a text string containing comma-separated
552 These are passed to the modules that handle particular
553 formats to control how those formats will behave.
554 Each option has one of the following forms:
555 .Bl -tag -compact -width indent
557 The key will be set to the specified value in every module that supports it.
558 Modules that do not support this key will ignore it.
560 The key will be enabled in every module that supports it.
561 This is equivalent to
564 The key will be disabled in every module that supports it.
565 .It Ar module:key=value , Ar module:key , Ar module:!key
566 As above, but the corresponding key and value will be provided
567 only to modules whose name matches
570 The currently supported modules and keys are:
571 .Bl -tag -compact -width indent
572 .It Cm iso9660:joliet
573 Support Joliet extensions.
574 This is enabled by default, use
579 .It Cm iso9660:rockridge
580 Support Rock Ridge extensions.
581 This is enabled by default, use
584 .Cm iso9660:!rockridge
586 .It Cm gzip:compression-level
587 A decimal integer from 1 to 9 specifying the gzip compression level.
588 .It Cm gzip:timestamp
590 This is enabled by default, use
595 .It Cm lrzip:compression Ns = Ns Ar type
598 as compression method.
599 Supported values are bzip2, gzip, lzo (ultra fast),
600 and zpaq (best, extremely slow).
601 .It Cm lrzip:compression-level
602 A decimal integer from 1 to 9 specifying the lrzip compression level.
603 .It Cm lz4:compression-level
604 A decimal integer from 1 to 9 specifying the lzop compression level.
605 .It Cm lz4:stream-checksum
606 Enable stream checksum.
607 This is by default, use
608 .Cm lz4:!stream-checksum
610 .It Cm lz4:block-checksum
611 Enable block checksum (Disabled by default).
612 .It Cm lz4:block-size
613 A decimal integer from 4 to 7 specifying the lz4 compression block size
614 (7 is set by default).
615 .It Cm lz4:block-dependence
616 Use the previous block of the block being compressed for
617 a compression dictionary to improve compression ratio.
618 .It Cm zstd:compression-level
619 A decimal integer from 1 to 22 specifying the zstd compression level.
620 .It Cm lzop:compression-level
621 A decimal integer from 1 to 9 specifying the lzop compression level.
622 .It Cm xz:compression-level
623 A decimal integer from 0 to 9 specifying the xz compression level.
624 .It Cm mtree: Ns Ar keyword
625 The mtree writer module allows you to specify which mtree keywords
626 will be included in the output.
627 Supported keywords include:
628 .Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent ,
629 .Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 ,
630 .Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname .
631 The default is equivalent to:
632 .Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname .
634 Enables all of the above keywords.
637 to disable all keywords.
643 Produce human-readable output by indenting options and splitting lines
644 to fit into 80 columns.
645 .It Cm zip:compression Ns = Ns Ar type
648 as compression method.
649 Supported values are store (uncompressed) and deflate (gzip algorithm).
650 .It Cm zip:encryption
651 Enable encryption using traditional zip encryption.
652 .It Cm zip:encryption Ns = Ns Ar type
656 Supported values are zipcrypt (traditional zip encryption),
657 aes128 (WinZip AES-128 encryption) and aes256 (WinZip AES-256 encryption).
658 .It Cm read_concatenated_archives
659 Ignore zeroed blocks in the archive, which occurs when multiple tar archives
660 have been concatenated together.
661 Without this option, only the contents of
662 the first concatenated archive would be read.
663 This option is comparable to the
664 .Fl i , Fl Fl ignore-zeros
667 If a provided option is not supported by any module, that
669 .It Fl P , Fl Fl absolute-paths
671 By default, absolute pathnames (those that begin with a /
672 character) have the leading slash removed both when creating archives
673 and extracting from them.
676 will refuse to extract archive entries whose pathnames contain
678 or whose target directory would be altered by a symlink.
679 This option suppresses these behaviors.
680 .It Fl p , Fl Fl insecure , Fl Fl preserve-permissions
682 Preserve file permissions.
683 Attempt to restore the full permissions, including file modes, file attributes
684 or file flags, extended file attributes and ACLs, if available, for each item
685 extracted from the archive.
686 This is the reverse of
687 .Fl Fl no-same-permissions
690 is being run as root.
691 It can be partially overridden by also specifying
694 .Fl Fl no-mac-metadata
697 .It Fl Fl passphrase Ar passphrase
700 is used to extract or create an encrypted archive.
701 Currently, zip is the only supported format that supports encryption.
702 You shouldn't use this option unless you realize how insecure
703 use of this option is.
708 .It Fl q , Fl Fl fast-read
710 Extract or list only the first archive entry that matches each pattern
712 Exit as soon as each specified pattern or filename has been matched.
713 By default, the archive is always read to the very end, since
714 there can be multiple entries with the same name and, by convention,
715 later entries overwrite earlier entries.
716 This option is provided as a performance optimization.
719 Extract files as sparse files.
720 For every block on disk, check first if it contains only NULL bytes and seek
722 This works similar to the conv=sparse option of dd.
724 Modify file or archive member names according to
726 The pattern has the format
727 .Ar /old/new/ Ns Op ghHprRsS
730 is a basic regular expression,
732 is the replacement string of the matched part,
733 and the optional trailing letters modify
734 how the replacement is handled.
737 is not matched, the pattern is skipped.
740 ~ is substituted with the match, \e1 to \e9 with the content of
741 the corresponding captured group.
742 The optional trailing g specifies that matching should continue
743 after the matched part and stop on the first unmatched pattern.
744 The optional trailing s specifies that the pattern applies to the value
746 The optional trailing p specifies that after a successful substitution
747 the original path name and the new path name should be printed to
749 Optional trailing H, R, or S characters suppress substitutions
750 for hardlink targets, regular filenames, or symlink targets,
752 Optional trailing h, r, or s characters enable substitutions
753 for hardlink targets, regular filenames, or symlink targets,
757 which applies substitutions to all names.
758 In particular, it is never necessary to specify h, r, or s.
761 Extract owner and group IDs.
762 This is the reverse of
764 and the default behavior if
767 .It Fl Fl strip-components Ar count
768 Remove the specified number of leading path elements.
769 Pathnames with fewer elements will be silently skipped.
770 Note that the pathname is edited after checking inclusion/exclusion patterns
771 but before security checks.
772 .It Fl T Ar filename , Fl Fl files-from Ar filename
775 will read the list of names to be extracted from
779 will read names to be archived from
783 on a line by itself will cause the current directory to be changed to
784 the directory specified on the following line.
785 Names are terminated by newlines unless
790 also disables the special handling of lines containing
792 Note: If you are generating lists of files using
794 you probably want to use
799 After archiving all files, print a summary to stderr.
800 .It Fl U , Fl Fl unlink , Fl Fl unlink-first
802 Unlink files before creating them.
803 This can be a minor performance optimization if most files
804 already exist, but can make things slower if most files
805 do not already exist.
806 This flag also causes
808 to remove intervening directory symlinks instead of
810 See the SECURITY section below for more details.
812 Use the provided user id number and ignore the user
813 name from the archive.
816 is not also specified, the user name will be set to
818 .It Fl Fl uname Ar name
819 Use the provided user name.
820 On extract, this overrides the user name in the archive;
821 if the provided user name does not exist on the system,
822 it will be ignored and the user id
823 (from the archive or from the
826 will be used instead.
827 On create, this sets the user name that will be stored
829 the name is not verified against the system user database.
830 .It Fl Fl use-compress-program Ar program
831 Pipe the input (in x or t mode) or the output (in c mode) through
833 instead of using the builtin compression support.
834 .It Fl v , Fl Fl verbose
835 Produce verbose output.
836 In create and extract modes,
838 will list each file name as it is read from or written to
842 will produce output similar to that of
846 option will also provide ls-like details in create and extract mode.
853 .It Fl w , Fl Fl confirmation , Fl Fl interactive
854 Ask for confirmation for every action.
855 .It Fl X Ar filename , Fl Fl exclude-from Ar filename
856 Read a list of exclusion patterns from the specified file.
859 for more information about the handling of exclusions.
861 (c, r, u, x modes only)
862 Archive or extract extended file attributes.
863 This is the reverse of
865 and the default behavior in c, r, and u modes or if
867 is run in x mode as root.
870 Compress the resulting archive with
872 In extract or list modes, this option is ignored.
875 implementation recognizes bzip2 compression automatically when reading
877 .It Fl Z , Fl Fl compress , Fl Fl uncompress
879 Compress the resulting archive with
881 In extract or list modes, this option is ignored.
884 implementation recognizes compress compression automatically when reading
886 .It Fl z , Fl Fl gunzip , Fl Fl gzip
888 Compress the resulting archive with
890 In extract or list modes, this option is ignored.
893 implementation recognizes gzip compression automatically when reading
897 The following environment variables affect the execution of
899 .Bl -tag -width ".Ev BLOCKSIZE"
900 .It Ev TAR_READER_OPTIONS
901 The default options for format readers and compression readers.
904 option overrides this.
905 .It Ev TAR_WRITER_OPTIONS
906 The default options for format writers and compression writers.
909 option overrides this.
914 for more information.
919 option overrides this.
920 Please see the description of the
922 option above for more details.
924 The timezone to use when displaying dates.
927 for more information.
932 The following creates a new archive
935 that contains two files
939 .Dl Nm Fl czf Pa file.tar.gz Pa source.c Pa source.h
941 To view a detailed table of contents for this
943 .Dl Nm Fl tvf Pa file.tar.gz
945 To extract all entries from the archive on
946 the default tape drive:
949 To examine the contents of an ISO 9660 cdrom image:
950 .Dl Nm Fl tf Pa image.iso
952 To move file hierarchies, invoke
955 .Dl Nm Fl cf Pa - Fl C Pa srcdir \&. | Nm Fl xpf Pa - Fl C Pa destdir
956 or more traditionally
957 .Dl cd srcdir \&; Nm Fl cf Pa - \&. | ( cd destdir \&; Nm Fl xpf Pa - )
959 In create mode, the list of files and directories to be archived
960 can also include directory change instructions of the form
962 and archive inclusions of the form
963 .Cm @ Ns Pa archive-file .
964 For example, the command line
965 .Dl Nm Fl c Fl f Pa new.tar Pa foo1 Cm @ Ns Pa old.tgz Cm -C Ns Pa /tmp Pa foo2
966 will create a new archive
971 from the current directory and add it to the output archive.
972 It will then read each entry from
974 and add those entries to the output archive.
975 Finally, it will switch to the
979 to the output archive.
983 format can be used to create an output archive with arbitrary ownership,
984 permissions, or names that differ from existing data on disk:
985 .Bd -literal -offset indent
988 usr/bin uid=0 gid=0 mode=0755 type=dir
989 usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls
990 $ tar -cvf output.tar @input.mtree
997 switches accept a variety of common date and time specifications, including
998 .Dq 12 Mar 2005 7:14:29pm ,
999 .Dq 2005-03-12 19:14 ,
1002 .Dq 19:14 PST May 1 .
1006 argument can be used to control various details of archive generation
1008 For example, you can generate mtree output which only contains
1009 .Cm type , Cm time ,
1013 .Dl Nm Fl cf Pa file.tar Fl Fl format=mtree Fl Fl options='!all,type,time,uid' Pa dir
1014 or you can set the compression level used by gzip or xz compression:
1015 .Dl Nm Fl czf Pa file.tar Fl Fl options='compression-level=9' .
1016 For more details, see the explanation of the
1017 .Fn archive_read_set_options
1019 .Fn archive_write_set_options
1020 API calls that are described in
1023 .Xr archive_write 3 .
1025 The bundled-arguments format is supported for compatibility
1026 with historic implementations.
1027 It consists of an initial word (with no leading - character) in which
1028 each character indicates an option.
1029 Arguments follow as separate words.
1030 The order of the arguments must match the order
1031 of the corresponding characters in the bundled command word.
1033 .Dl Nm Cm tbf 32 Pa file.tar
1034 specifies three flags
1043 flags both require arguments,
1044 so there must be two additional items
1045 on the command line.
1048 is the argument to the
1052 is the argument to the
1056 The mode options c, r, t, u, and x and the options
1057 b, f, l, m, o, v, and w comply with SUSv2.
1059 For maximum portability, scripts that invoke
1061 should use the bundled-argument format above, should limit
1076 Additional long options are provided to improve compatibility with other
1077 tar implementations.
1079 Certain security issues are common to many archiving programs, including
1081 In particular, carefully-crafted archives can request that
1083 extract files to locations outside of the target directory.
1084 This can potentially be used to cause unwitting users to overwrite
1085 files they did not intend to overwrite.
1086 If the archive is being extracted by the superuser, any file
1087 on the system can potentially be overwritten.
1088 There are three ways this can happen.
1091 has mechanisms to protect against each one,
1092 savvy users should be aware of the implications:
1093 .Bl -bullet -width indent
1095 Archive entries can have absolute pathnames.
1100 character from filenames before restoring them to guard against this problem.
1102 Archive entries can have pathnames that include
1107 will not extract files containing
1109 components in their pathname.
1111 Archive entries can exploit symbolic links to restore
1112 files to other directories.
1113 An archive can restore a symbolic link to another directory,
1114 then use that link to restore a file into that directory.
1115 To guard against this,
1117 checks each extracted path for symlinks.
1118 If the final path element is a symlink, it will be removed
1119 and replaced with the archive entry.
1122 is specified, any intermediate symlink will also be unconditionally removed.
1129 will refuse to extract the entry.
1131 To protect yourself, you should be wary of any archives that
1132 come from untrusted sources.
1133 You should examine the contents of an archive with
1134 .Dl Nm Fl tf Pa filename
1138 option to ensure that
1140 will not overwrite any existing files or the
1142 option to remove any pre-existing files.
1143 You should generally not extract archives while running with super-user
1149 disables the security checks above and allows you to extract
1150 an archive while preserving any absolute pathnames,
1152 components, or symlinks to other directories.
1163 .Xr libarchive-formats 5 ,
1166 There is no current POSIX standard for the tar command; it appeared
1169 but was dropped from
1171 The options supported by this implementation were developed by surveying a
1172 number of existing tar implementations as well as the old POSIX specification
1173 for tar and the current POSIX specification for pax.
1175 The ustar and pax interchange file formats are defined by
1177 for the pax command.
1181 command appeared in Seventh Edition Unix, which was released in January, 1979.
1182 There have been numerous other implementations,
1183 many of which extended the file format.
1186 public-domain implementation (circa November, 1987)
1187 was quite influential, and formed the basis of GNU tar.
1188 GNU tar was included as the standard system tar
1194 This is a complete re-implementation based on the
1197 It was first released with
1201 This program follows
1203 for the definition of the
1206 Note that GNU tar prior to version 1.15 treated
1208 as a synonym for the
1209 .Fl Fl one-file-system
1214 option may differ from historic implementations.
1216 All archive output is written in correctly-sized blocks, even
1217 if the output is being compressed.
1218 Whether or not the last output block is padded to a full
1219 block size varies depending on the format and the
1221 For tar and cpio formats, the last block of output is padded
1222 to a full block size if the output is being
1223 written to standard output or to a character or block device such as
1225 If the output is being written to a regular file, the last block
1227 Many compressors, including
1231 complain about the null padding when decompressing an archive created by
1233 although they still extract it correctly.
1235 The compression and decompression is implemented internally, so
1236 there may be insignificant differences between the compressed output
1238 .Dl Nm Fl czf Pa - file
1239 and that generated by
1240 .Dl Nm Fl cf Pa - file | Nm gzip
1242 The default should be to read and write archives to the standard I/O paths,
1243 but tradition (and POSIX) dictates otherwise.
1249 modes require that the archive be uncompressed
1250 and located in a regular file on disk.
1251 Other archives can be modified using
1257 To archive a file called
1261 you must specify it as
1267 In create mode, a leading
1272 is stripped unless the
1274 option is specified.
1276 There needs to be better support for file selection on both create
1279 There is not yet any support for multi-volume archives.
1281 Converting between dissimilar archive formats (such as tar and cpio) using the
1283 convention can cause hard link information to be lost.
1284 (This is a consequence of the incompatible ways that different archive
1285 formats store hardlink information.)