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