xref: /freebsd/contrib/libarchive/tar/bsdtar.1 (revision 278d6950943a9fec2bddb037b547c04a847c54ba)
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 March 1, 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
648A decimal integer specifying the zstd compression level. Supported values depend
649on the library version, common values are from 1 to 22.
650.It Cm zstd:threads
651Specify the number of worker threads to use.
652Setting threads to a special value 0 makes
653.Xr zstd 1
654use as many threads as there are CPU cores on the system.
655.It Cm zstd:frame-per-file
656Start a new compression frame at the beginning of each file in the
657archive.
658.It Cm zstd:min-frame-in Ns = Ns Ar N
659In combination with
660.Cm zstd:frame-per-file ,
661do not start a new compression frame unless the uncompressed size of
662the current frame is at least
663.Ar N
664bytes.
665The number may be followed by
666.Li k / Li kB ,
667.Li M / Li MB ,
668or
669.Li G / Li GB
670to indicate kilobytes, megabytes or gigabytes respectively.
671.It Cm zstd:min-frame-out Ns = Ns Ar N , Cm zstd:min-frame-size Ns = Ns Ar N
672In combination with
673.Cm zstd:frame-per-file ,
674do not start a new compression frame unless the compressed size of the
675current frame is at least
676.Ar N
677bytes.
678The number may be followed by
679.Li k / Li kB ,
680.Li M / Li MB ,
681or
682.Li G / Li GB
683to indicate kilobytes, megabytes or gigabytes respectively.
684.It Cm zstd:max-frame-in Ns = Ns Ar N , Cm zstd:max-frame-size Ns = Ns Ar N
685Start a new compression frame as soon as possible after the
686uncompressed size of the current frame exceeds
687.Ar N
688bytes.
689The number may be followed by
690.Li k / Li kB ,
691.Li M / Li MB ,
692or
693.Li G / Li GB
694to indicate kilobytes, megabytes or gigabytes respectively.
695Values less than 1,024 will be rejected.
696.It Cm zstd:max-frame-out Ns = Ns Ar N
697Start a new compression frame as soon as possible after the compressed
698size of the current frame exceeds
699.Ar N
700bytes.
701The number may be followed by
702.Li k / Li kB ,
703.Li M / Li MB ,
704or
705.Li G / Li GB
706to indicate kilobytes, megabytes or gigabytes respectively.
707Values less than 1,024 will be rejected.
708.It Cm lzop:compression-level
709A decimal integer from 1 to 9 specifying the lzop compression level.
710.It Cm xz:compression-level
711A decimal integer from 0 to 9 specifying the xz compression level.
712.It Cm xz:threads
713Specify the number of worker threads to use.
714Setting threads to a special value 0 makes
715.Xr xz 1
716use as many threads as there are CPU cores on the system.
717.It Cm mtree: Ns Ar keyword
718The mtree writer module allows you to specify which mtree keywords
719will be included in the output.
720Supported keywords include:
721.Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent ,
722.Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 ,
723.Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname .
724The default is equivalent to:
725.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname .
726.It Cm mtree:all
727Enables all of the above keywords.
728You can also use
729.Cm mtree:!all
730to disable all keywords.
731.It Cm mtree:use-set
732Enable generation of
733.Cm /set
734lines in the output.
735.It Cm mtree:indent
736Produce human-readable output by indenting options and splitting lines
737to fit into 80 columns.
738.It Cm zip:compression Ns = Ns Ar type
739Use
740.Ar type
741as compression method.
742Supported values are store (uncompressed) and deflate (gzip algorithm).
743.It Cm zip:encryption
744Enable encryption using traditional zip encryption.
745.It Cm zip:encryption Ns = Ns Ar type
746Use
747.Ar type
748as encryption type.
749Supported values are zipcrypt (traditional zip encryption),
750aes128 (WinZip AES-128 encryption) and aes256 (WinZip AES-256 encryption).
751.It Cm read_concatenated_archives
752Ignore zeroed blocks in the archive, which occurs when multiple tar archives
753have been concatenated together.
754Without this option, only the contents of
755the first concatenated archive would be read.
756This option is comparable to the
757.Fl i , Fl Fl ignore-zeros
758option of GNU tar.
759.El
760If a provided option is not supported by any module, that
761is a fatal error.
762.It Fl P , Fl Fl absolute-paths
763Preserve pathnames.
764By default, absolute pathnames (those that begin with a /
765character) have the leading slash removed both when creating archives
766and extracting from them.
767Also,
768.Nm
769will refuse to extract archive entries whose pathnames contain
770.Pa ..
771or whose target directory would be altered by a symlink.
772This option suppresses these behaviors.
773.It Fl p , Fl Fl insecure , Fl Fl preserve-permissions
774(x mode only)
775Preserve file permissions.
776Attempt to restore the full permissions, including file modes, file attributes
777or file flags, extended file attributes and ACLs, if available, for each item
778extracted from the archive.
779This is the reverse of
780.Fl Fl no-same-permissions
781and the default if
782.Nm
783is being run as root.
784It can be partially overridden by also specifying
785.Fl Fl no-acls ,
786.Fl Fl no-fflags ,
787.Fl Fl no-mac-metadata
788or
789.Fl Fl no-xattrs .
790.It Fl Fl passphrase Ar passphrase
791The
792.Pa passphrase
793is used to extract or create an encrypted archive.
794Currently, zip is the only supported format that supports encryption.
795You shouldn't use this option unless you realize how insecure
796use of this option is.
797.It Fl Fl posix
798(c, r, u mode only)
799Synonym for
800.Fl Fl format Ar pax
801.It Fl q , Fl Fl fast-read
802(x and t mode only)
803Extract or list only the first archive entry that matches each pattern
804or filename operand.
805Exit as soon as each specified pattern or filename has been matched.
806By default, the archive is always read to the very end, since
807there can be multiple entries with the same name and, by convention,
808later entries overwrite earlier entries.
809This option is provided as a performance optimization.
810.It Fl Fl read-sparse
811(c, r, u modes only)
812Read sparse file information from disk.
813This is the reverse of
814.Fl Fl no-read-sparse
815and the default behavior.
816.It Fl S
817(x mode only)
818Extract files as sparse files.
819For every block on disk, check first if it contains only NULL bytes and seek
820over it otherwise.
821This works similar to the conv=sparse option of dd.
822.It Fl s Ar pattern
823Modify file or archive member names according to
824.Pa pattern .
825The pattern has the format
826.Ar /old/new/ Ns Op bghHprRsS
827where
828.Ar old
829is a basic regular expression,
830.Ar new
831is the replacement string of the matched part,
832and the optional trailing letters modify
833how the replacement is handled.
834If
835.Ar old
836is not matched, the pattern is skipped.
837Within
838.Ar new ,
839~ is substituted with the match, \e1 to \e9 with the content of
840the corresponding captured group.
841The optional trailing g specifies that matching should continue
842after the matched part and stop on the first unmatched pattern.
843The optional trailing s specifies that the pattern applies to the value
844of symbolic links.
845The optional trailing p specifies that after a successful substitution
846the original path name and the new path name should be printed to
847standard error.
848The optional trailing b specifies that the substitution should be
849matched from the beginning of the string rather than from right after the
850position at which the previous matching substitution ended.
851Optional trailing H, R, or S characters suppress substitutions
852for hardlink targets, regular filenames, or symlink targets,
853respectively.
854Optional trailing h, r, or s characters enable substitutions
855for hardlink targets, regular filenames, or symlink targets,
856respectively.
857The default is
858.Ar hrs
859which applies substitutions to all names.
860In particular, it is never necessary to specify h, r, or s.
861.It Fl Fl safe-writes
862(x mode only)
863Extract files atomically.
864By default
865.Nm
866unlinks the original file with the same name as the extracted file (if it
867exists), and then creates it immediately under the same name and writes to
868it.
869For a short period of time, applications trying to access the file might
870not find it, or see incomplete results.
871If
872.Fl Fl safe-writes
873is enabled,
874.Nm
875first creates a unique temporary file, then writes the new contents to
876the temporary file, and finally renames the temporary file to its final
877name atomically using
878.Xr rename 2 .
879This guarantees that an application accessing the file, will either see
880the old contents or the new contents at all times.
881.It Fl Fl same-owner
882(x mode only)
883Extract owner and group IDs.
884This is the reverse of
885.Fl Fl no-same-owner
886and the default behavior if
887.Nm
888is run as root.
889.It Fl Fl strip-components Ar count
890Remove the specified number of leading path elements.
891Pathnames with fewer elements will be silently skipped.
892Note that the pathname is edited after checking inclusion/exclusion patterns
893but before security checks.
894.It Fl T Ar filename , Fl Fl files-from Ar filename
895In x or t mode,
896.Nm
897will read the list of names to be extracted from
898.Pa filename .
899In c mode,
900.Nm
901will read names to be archived from
902.Pa filename .
903The special name
904.Dq -C
905on a line by itself will cause the current directory to be changed to
906the directory specified on the following line.
907Names are terminated by newlines unless
908.Fl Fl null
909is specified.
910Note that
911.Fl Fl null
912also disables the special handling of lines containing
913.Dq -C .
914Note:  If you are generating lists of files using
915.Xr find 1 ,
916you probably want to use
917.Fl n
918as well.
919.It Fl Fl totals
920(c, r, u modes only)
921After archiving all files, print a summary to stderr.
922.It Fl U , Fl Fl unlink , Fl Fl unlink-first
923(x mode only)
924Unlink files before creating them.
925This can be a minor performance optimization if most files
926already exist, but can make things slower if most files
927do not already exist.
928This flag also causes
929.Nm
930to remove intervening directory symlinks instead of
931reporting an error.
932See the SECURITY section below for more details.
933.It Fl Fl uid Ar id
934Use the provided user id number and ignore the user
935name from the archive.
936On create, if
937.Fl Fl uname
938is not also specified, the user name will be set to
939match the user id.
940.It Fl Fl uname Ar name
941Use the provided user name.
942On extract, this overrides the user name in the archive;
943if the provided user name does not exist on the system,
944it will be ignored and the user id
945(from the archive or from the
946.Fl Fl uid
947option)
948will be used instead.
949On create, this sets the user name that will be stored
950in the archive;
951the name is not verified against the system user database.
952.It Fl Fl use-compress-program Ar program
953Pipe the input (in x or t mode) or the output (in c mode) through
954.Pa program
955instead of using the builtin compression support.
956.It Fl Fl owner Ar name Ns Op : Ns Ar uid
957Use the provided user, if
958.Ar uid
959is not provided,
960.Ar name
961can be either an username or numeric id.
962See the
963.Fl Fl uname
964option for details.
965.It Fl v , Fl Fl verbose
966Produce verbose output.
967In create and extract modes,
968.Nm
969will list each file name as it is read from or written to
970the archive.
971In list mode,
972.Nm
973will produce output similar to that of
974.Xr ls 1 .
975An additional
976.Fl v
977option will also provide ls-like details in create and extract mode.
978.It Fl Fl version
979Print version of
980.Nm
981and
982.Nm libarchive ,
983and exit.
984.It Fl w , Fl Fl confirmation , Fl Fl interactive
985Ask for confirmation for every action.
986.It Fl X Ar filename , Fl Fl exclude-from Ar filename
987Read a list of exclusion patterns from the specified file.
988See
989.Fl Fl exclude
990for more information about the handling of exclusions.
991.It Fl Fl xattrs
992(c, r, u, x modes only)
993Archive or extract extended file attributes.
994This is the reverse of
995.Fl Fl no-xattrs
996and the default behavior in c, r, and u modes or if
997.Nm
998is run in x mode as root.
999.It Fl y
1000(c mode only)
1001Compress the resulting archive with
1002.Xr bzip2 1 .
1003In extract or list modes, this option is ignored.
1004Note that this
1005.Nm tar
1006implementation recognizes bzip2 compression automatically when reading
1007archives.
1008.It Fl Z , Fl Fl compress , Fl Fl uncompress
1009(c mode only)
1010Compress the resulting archive with
1011.Xr compress 1 .
1012In extract or list modes, this option is ignored.
1013Note that this
1014.Nm tar
1015implementation recognizes compress compression automatically when reading
1016archives.
1017.It Fl z , Fl Fl gunzip , Fl Fl gzip
1018(c mode only)
1019Compress the resulting archive with
1020.Xr gzip 1 .
1021In extract or list modes, this option is ignored.
1022Note that this
1023.Nm tar
1024implementation recognizes gzip compression automatically when reading
1025archives.
1026.El
1027.Sh ENVIRONMENT
1028The following environment variables affect the execution of
1029.Nm :
1030.Bl -tag -width indent
1031.It Ev TAR_READER_OPTIONS
1032The default options for format readers and compression readers.
1033The
1034.Fl Fl options
1035option overrides this.
1036.It Ev TAR_WRITER_OPTIONS
1037The default options for format writers and compression writers.
1038The
1039.Fl Fl options
1040option overrides this.
1041.It Ev LANG
1042The locale to use.
1043See
1044.Xr environ 7
1045for more information.
1046.It Ev TAPE
1047The default device.
1048The
1049.Fl f
1050option overrides this.
1051Please see the description of the
1052.Fl f
1053option above for more details.
1054.It Ev TZ
1055The timezone to use when displaying dates.
1056See
1057.Xr environ 7
1058for more information.
1059.El
1060.Sh EXIT STATUS
1061.Ex -std
1062.Sh EXAMPLES
1063The following creates a new archive
1064called
1065.Ar file.tar.gz
1066that contains two files
1067.Ar source.c
1068and
1069.Ar source.h :
1070.Dl Nm Fl czf Pa file.tar.gz Pa source.c Pa source.h
1071.Pp
1072To view a detailed table of contents for this
1073archive:
1074.Dl Nm Fl tvf Pa file.tar.gz
1075.Pp
1076To extract all entries from the archive on
1077the default tape drive:
1078.Dl Nm Fl x
1079.Pp
1080To examine the contents of an ISO 9660 cdrom image:
1081.Dl Nm Fl tf Pa image.iso
1082.Pp
1083To move file hierarchies, invoke
1084.Nm
1085as
1086.Dl Nm Fl cf Pa - Fl C Pa srcdir \&. | Nm Fl xpf Pa - Fl C Pa destdir
1087or more traditionally
1088.Dl cd srcdir \&; Nm Fl cf Pa - \&. | ( cd destdir \&; Nm Fl xpf Pa - )
1089.Pp
1090In create mode, the list of files and directories to be archived
1091can also include directory change instructions of the form
1092.Cm -C Ns Pa foo/baz
1093and archive inclusions of the form
1094.Cm @ Ns Pa archive-file .
1095For example, the command line
1096.Dl Nm Fl c Fl f Pa new.tar Pa foo1 Cm @ Ns Pa old.tgz Cm -C Ns Pa /tmp Pa foo2
1097will create a new archive
1098.Pa new.tar .
1099.Nm
1100will read the file
1101.Pa foo1
1102from the current directory and add it to the output archive.
1103It will then read each entry from
1104.Pa old.tgz
1105and add those entries to the output archive.
1106Finally, it will switch to the
1107.Pa /tmp
1108directory and add
1109.Pa foo2
1110to the output archive.
1111.Pp
1112An input file in
1113.Xr mtree 5
1114format can be used to create an output archive with arbitrary ownership,
1115permissions, or names that differ from existing data on disk:
1116.Bd -literal -offset indent
1117$ cat input.mtree
1118#mtree
1119usr/bin uid=0 gid=0 mode=0755 type=dir
1120usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls
1121$ tar -cvf output.tar @input.mtree
1122.Ed
1123.Pp
1124The
1125.Fl Fl newer
1126and
1127.Fl Fl newer-mtime
1128switches accept a variety of common date and time specifications, including
1129.Dq 12 Mar 2005 7:14:29pm ,
1130.Dq 2005-03-12 19:14 ,
1131.Dq 5 minutes ago ,
1132and
1133.Dq 19:14 PST May 1 .
1134.Pp
1135The
1136.Fl Fl options
1137argument can be used to control various details of archive generation
1138or reading.
1139For example, you can generate mtree output which only contains
1140.Cm type , Cm time ,
1141and
1142.Cm uid
1143keywords:
1144.Dl Nm Fl cf Pa file.tar Fl Fl format=mtree Fl Fl options='!all,type,time,uid' Pa dir
1145or you can set the compression level used by gzip or xz compression:
1146.Dl Nm Fl czf Pa file.tar Fl Fl options='compression-level=9' .
1147For more details, see the explanation of the
1148.Fn archive_read_set_options
1149and
1150.Fn archive_write_set_options
1151API calls that are described in
1152.Xr archive_read 3
1153and
1154.Xr archive_write 3 .
1155.Sh COMPATIBILITY
1156The bundled-arguments format is supported for compatibility
1157with historic implementations.
1158It consists of an initial word (with no leading - character) in which
1159each character indicates an option.
1160Arguments follow as separate words.
1161The order of the arguments must match the order
1162of the corresponding characters in the bundled command word.
1163For example,
1164.Dl Nm Cm tbf 32 Pa file.tar
1165specifies three flags
1166.Cm t ,
1167.Cm b ,
1168and
1169.Cm f .
1170The
1171.Cm b
1172and
1173.Cm f
1174flags both require arguments,
1175so there must be two additional items
1176on the command line.
1177The
1178.Ar 32
1179is the argument to the
1180.Cm b
1181flag, and
1182.Ar file.tar
1183is the argument to the
1184.Cm f
1185flag.
1186.Pp
1187The mode options c, r, t, u, and x and the options
1188b, f, l, m, o, v, and w comply with SUSv2.
1189.Pp
1190For maximum portability, scripts that invoke
1191.Nm tar
1192should use the bundled-argument format above, should limit
1193themselves to the
1194.Cm c ,
1195.Cm t ,
1196and
1197.Cm x
1198modes, and the
1199.Cm b ,
1200.Cm f ,
1201.Cm m ,
1202.Cm v ,
1203and
1204.Cm w
1205options.
1206.Pp
1207Additional long options are provided to improve compatibility with other
1208tar implementations.
1209.Sh SECURITY
1210Certain security issues are common to many archiving programs, including
1211.Nm .
1212In particular, carefully-crafted archives can request that
1213.Nm
1214extract files to locations outside of the target directory.
1215This can potentially be used to cause unwitting users to overwrite
1216files they did not intend to overwrite.
1217If the archive is being extracted by the superuser, any file
1218on the system can potentially be overwritten.
1219There are three ways this can happen.
1220Although
1221.Nm
1222has mechanisms to protect against each one,
1223savvy users should be aware of the implications:
1224.Bl -bullet -width indent
1225.It
1226Archive entries can have absolute pathnames.
1227By default,
1228.Nm
1229removes the leading
1230.Pa /
1231character from filenames before restoring them to guard against this problem.
1232.It
1233Archive entries can have pathnames that include
1234.Pa ..
1235components.
1236By default,
1237.Nm
1238will not extract files containing
1239.Pa ..
1240components in their pathname.
1241.It
1242Archive entries can exploit symbolic links to restore
1243files to other directories.
1244An archive can restore a symbolic link to another directory,
1245then use that link to restore a file into that directory.
1246To guard against this,
1247.Nm
1248checks each extracted path for symlinks.
1249If the final path element is a symlink, it will be removed
1250and replaced with the archive entry.
1251If
1252.Fl U
1253is specified, any intermediate symlink will also be unconditionally removed.
1254If neither
1255.Fl U
1256nor
1257.Fl P
1258is specified,
1259.Nm
1260will refuse to extract the entry.
1261.El
1262To protect yourself, you should be wary of any archives that
1263come from untrusted sources.
1264You should examine the contents of an archive with
1265.Dl Nm Fl tf Pa filename
1266before extraction.
1267You should use the
1268.Fl k
1269option to ensure that
1270.Nm
1271will not overwrite any existing files or the
1272.Fl U
1273option to remove any pre-existing files.
1274You should generally not extract archives while running with super-user
1275privileges.
1276Note that the
1277.Fl P
1278option to
1279.Nm
1280disables the security checks above and allows you to extract
1281an archive while preserving any absolute pathnames,
1282.Pa ..
1283components, or symlinks to other directories.
1284.Sh SEE ALSO
1285.Xr bzip2 1 ,
1286.Xr compress 1 ,
1287.Xr cpio 1 ,
1288.Xr gzip 1 ,
1289.Xr mt 1 ,
1290.Xr pax 1 ,
1291.Xr shar 1 ,
1292.Xr xz 1 ,
1293.Xr libarchive 3 ,
1294.Xr libarchive-formats 5 ,
1295.Xr tar 5
1296.Sh STANDARDS
1297There is no current POSIX standard for the tar command; it appeared
1298in
1299.St -p1003.1-96
1300but was dropped from
1301.St -p1003.1-2001 .
1302The options supported by this implementation were developed by surveying a
1303number of existing tar implementations as well as the old POSIX specification
1304for tar and the current POSIX specification for pax.
1305.Pp
1306The ustar and pax interchange file formats are defined by
1307.St -p1003.1-2001
1308for the pax command.
1309.Sh HISTORY
1310A
1311.Nm tar
1312command appeared in Seventh Edition Unix, which was released in January, 1979.
1313There have been numerous other implementations,
1314many of which extended the file format.
1315John Gilmore's
1316.Nm pdtar
1317public-domain implementation (circa November, 1987)
1318was quite influential, and formed the basis of GNU tar.
1319GNU tar was included as the standard system tar
1320in
1321.Fx
1322beginning with
1323.Fx 1.0 .
1324.Pp
1325This is a complete re-implementation based on the
1326.Xr libarchive 3
1327library.
1328It was first released with
1329.Fx 5.4
1330in May, 2005.
1331.Sh BUGS
1332This program follows
1333.St -p1003.1-96
1334for the definition of the
1335.Fl l
1336option.
1337Note that GNU tar prior to version 1.15 treated
1338.Fl l
1339as a synonym for the
1340.Fl Fl one-file-system
1341option.
1342.Pp
1343The
1344.Fl C Pa dir
1345option may differ from historic implementations.
1346.Pp
1347All archive output is written in correctly-sized blocks, even
1348if the output is being compressed.
1349Whether or not the last output block is padded to a full
1350block size varies depending on the format and the
1351output device.
1352For tar and cpio formats, the last block of output is padded
1353to a full block size if the output is being
1354written to standard output or to a character or block device such as
1355a tape drive.
1356If the output is being written to a regular file, the last block
1357will not be padded.
1358Many compressors, including
1359.Xr gzip 1
1360and
1361.Xr bzip2 1 ,
1362complain about the null padding when decompressing an archive created by
1363.Nm ,
1364although they still extract it correctly.
1365.Pp
1366The compression and decompression is implemented internally, so
1367there may be insignificant differences between the compressed output
1368generated by
1369.Dl Nm Fl czf Pa - file
1370and that generated by
1371.Dl Nm Fl cf Pa - file | Nm gzip
1372.Pp
1373The default should be to read and write archives to the standard I/O paths,
1374but tradition (and POSIX) dictates otherwise.
1375.Pp
1376The
1377.Cm r
1378and
1379.Cm u
1380modes require that the archive be uncompressed
1381and located in a regular file on disk.
1382Other archives can be modified using
1383.Cm c
1384mode with the
1385.Pa @archive-file
1386extension.
1387.Pp
1388To archive a file called
1389.Pa @foo
1390or
1391.Pa -foo
1392you must specify it as
1393.Pa ./@foo
1394or
1395.Pa ./-foo ,
1396respectively.
1397.Pp
1398In create mode, a leading
1399.Pa ./
1400is always removed.
1401A leading
1402.Pa /
1403is stripped unless the
1404.Fl P
1405option is specified.
1406.Pp
1407There needs to be better support for file selection on both create
1408and extract.
1409.Pp
1410There is not yet any support for multi-volume archives.
1411.Pp
1412Converting between dissimilar archive formats (such as tar and cpio) using the
1413.Cm @ Ns Pa -
1414convention can cause hard link information to be lost.
1415(This is a consequence of the incompatible ways that different archive
1416formats store hardlink information.)
1417