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