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