4 - manipulate tape archives
8 <nowiki>[</nowiki>''bundled-flags'' <args><nowiki>]</nowiki>
9 <nowiki>[</nowiki><''file''> | <''pattern''> ...<nowiki>]</nowiki>
12 <nowiki>{</nowiki>-c<nowiki>}</nowiki>
13 <nowiki>[</nowiki>''options''<nowiki>]</nowiki>
14 <nowiki>[</nowiki>''files'' | ''directories''<nowiki>]</nowiki>
17 <nowiki>{</nowiki>-r | -u<nowiki>}</nowiki>
19 <nowiki>[</nowiki>''options''<nowiki>]</nowiki>
20 <nowiki>[</nowiki>''files'' | ''directories''<nowiki>]</nowiki>
23 <nowiki>{</nowiki>-t | -x<nowiki>}</nowiki>
24 <nowiki>[</nowiki>''options''<nowiki>]</nowiki>
25 <nowiki>[</nowiki>''patterns''<nowiki>]</nowiki>
28 creates and manipulates streaming archive files.
29 This implementation can extract from tar, pax, cpio, zip, jar, ar, xar,
30 rpm, 7-zip, and ISO 9660 cdrom images and can create tar, pax, cpio, ar, zip,
31 7-zip, and shar archives.
33 The first synopsis form shows a
36 This usage is provided for compatibility with historical implementations.
37 See COMPATIBILITY below for details.
39 The other synopsis forms show the preferred usage.
42 is a mode indicator from the following list:
45 Create a new archive containing the specified items.
46 The long option form is
51 but new entries are appended to the archive.
52 Note that this only works on uncompressed archives stored in regular files.
56 The long option form is
59 List archive contents to stdout.
60 The long option form is
65 but new entries are added only if they have a modification date
66 newer than the corresponding entry in the archive.
67 Note that this only works on uncompressed archives stored in regular files.
74 Extract to disk from the archive.
75 If a file with the same name appears more than once in the archive,
76 each copy will be extracted, with later copies overwriting (replacing)
78 The long option form is
87 mode, each specified file or directory is added to the
88 archive in the order specified on the command line.
89 By default, the contents of each directory are also archived.
91 In extract or list mode, the entire command line
92 is read and parsed before the archive is opened.
93 The pathnames or patterns on the command line indicate
94 which items in the archive should be processed.
95 Patterns are shell-style globbing patterns as
97 [[tcsh(1)|http://www.freebsd.org/cgi/man.cgi?query=tcsh&sektion=1]].
99 Unless specifically stated otherwise, options are applicable in
102 <dt>'''@'''''archive''</dt><dd>
104 The specified archive is opened and the entries
105 in it will be appended to the current archive.
108 tar -c -f - newfile @original.tar
110 writes a new archive to standard output containing a file
112 and all of the entries from
116 tar -c -f - newfile original.tar
118 creates a new archive with only two entries.
121 tar -czf - --format pax @-
123 reads an archive from standard input (whose format will be determined
124 automatically) and converts it into a gzip-compressed
125 pax-format archive on stdout.
128 can be used to convert archives from one format to another.
129 </dd><dt>-a, --auto-compress</dt><dd>
131 Use the archive suffix to decide a set of the format and
135 tar -a -cf archive.tgz source.c source.h
137 creates a new archive with restricted pax format and gzip compression,
139 tar -a -cf archive.tar.bz2.uu source.c source.h
141 creates a new archive with restricted pax format and bzip2 compression
142 and uuencode compression,
144 tar -a -cf archive.zip source.c source.h
146 creates a new archive with zip format,
148 tar -a -jcf archive.tgz source.c source.h
152 option, and creates a new archive with restricted pax format
153 and gzip compression,
155 tar -a -jcf archive.xxx source.c source.h
157 if it is unknown suffix or no suffix, creates a new archive with
158 restricted pax format and bzip2 compression.
159 </dd><dt>--acls</dt><dd>
160 (c, r, u, x modes only)
161 Archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of
163 and the default behavior in c, r, and u modes (except Mac OS X) or if
165 is run in x mode as root. On Mac OS X this option translates extended ACLs
166 to NFSv4 ACLs. To store extended ACLs the
169 </dd><dt>-B, --read-full-blocks</dt><dd>
170 Ignored for compatibility with other
173 </dd><dt>-b ''blocksize'', --block-size ''blocksize''</dt><dd>
174 Specify the block size, in 512-byte records, for tape drive I/O.
175 As a rule, this argument is only needed when reading from or writing
176 to tape drives, and usually not even then as the default block size of
177 20 records (10240 bytes) is very common.
178 </dd><dt>-C ''directory'', --cd ''directory'', --directory ''directory''</dt><dd>
179 In c and r mode, this changes the directory before adding
181 In x mode, change directories after opening the archive
182 but before extracting entries from the archive.
183 </dd><dt>--chroot</dt><dd>
186 to the current directory after processing any
188 options and before extracting any files.
189 </dd><dt>--clear-nochange-fflags</dt><dd>
191 Before removing file system objects to replace them, clear platform-specific
192 file flags that might prevent removal.
193 </dd><dt>--exclude ''pattern''</dt><dd>
194 Do not process files or directories that match the
196 Note that exclusions take precedence over patterns or filenames
197 specified on the command line.
198 </dd><dt>--fflags</dt><dd>
199 (c, r, u, x modes only)
200 Archive or extract file flags. This is the reverse of
202 and the default behavior in c, r, and u modes or if
204 is run in x mode as root.
205 </dd><dt>--format ''format''</dt><dd>
207 Use the specified format for the created archive.
208 Supported formats include
214 Other formats may also be supported; see
215 [[ManPageLibarchiveFormats5]]
216 for more information about currently-supported formats.
217 In r and u modes, when extending an existing archive, the format specified
218 here must be compatible with the format of the existing archive on disk.
219 </dd><dt>-f ''file'', --file ''file''</dt><dd>
220 Read the archive from or write the archive to the specified file.
223 for standard input or standard output.
224 The default varies by system;
229 on Linux, the default is
231 </dd><dt>--gid ''id''</dt><dd>
232 Use the provided group id number.
233 On extract, this overrides the group id in the archive;
234 the group name in the archive will be ignored.
235 On create, this overrides the group id read from disk;
238 is not also specified, the group name will be set to
240 </dd><dt>--gname ''name''</dt><dd>
241 Use the provided group name.
242 On extract, this overrides the group name in the archive;
243 if the provided group name does not exist on the system,
245 (from the archive or from the
248 will be used instead.
249 On create, this sets the group name that will be stored
251 the name will not be verified against the system group database.
254 Symbolic links named on the command line will be followed; the
255 target of the link will be archived, not the link itself.
263 </dd><dt>--help</dt><dd>
265 </dd><dt>--hfsCompression</dt><dd>
267 Mac OS X specific (v10.6 or later). Compress extracted regular files with HFS+
269 </dd><dt>--ignore-zeros</dt><dd>
271 --options '''read_concatenated_archives'''
272 for compatibility with GNU tar.
273 </dd><dt>--include ''pattern''</dt><dd>
274 Process only files or directories that match the specified pattern.
275 Note that exclusions specified with
277 take precedence over inclusions.
278 If no inclusions are explicitly specified, all entries are processed by
282 option is especially useful when filtering archives.
283 For example, the command
285 tar -c -f new.tar --include='*foo*' @old.tgz
287 creates a new archive
289 containing only the entries from
291 containing the string
293 </dd><dt>-J, --xz</dt><dd>
295 Compress the resulting archive with
296 [[xz(1)|http://www.freebsd.org/cgi/man.cgi?query=xz&sektion=1]].
297 In extract or list modes, this option is ignored.
298 Note that, unlike other
300 implementations, this implementation recognizes XZ compression
301 automatically when reading archives.
302 </dd><dt>-j, --bzip, --bzip2, --bunzip2</dt><dd>
304 Compress the resulting archive with
305 [[bzip2(1)|http://www.freebsd.org/cgi/man.cgi?query=bzip2&sektion=1]].
306 In extract or list modes, this option is ignored.
307 Note that, unlike other
309 implementations, this implementation recognizes bzip2 compression
310 automatically when reading archives.
311 </dd><dt>-k, --keep-old-files</dt><dd>
313 Do not overwrite existing files.
314 In particular, if a file appears more than once in an archive,
315 later copies will not overwrite earlier copies.
316 </dd><dt>--keep-newer-files</dt><dd>
318 Do not overwrite existing files that are newer than the
319 versions appearing in the archive being extracted.
320 </dd><dt>-L, --dereference</dt><dd>
322 All symbolic links will be followed.
323 Normally, symbolic links are archived as such.
324 With this option, the target of the link will be archived instead.
325 </dd><dt>-l, --check-links</dt><dd>
327 Issue a warning message unless all links to each file are archived.
328 </dd><dt>--lrzip</dt><dd>
330 Compress the resulting archive with
331 [[lrzip(1)|http://www.freebsd.org/cgi/man.cgi?query=lrzip&sektion=1]].
332 In extract or list modes, this option is ignored.
333 </dd><dt>--lz4</dt><dd>
335 Compress the archive with lz4-compatible compression before writing it.
336 In input mode, this option is ignored; lz4 compression is recognized
337 automatically on input.
338 </dd><dt>--lzma</dt><dd>
339 (c mode only) Compress the resulting archive with the original LZMA algorithm.
340 Use of this option is discouraged and new archives should be created with
343 Note that, unlike other
345 implementations, this implementation recognizes LZMA compression
346 automatically when reading archives.
347 </dd><dt>--lzop</dt><dd>
349 Compress the resulting archive with
350 [[lzop(1)|http://www.freebsd.org/cgi/man.cgi?query=lzop&sektion=1]].
351 In extract or list modes, this option is ignored.
352 </dd><dt>-m, --modification-time</dt><dd>
354 Do not extract modification time.
355 By default, the modification time is set to the time stored in the archive.
356 </dd><dt>--mac-metadata</dt><dd>
357 (c, r, u and x mode only)
358 Mac OS X specific. Archive or extract extended ACLs and extended attributes
360 [[copyfile(3)|http://www.freebsd.org/cgi/man.cgi?query=copyfile&sektion=3]]
361 in AppleDouble format. This is the reverse of
363 and the default behavior in c, r, and u modes or if
365 is run in x mode as root.
366 </dd><dt>-n, --norecurse, --no-recursion</dt><dd>
368 Do not recursively archive the contents of directories.
369 </dd><dt>--newer ''date''</dt><dd>
371 Only include files and directories newer than the specified date.
372 This compares ctime entries.
373 </dd><dt>--newer-mtime ''date''</dt><dd>
377 except it compares mtime entries instead of ctime entries.
378 </dd><dt>--newer-than ''file''</dt><dd>
380 Only include files and directories newer than the specified file.
381 This compares ctime entries.
382 </dd><dt>--newer-mtime-than ''file''</dt><dd>
386 except it compares mtime entries instead of ctime entries.
387 </dd><dt>--nodump</dt><dd>
389 Honor the nodump file flag by skipping this file.
390 </dd><dt>--nopreserveHFSCompression</dt><dd>
392 Mac OS X specific(v10.6 or later). Do not compress extracted regular files
393 which were compressed with HFS+ compression before archived.
394 By default, compress the regular files again with HFS+ compression.
395 </dd><dt>--null</dt><dd>
400 Filenames or patterns are separated by null characters,
402 This is often used to read filenames output by the
405 [[find(1)|http://www.freebsd.org/cgi/man.cgi?query=find&sektion=1]].
406 </dd><dt>--no-acls</dt><dd>
407 (c, r, u, x modes only)
408 Do not archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of
410 and the default behavior if
412 is run as non-root in x mode (on Mac OS X also in c, r and u modes).
413 </dd><dt>--no-fflags</dt><dd>
414 (c, r, u, x modes only)
415 Do not archive or extract file flags. This is the reverse of
417 and the default behavior if
419 is run as non-root in x mode.
420 </dd><dt>--no-mac-metadata</dt><dd>
422 Mac OS X specific. Do not archive or extract ACLs and extended attributes using
423 [[copyfile(3)|http://www.freebsd.org/cgi/man.cgi?query=copyfile&sektion=3]]
424 in AppleDouble format. This is the reverse of
426 and the default behavior if
428 is run as non-root in x mode.
429 </dd><dt>-n, --norecurse, --no-recursion</dt><dd>
430 </dd><dt>--no-same-owner</dt><dd>
432 Do not extract owner and group IDs.
433 This is the reverse of
435 and the default behavior if
438 </dd><dt>--no-same-permissions</dt><dd>
440 Do not extract full permissions (SGID, SUID, sticky bit, ACLs,
441 extended attributes or extended file flags).
442 This is the reverse of
444 and the default behavior if
446 is run as non-root and can be overridden by also specifying
454 </dd><dt>--no-xattrs</dt><dd>
455 (c, r, u, x modes only)
456 Do not archive or extract extended attributes. This is the reverse of
458 and the default behavior if
460 is run as non-root in x mode.
461 </dd><dt>--numeric-owner</dt><dd>
462 This is equivalent to
467 On extract, it causes user and group names in the archive
468 to be ignored in favor of the numeric user and group ids.
469 On create, it causes user and group names to not be stored
471 </dd><dt>-O, --to-stdout</dt><dd>
473 In extract (-x) mode, files will be written to standard out rather than
474 being extracted to disk.
475 In list (-t) mode, the file listing will be written to stderr rather than
479 Use the user and group of the user running the program rather
480 than those specified in the archive.
481 Note that this has no significance unless
483 is specified, and the program is being run by the root user.
484 In this case, the file modes and flags from
485 the archive will be restored, but ACLs or owner information in
486 the archive will be discarded.
491 </dd><dt>--older ''date''</dt><dd>
493 Only include files and directories older than the specified date.
494 This compares ctime entries.
495 </dd><dt>--older-mtime ''date''</dt><dd>
499 except it compares mtime entries instead of ctime entries.
500 </dd><dt>--older-than ''file''</dt><dd>
502 Only include files and directories older than the specified file.
503 This compares ctime entries.
504 </dd><dt>--older-mtime-than ''file''</dt><dd>
508 except it compares mtime entries instead of ctime entries.
509 </dd><dt>--one-file-system</dt><dd>
511 Do not cross mount points.
512 </dd><dt>--options ''options''</dt><dd>
513 Select optional behaviors for particular modules.
514 The argument is a text string containing comma-separated
516 These are passed to the modules that handle particular
517 formats to control how those formats will behave.
518 Each option has one of the following forms:
520 <dt>''key=value''</dt><dd>
521 The key will be set to the specified value in every module that supports it.
522 Modules that do not support this key will ignore it.
523 </dd><dt>''key''</dt><dd>
524 The key will be enabled in every module that supports it.
525 This is equivalent to
527 </dd><dt>''!key''</dt><dd>
528 The key will be disabled in every module that supports it.
529 </dd><dt>''module:key=value'', ''module:key'', ''module:!key''</dt><dd>
530 As above, but the corresponding key and value will be provided
531 only to modules whose name matches
534 The currently supported modules and keys are:
536 <dt>'''iso9660:joliet'''</dt><dd>
537 Support Joliet extensions.
538 This is enabled by default, use
541 '''iso9660:!joliet'''
543 </dd><dt>'''iso9660:rockridge'''</dt><dd>
544 Support Rock Ridge extensions.
545 This is enabled by default, use
548 '''iso9660:!rockridge'''
550 </dd><dt>'''gzip:compression-level'''</dt><dd>
551 A decimal integer from 1 to 9 specifying the gzip compression level.
552 </dd><dt>'''gzip:timestamp'''</dt><dd>
553 Store timestamp. This is enabled by default, use
556 '''gzip:!timestamp'''
558 </dd><dt>'''lrzip:compression'''=''type''</dt><dd>
561 as compression method.
562 Supported values are bzip2, gzip, lzo (ultra fast),
563 and zpaq (best, extremely slow).
564 </dd><dt>'''lrzip:compression-level'''</dt><dd>
565 A decimal integer from 1 to 9 specifying the lrzip compression level.
566 </dd><dt>'''lz4:compression-level'''</dt><dd>
567 A decimal integer from 1 to 9 specifying the lzop compression level.
568 </dd><dt>'''lz4:stream-checksum'''</dt><dd>
569 Enable stream checksum. This is by default, use
570 '''lz4:!stream-checksum'''
572 </dd><dt>'''lz4:block-checksum'''</dt><dd>
573 Enable block checksum (Disabled by default).
574 </dd><dt>'''lz4:block-size'''</dt><dd>
575 A decimal integer from 4 to 7 specifying the lz4 compression block size
576 (7 is set by default).
577 </dd><dt>'''lz4:block-dependence'''</dt><dd>
578 Use the previous block of the block being compressed for
579 a compression dictionary to improve compression ratio.
580 </dd><dt>'''lzop:compression-level'''</dt><dd>
581 A decimal integer from 1 to 9 specifying the lzop compression level.
582 </dd><dt>'''xz:compression-level'''</dt><dd>
583 A decimal integer from 0 to 9 specifying the xz compression level.
584 </dd><dt>'''mtree:'''''keyword''</dt><dd>
585 The mtree writer module allows you to specify which mtree keywords
586 will be included in the output.
587 Supported keywords include:
588 '''cksum''', '''device''', '''flags''', '''gid''', '''gname''', '''indent''',
589 '''link''', '''md5''', '''mode''', '''nlink''', '''rmd160''', '''sha1''', '''sha256''',
590 '''sha384''', '''sha512''', '''size''', '''time''', '''uid''', '''uname'''.
591 The default is equivalent to:
592 "device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname".
593 </dd><dt>'''mtree:all'''</dt><dd>
594 Enables all of the above keywords.
597 to disable all keywords.
598 </dd><dt>'''mtree:use-set'''</dt><dd>
602 </dd><dt>'''mtree:indent'''</dt><dd>
603 Produce human-readable output by indenting options and splitting lines
604 to fit into 80 columns.
605 </dd><dt>'''zip:compression'''=''type''</dt><dd>
608 as compression method.
609 Supported values are store (uncompressed) and deflate (gzip algorithm).
610 </dd><dt>'''zip:encryption'''</dt><dd>
611 Enable encryption using traditional zip encryption.
612 </dd><dt>'''zip:encryption'''=''type''</dt><dd>
616 Supported values are zipcrypt (traditional zip encryption),
617 aes128 (WinZip AES-128 encryption) and aes256 (WinZip AES-256 encryption).
618 </dd><dt>'''read_concatenated_archives'''</dt><dd>
619 Ignore zeroed blocks in the archive, which occurs when multiple tar archives
620 have been concatenated together. Without this option, only the contents of
621 the first concatenated archive would be read. This option is comparable to
626 If a provided option is not supported by any module, that
628 </dd><dt>-P, --absolute-paths</dt><dd>
630 By default, absolute pathnames (those that begin with a /
631 character) have the leading slash removed both when creating archives
632 and extracting from them.
635 will refuse to extract archive entries whose pathnames contain
637 or whose target directory would be altered by a symlink.
638 This option suppresses these behaviors.
639 </dd><dt>-p, --insecure, --preserve-permissions</dt><dd>
641 Preserve file permissions.
642 Attempt to restore the full permissions, including owner, file modes, ACLs,
643 extended atributes and extended file flags, if available, for each item
644 extracted from the archive. This is the default, if
646 is being run by root and can be overridden by also specifying
651 --no-same-permissions
654 </dd><dt>--passphrase ''passphrase''</dt><dd>
657 is used to extract or create an encrypted archive.
658 Currently, zip is the only supported format that supports encryption.
659 You shouldn't use this option unless you realize how insecure
660 use of this option is.
661 </dd><dt>--posix</dt><dd>
665 </dd><dt>-q, --fast-read</dt><dd>
667 Extract or list only the first archive entry that matches each pattern
669 Exit as soon as each specified pattern or filename has been matched.
670 By default, the archive is always read to the very end, since
671 there can be multiple entries with the same name and, by convention,
672 later entries overwrite earlier entries.
673 This option is provided as a performance optimization.
676 Extract files as sparse files.
677 For every block on disk, check first if it contains only NULL bytes and seek
679 This works similar to the conv=sparse option of dd.
680 </dd><dt>-s ''pattern''</dt><dd>
681 Modify file or archive member names according to
683 The pattern has the format
684 ''/old/new/''<nowiki>[</nowiki>ghHprRsS<nowiki>]</nowiki>
687 is a basic regular expression,
689 is the replacement string of the matched part,
690 and the optional trailing letters modify
691 how the replacement is handled.
694 is not matched, the pattern is skipped.
697 ~ is substituted with the match, \e1 to \e9 with the content of
698 the corresponding captured group.
699 The optional trailing g specifies that matching should continue
700 after the matched part and stop on the first unmatched pattern.
701 The optional trailing s specifies that the pattern applies to the value
703 The optional trailing p specifies that after a successful substitution
704 the original path name and the new path name should be printed to
706 Optional trailing H, R, or S characters suppress substitutions
707 for hardlink targets, regular filenames, or symlink targets,
709 Optional trailing h, r, or s characters enable substitutions
710 for hardlink targets, regular filenames, or symlink targets,
714 which applies substitutions to all names.
715 In particular, it is never necessary to specify h, r, or s.
716 </dd><dt>--same-owner</dt><dd>
718 Extract owner and group IDs.
719 This is the reverse of
721 and the default behavior if
724 </dd><dt>--strip-components ''count''</dt><dd>
725 Remove the specified number of leading path elements.
726 Pathnames with fewer elements will be silently skipped.
727 Note that the pathname is edited after checking inclusion/exclusion patterns
728 but before security checks.
729 </dd><dt>-T ''filename'', --files-from ''filename''</dt><dd>
732 will read the list of names to be extracted from
736 will read names to be archived from
740 on a line by itself will cause the current directory to be changed to
741 the directory specified on the following line.
742 Names are terminated by newlines unless
747 also disables the special handling of lines containing
749 Note: If you are generating lists of files using
750 [[find(1)|http://www.freebsd.org/cgi/man.cgi?query=find&sektion=1]],
751 you probably want to use
754 </dd><dt>--totals</dt><dd>
756 After archiving all files, print a summary to stderr.
757 </dd><dt>-U, --unlink, --unlink-first</dt><dd>
759 Unlink files before creating them.
760 This can be a minor performance optimization if most files
761 already exist, but can make things slower if most files
762 do not already exist.
763 This flag also causes
765 to remove intervening directory symlinks instead of
767 See the SECURITY section below for more details.
768 </dd><dt>--uid ''id''</dt><dd>
769 Use the provided user id number and ignore the user
770 name from the archive.
773 is not also specified, the user name will be set to
775 </dd><dt>--uname ''name''</dt><dd>
776 Use the provided user name.
777 On extract, this overrides the user name in the archive;
778 if the provided user name does not exist on the system,
779 it will be ignored and the user id
780 (from the archive or from the
783 will be used instead.
784 On create, this sets the user name that will be stored
786 the name is not verified against the system user database.
787 </dd><dt>--use-compress-program ''program''</dt><dd>
788 Pipe the input (in x or t mode) or the output (in c mode) through
790 instead of using the builtin compression support.
791 </dd><dt>-v, --verbose</dt><dd>
792 Produce verbose output.
793 In create and extract modes,
795 will list each file name as it is read from or written to
799 will produce output similar to that of
800 [[ls(1)|http://www.freebsd.org/cgi/man.cgi?query=ls&sektion=1]].
803 option will also provide ls-like details in create and extract mode.
804 </dd><dt>--version</dt><dd>
810 </dd><dt>-w, --confirmation, --interactive</dt><dd>
811 Ask for confirmation for every action.
812 </dd><dt>-X ''filename'', --exclude-from ''filename''</dt><dd>
813 Read a list of exclusion patterns from the specified file.
816 for more information about the handling of exclusions.
817 </dd><dt>--xattrs</dt><dd>
818 (c, r, u, x modes only)
819 Archive or extract extended attributes. This is the reverse of
821 and the default behavior in c, r, and u modes or if
823 is run in x mode as root.
826 Compress the resulting archive with
827 [[bzip2(1)|http://www.freebsd.org/cgi/man.cgi?query=bzip2&sektion=1]].
828 In extract or list modes, this option is ignored.
829 Note that, unlike other
831 implementations, this implementation recognizes bzip2 compression
832 automatically when reading archives.
833 </dd><dt>-Z, --compress, --uncompress</dt><dd>
835 Compress the resulting archive with
836 [[compress(1)|http://www.freebsd.org/cgi/man.cgi?query=compress&sektion=1]].
837 In extract or list modes, this option is ignored.
838 Note that, unlike other
840 implementations, this implementation recognizes compress compression
841 automatically when reading archives.
842 </dd><dt>-z, --gunzip, --gzip</dt><dd>
844 Compress the resulting archive with
845 [[gzip(1)|http://www.freebsd.org/cgi/man.cgi?query=gzip&sektion=1]].
846 In extract or list modes, this option is ignored.
847 Note that, unlike other
849 implementations, this implementation recognizes gzip compression
850 automatically when reading archives.
853 The following environment variables affect the execution of
856 <dt>'''TAR_READER_OPTIONS'''</dt><dd>
857 The default options for format readers and compression readers.
860 option overrides this.
861 </dd><dt>'''TAR_WRITER_OPTIONS'''</dt><dd>
862 The default options for format writers and compression writers.
865 option overrides this.
866 </dd><dt>'''LANG'''</dt><dd>
869 [[environ(7)|http://www.freebsd.org/cgi/man.cgi?query=environ&sektion=7]]
870 for more information.
871 </dd><dt>'''TAPE'''</dt><dd>
875 option overrides this.
876 Please see the description of the
878 option above for more details.
879 </dd><dt>'''TZ'''</dt><dd>
880 The timezone to use when displaying dates.
882 [[environ(7)|http://www.freebsd.org/cgi/man.cgi?query=environ&sektion=7]]
883 for more information.
886 The '''tar''' utility exits 0 on success, and >0 if an error occurs.
888 The following creates a new archive
891 that contains two files
896 tar -czf file.tar.gz source.c source.h
899 To view a detailed table of contents for this
905 To extract all entries from the archive on
906 the default tape drive:
911 To examine the contents of an ISO 9660 cdrom image:
916 To move file hierarchies, invoke
920 tar -cf - -C srcdir\. | tar -xpf - -C destdir
922 or more traditionally
924 cd srcdir ; tar -cf -\. | (cd destdir ; tar -xpf -)
927 In create mode, the list of files and directories to be archived
928 can also include directory change instructions of the form
930 and archive inclusions of the form
931 '''@'''''archive-file''.
932 For example, the command line
934 tar -c -f new.tar foo1 @old.tgz -C/tmp foo2
936 will create a new archive
941 from the current directory and add it to the output archive.
942 It will then read each entry from
944 and add those entries to the output archive.
945 Finally, it will switch to the
949 to the output archive.
953 format can be used to create an output archive with arbitrary ownership,
954 permissions, or names that differ from existing data on disk:
959 usr/bin uid=0 gid=0 mode=0755 type=dir
960 usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls
961 $ tar -cvf output.tar @input.mtree
968 switches accept a variety of common date and time specifications, including
969 "12 Mar 2005 7:14:29pm",
977 argument can be used to control various details of archive generation
979 For example, you can generate mtree output which only contains
980 '''type''', '''time''',
985 tar -cf file.tar --format=mtree --options='!all,type,time,uid' dir
987 or you can set the compression level used by gzip or xz compression:
989 tar -czf file.tar --options='compression-level=9'.
991 For more details, see the explanation of the
992 '''archive_read_set_options'''()
994 '''archive_write_set_options'''()
995 API calls that are described in
996 [[ManPageArchiveRead3]]
998 [[ManPageArchiveWrite3]].
1000 The bundled-arguments format is supported for compatibility
1001 with historic implementations.
1002 It consists of an initial word (with no leading - character) in which
1003 each character indicates an option.
1004 Arguments follow as separate words.
1005 The order of the arguments must match the order
1006 of the corresponding characters in the bundled command word.
1011 specifies three flags
1020 flags both require arguments,
1021 so there must be two additional items
1022 on the command line.
1025 is the argument to the
1029 is the argument to the
1033 The mode options c, r, t, u, and x and the options
1034 b, f, l, m, o, v, and w comply with SUSv2.
1036 For maximum portability, scripts that invoke
1038 should use the bundled-argument format above, should limit
1053 Additional long options are provided to improve compatibility with other
1054 tar implementations.
1056 Certain security issues are common to many archiving programs, including
1058 In particular, carefully-crafted archives can request that
1060 extract files to locations outside of the target directory.
1061 This can potentially be used to cause unwitting users to overwrite
1062 files they did not intend to overwrite.
1063 If the archive is being extracted by the superuser, any file
1064 on the system can potentially be overwritten.
1065 There are three ways this can happen.
1068 has mechanisms to protect against each one,
1069 savvy users should be aware of the implications:
1072 Archive entries can have absolute pathnames.
1077 character from filenames before restoring them to guard against this problem.
1079 Archive entries can have pathnames that include
1084 will not extract files containing
1086 components in their pathname.
1088 Archive entries can exploit symbolic links to restore
1089 files to other directories.
1090 An archive can restore a symbolic link to another directory,
1091 then use that link to restore a file into that directory.
1092 To guard against this,
1094 checks each extracted path for symlinks.
1095 If the final path element is a symlink, it will be removed
1096 and replaced with the archive entry.
1099 is specified, any intermediate symlink will also be unconditionally removed.
1106 will refuse to extract the entry.
1108 To protect yourself, you should be wary of any archives that
1109 come from untrusted sources.
1110 You should examine the contents of an archive with
1117 option to ensure that
1119 will not overwrite any existing files or the
1121 option to remove any pre-existing files.
1122 You should generally not extract archives while running with super-user
1128 disables the security checks above and allows you to extract
1129 an archive while preserving any absolute pathnames,
1131 components, or symlinks to other directories.
1133 [[bzip2(1)|http://www.freebsd.org/cgi/man.cgi?query=bzip2&sektion=1]],
1134 [[compress(1)|http://www.freebsd.org/cgi/man.cgi?query=compress&sektion=1]],
1135 [[ManPageBsdcpio1]],
1136 [[gzip(1)|http://www.freebsd.org/cgi/man.cgi?query=gzip&sektion=1]],
1137 [[mt(1)|http://www.freebsd.org/cgi/man.cgi?query=mt&sektion=1]],
1138 [[pax(1)|http://www.freebsd.org/cgi/man.cgi?query=pax&sektion=1]],
1139 [[shar(1)|http://www.freebsd.org/cgi/man.cgi?query=shar&sektion=1]],
1140 [[xz(1)|http://www.freebsd.org/cgi/man.cgi?query=xz&sektion=1]],
1141 [[ManPageLibarchive3]],
1142 [[ManPageLibarchiveFormats5]],
1145 There is no current POSIX standard for the tar command; it appeared
1147 <nowiki>ISO/IEC 9945-1:1996 (``POSIX.1'')</nowiki>
1148 but was dropped from
1149 <nowiki>IEEE Std 1003.1-2001 (``POSIX.1'')</nowiki>.
1150 The options supported by this implementation were developed by surveying a
1151 number of existing tar implementations as well as the old POSIX specification
1152 for tar and the current POSIX specification for pax.
1154 The ustar and pax interchange file formats are defined by
1155 <nowiki>IEEE Std 1003.1-2001 (``POSIX.1'')</nowiki>
1156 for the pax command.
1160 command appeared in Seventh Edition Unix, which was released in January, 1979.
1161 There have been numerous other implementations,
1162 many of which extended the file format.
1165 public-domain implementation (circa November, 1987)
1166 was quite influential, and formed the basis of GNU tar.
1167 GNU tar was included as the standard system tar
1173 This is a complete re-implementation based on the
1174 [[ManPageLibarchive3]]
1176 It was first released with
1180 This program follows
1181 <nowiki>ISO/IEC 9945-1:1996 (``POSIX.1'')</nowiki>
1182 for the definition of the
1185 Note that GNU tar prior to version 1.15 treated
1187 as a synonym for the
1193 option may differ from historic implementations.
1195 All archive output is written in correctly-sized blocks, even
1196 if the output is being compressed.
1197 Whether or not the last output block is padded to a full
1198 block size varies depending on the format and the
1200 For tar and cpio formats, the last block of output is padded
1201 to a full block size if the output is being
1202 written to standard output or to a character or block device such as
1204 If the output is being written to a regular file, the last block
1206 Many compressors, including
1207 [[gzip(1)|http://www.freebsd.org/cgi/man.cgi?query=gzip&sektion=1]]
1209 [[bzip2(1)|http://www.freebsd.org/cgi/man.cgi?query=bzip2&sektion=1]],
1210 complain about the null padding when decompressing an archive created by
1212 although they still extract it correctly.
1214 The compression and decompression is implemented internally, so
1215 there may be insignificant differences between the compressed output
1220 and that generated by
1222 tar -cf - file | gzip
1225 The default should be to read and write archives to the standard I/O paths,
1226 but tradition (and POSIX) dictates otherwise.
1232 modes require that the archive be uncompressed
1233 and located in a regular file on disk.
1234 Other archives can be modified using
1240 To archive a file called
1244 you must specify it as
1250 In create mode, a leading
1255 is stripped unless the
1257 option is specified.
1259 There needs to be better support for file selection on both create
1262 There is not yet any support for multi-volume archives.
1264 Converting between dissimilar archive formats (such as tar and cpio) using the
1266 convention can cause hard link information to be lost.
1267 (This is a consequence of the incompatible ways that different archive
1268 formats store hardlink information.)