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