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