xref: /netbsd-src/bin/pax/tar.1 (revision c9960b6dc598d5022854141d48103e779c1bf825)
1*c9960b6dSwiz.\" $NetBSD: tar.1,v 1.39 2019/03/19 10:14:46 wiz Exp $
2b73dcc21Schristos.\"
3b73dcc21Schristos.\" Copyright (c) 1996 SigmaSoft, Th. Lockert
4b73dcc21Schristos.\" All rights reserved.
5b73dcc21Schristos.\"
6b73dcc21Schristos.\" Redistribution and use in source and binary forms, with or without
7b73dcc21Schristos.\" modification, are permitted provided that the following conditions
8b73dcc21Schristos.\" are met:
9b73dcc21Schristos.\" 1. Redistributions of source code must retain the above copyright
10b73dcc21Schristos.\"    notice, this list of conditions and the following disclaimer.
11b73dcc21Schristos.\" 2. Redistributions in binary form must reproduce the above copyright
12b73dcc21Schristos.\"    notice, this list of conditions and the following disclaimer in the
13b73dcc21Schristos.\"    documentation and/or other materials provided with the distribution.
14b73dcc21Schristos.\"
15b73dcc21Schristos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16b73dcc21Schristos.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17b73dcc21Schristos.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18b73dcc21Schristos.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19b73dcc21Schristos.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20b73dcc21Schristos.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21b73dcc21Schristos.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22b73dcc21Schristos.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23b73dcc21Schristos.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24b73dcc21Schristos.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25b73dcc21Schristos.\"
26b73dcc21Schristos.\"	OpenBSD: tar.1,v 1.28 2000/11/09 23:58:56 aaron Exp
27b73dcc21Schristos.\"
28b96bf3b0Sgutteridge.Dd March 19, 2019
29b73dcc21Schristos.Dt TAR 1
30b73dcc21Schristos.Os
31b73dcc21Schristos.Sh NAME
32b73dcc21Schristos.Nm tar
33b73dcc21Schristos.Nd tape archiver
34b73dcc21Schristos.Sh SYNOPSIS
35b73dcc21Schristos.Nm tar
36b73dcc21Schristos.Sm off
3723c362a5Schristos.Oo \&- Oc {crtux} Op Fl 014578befHhJjklmOoPpqSvwXZz
38b73dcc21Schristos.Sm on
39b73dcc21Schristos.Op Ar archive
40b73dcc21Schristos.Op Ar blocksize
41b73dcc21Schristos.\" XXX how to do this right?
42b73dcc21Schristos.Op Fl C Ar directory
43b73dcc21Schristos.Op Fl s Ar replstr
4473f0c105Swiz.Op Fl T Ar file
45b73dcc21Schristos.Op Ar file ...
46b73dcc21Schristos.Sh DESCRIPTION
47b73dcc21SchristosThe
48b73dcc21Schristos.Nm
49b73dcc21Schristoscommand creates, adds files to, or extracts files from an
50b73dcc21Schristosarchive file in
51b73dcc21Schristos.Dq tar
52eb12ddd1Swizformat.
53eb12ddd1SwizA tar archive is often stored on a magnetic tape, but can be
54b73dcc21Schristosstored equally well on a floppy, CD-ROM, or in a regular disk file.
55b73dcc21Schristos.Pp
56b73dcc21SchristosOne of the following flags must be present:
57b73dcc21Schristos.Bl -tag -width Ar
581824f8a2Swiz.It Fl c , Fl Fl create
59b73dcc21SchristosCreate new archive, or overwrite an existing archive,
60b73dcc21Schristosadding the specified files to it.
611824f8a2Swiz.It Fl r , Fl Fl append
62b73dcc21SchristosAppend the named new files to existing archive.
63b73dcc21SchristosNote that this will only work on media on which an end-of-file mark
64b73dcc21Schristoscan be overwritten.
651824f8a2Swiz.It Fl t , Fl Fl list
66b73dcc21SchristosList contents of archive.
67b73dcc21SchristosIf any files are named on the
68b73dcc21Schristoscommand line, only those files will be listed.
691824f8a2Swiz.It Fl u , Fl Fl update
70b73dcc21SchristosAlias for
71b73dcc21Schristos.Fl r .
721824f8a2Swiz.It Fl x , Fl Fl extract , Fl Fl get
73b73dcc21SchristosExtract files from archive.
74b73dcc21SchristosIf any files are named on the
75b73dcc21Schristoscommand line, only those files will be extracted from the
76b73dcc21Schristosarchive.
77b73dcc21SchristosIf more than one copy of a file exists in the
78b73dcc21Schristosarchive, later copies will overwrite earlier copies during
79b73dcc21Schristosextraction.
80b73dcc21SchristosThe file mode and modification time are preserved
81b73dcc21Schristosif possible.
82b73dcc21SchristosThe file mode is subject to modification by the
83b73dcc21Schristos.Xr umask 2 .
84b73dcc21Schristos.El
85b73dcc21Schristos.Pp
86b73dcc21SchristosIn addition to the flags mentioned above, any of the following
87b73dcc21Schristosflags may be used:
88b73dcc21Schristos.Bl -tag -width Ar
891824f8a2Swiz.It Fl b Ar "blocking factor" , Fl Fl block-size Ar "blocking factor"
90b73dcc21SchristosSet blocking factor to use for the archive.
91b73dcc21Schristos.Nm
92b73dcc21Schristosuses 512 byte blocks.
93b73dcc21SchristosThe default is 20, the maximum is 126.
94b73dcc21SchristosArchives with a blocking factor larger 63 violate the
95b73dcc21Schristos.Tn POSIX
96b73dcc21Schristosstandard and will not be portable to all systems.
97b73dcc21Schristos.It Fl e
98b73dcc21SchristosStop after first error.
991824f8a2Swiz.It Fl f Ar archive , Fl Fl file Ar archive
100b73dcc21SchristosFilename where the archive is stored.
101b73dcc21SchristosDefaults to
102b73dcc21Schristos.Pa /dev/rst0 .
10324dd1a7dSchristosIf the archive is of the form:
10424dd1a7dSchristos.Ar [[user@]host:]file
10524dd1a7dSchristosthen the archive will be processed using
10624dd1a7dSchristos.Xr rmt 8 .
1071824f8a2Swiz.It Fl h , Fl Fl dereference
108b73dcc21SchristosFollow symbolic links as if they were normal files
109b73dcc21Schristosor directories.
11023c362a5Schristos.It Fl J , Fl Fl xz
11123c362a5SchristosCompress/decompress archive using
11223c362a5Schristos.Xr xz 1 .
1131824f8a2Swiz.It Fl j , Fl Fl bzip2 , Fl Fl bunzip2
114e04df3a3SwizUse
115e04df3a3Swiz.Xr bzip2 1
116e04df3a3Swizfor compression of the archive.
117e04df3a3SwizThis option is a GNU extension.
1181824f8a2Swiz.It Fl k , Fl Fl keep-old-files
119c8921f64SchristosKeep existing files; don't overwrite them from archive.
1201824f8a2Swiz.It Fl l , Fl Fl one-file-system
121702d1ca5SchristosDo not descend across mount points.
122702d1ca5Schristos.\" should be '-X'
1231824f8a2Swiz.It Fl m , Fl Fl modification-time
124b73dcc21SchristosDo not preserve modification time.
125b73dcc21Schristos.It Fl O
1261301238aSsimonbWhen creating and appending to an archive, write old-style (non-POSIX) archives.
1271301238aSsimonbWhen extracting from an archive, extract to standard output.
1281824f8a2Swiz.It Fl o , Fl Fl portability , Fl Fl old-archive
129b73dcc21SchristosDon't write directory information that the older (V7) style
130b73dcc21Schristos.Nm
131b73dcc21Schristosis unable to decode.
132b73dcc21SchristosThis implies the
133b73dcc21Schristos.Fl O
134b73dcc21Schristosflag.
1351824f8a2Swiz.It Fl p , Fl Fl preserve-permissions , Fl Fl preserve
136b73dcc21SchristosPreserve user and group ID as well as file mode regardless of
137b73dcc21Schristosthe current
138b73dcc21Schristos.Xr umask 2 .
139b73dcc21SchristosThe setuid and setgid bits are only preserved if the user is
140b73dcc21Schristosthe superuser.
141b73dcc21SchristosOnly meaningful in conjunction with the
142b73dcc21Schristos.Fl x
143b73dcc21Schristosflag.
1441824f8a2Swiz.It Fl q , Fl Fl fast-read
145b73dcc21SchristosSelect the first archive member that matches each
146b73dcc21Schristos.Ar pattern
147b73dcc21Schristosoperand.
148b73dcc21SchristosNo more than one archive member is matched for each
149b73dcc21Schristos.Ar pattern .
150b73dcc21SchristosWhen members of type directory are matched, the file hierarchy rooted at that
151b73dcc21Schristosdirectory is also matched.
1521824f8a2Swiz.It Fl S , Fl Fl sparse
15360cf1998SchristosThis flag has no effect as
15460cf1998Schristos.Nm
15560cf1998Schristosalways generates sparse files.
156b73dcc21Schristos.It Fl s Ar replstr
157b73dcc21SchristosModify the file or archive member names specified by the
158b73dcc21Schristos.Ar pattern
159b73dcc21Schristosor
160b73dcc21Schristos.Ar file
161b73dcc21Schristosoperands according to the substitution expression
162b73dcc21Schristos.Ar replstr ,
163b73dcc21Schristosusing the syntax of the
164b73dcc21Schristos.Xr ed 1
165b73dcc21Schristosutility regular expressions.
166b73dcc21SchristosThe format of these regular expressions are:
167206f4182Schristos.Dl /old/new/[gps]
168b73dcc21SchristosAs in
169b73dcc21Schristos.Xr ed 1 ,
170b73dcc21Schristos.Cm old
171b73dcc21Schristosis a basic regular expression and
172b73dcc21Schristos.Cm new
17301869ca4Swizcan contain an ampersand (&), \en (where n is a digit) back-references,
174b73dcc21Schristosor subexpression matching.
175b73dcc21SchristosThe
176b73dcc21Schristos.Cm old
177b73dcc21Schristosstring may also contain
178eb12ddd1Swiz.Aq Dv newline
179b73dcc21Schristoscharacters.
180b96bf3b0SgutteridgeAny non-null character except a backslash (\\) can be used as a delimiter
181b96bf3b0Sgutteridge(/ is shown here).
182b73dcc21SchristosMultiple
183b73dcc21Schristos.Fl s
184b73dcc21Schristosexpressions can be specified.
185b73dcc21SchristosThe expressions are applied in the order they are specified on the
186b73dcc21Schristoscommand line, terminating with the first successful substitution.
187b73dcc21SchristosThe optional trailing
188b73dcc21Schristos.Cm g
189b73dcc21Schristoscontinues to apply the substitution expression to the pathname substring
190b73dcc21Schristoswhich starts with the first character following the end of the last successful
191b73dcc21Schristossubstitution.
192b73dcc21SchristosThe first unsuccessful substitution stops the operation of the
193b73dcc21Schristos.Cm g
194b73dcc21Schristosoption.
195b73dcc21SchristosThe optional trailing
196b73dcc21Schristos.Cm p
197b73dcc21Schristoswill cause the final result of a successful substitution to be written to
198b73dcc21Schristos.Dv standard error
199b73dcc21Schristosin the following format:
200b96bf3b0Sgutteridge.Dl Ao "original pathname" Ac >> Ao "new pathname" Ac
201b73dcc21SchristosFile or archive member names that substitute to the empty string
202b73dcc21Schristosare not selected and will be skipped.
203206f4182SchristosThe substitutions are applied by default to the destination hard and symbolic
20473f0c105Swizlinks.
20573f0c105SwizThe optional trailing
206206f4182Schristos.Cm s
207206f4182Schristosprevents the substitutions from being performed on symbolic link destinations.
208b73dcc21Schristos.It Fl v
209b73dcc21SchristosVerbose operation mode.
2101824f8a2Swiz.It Fl w , Fl Fl interactive , Fl Fl confirmation
211b73dcc21SchristosInteractively rename files.
212b73dcc21SchristosThis option causes
213b73dcc21Schristos.Nm
214b73dcc21Schristosto prompt the user for the filename to use when storing or
215b73dcc21Schristosextracting files in an archive.
2161824f8a2Swiz.It Fl z , Fl Fl gzip , Fl Fl gunzip
2179f641b5cSchristosCompress/decompress archive using
2189f641b5cSchristos.Xr gzip 1 .
2191824f8a2Swiz.It Fl B , Fl Fl read-full-blocks
22024dd1a7dSchristosReassemble small reads into full blocks (For reading from 4.2BSD pipes).
2211824f8a2Swiz.It Fl C Ar directory , Fl Fl directory Ar directory
222b73dcc21SchristosThis is a positional argument which sets the working directory for the
223b73dcc21Schristosfollowing files.
224b73dcc21SchristosWhen extracting, files will be extracted into
225b73dcc21Schristosthe specified directory; when creating, the specified files will be matched
226b73dcc21Schristosfrom the directory.
227b73dcc21SchristosThis argument and its parameter may also appear in a file list specified by
228b73dcc21Schristos.Fl T .
229b73dcc21Schristos.It Fl H
230702d1ca5SchristosOnly follow symlinks given on command line.
231702d1ca5Schristos.Pp
23223ba00dbSdhollandNote SysVr3/i386 picked up ISC/SCO UNIX compatibility which implemented
233702d1ca5Schristos.Dq Fl F Ar file
234702d1ca5Schristoswhich was defined as obtaining a list of command line switches and files
235702d1ca5Schristoson which to operate from the specified file,
236702d1ca5Schristosbut SunOS-5 uses
237702d1ca5Schristos.Dq Fl I Ar file
238702d1ca5Schristosbecause they use
239702d1ca5Schristos.Sq Fl F
24073f0c105Swizto mean something else.
24123ba00dbSdhollandWe might someday provide SunOS-5 compatibility
24223ba00dbSdhollandbut it makes little sense to confuse things with ISC/SCO compatibility.
243702d1ca5Schristos.\".It Fl L
244702d1ca5Schristos.\"Do not follow any symlinks (do the opposite of
245702d1ca5Schristos.\".Fl h ).
2461824f8a2Swiz.It Fl P , Fl Fl absolute-paths
247b73dcc21SchristosDo not strip leading slashes
248b73dcc21Schristos.Pq Sq /
249b73dcc21Schristosfrom pathnames.
250b73dcc21SchristosThe default is to strip leading slashes.
2511824f8a2Swiz.It Fl T Ar file , Fl Fl files-from Ar file
252b73dcc21SchristosRead the names of files to archive or extract from the given file, one
253b73dcc21Schristosper line.
254b73dcc21SchristosA line may also specify the positional argument
255b73dcc21Schristos.Dq Fl C Ar directory .
2561824f8a2Swiz.It Fl X Ar file , Fl Fl exclude-from Ar file
257bf1e7b50SdhollandExclude files matching the shell glob patterns listed in the given file.
258702d1ca5Schristos.\" exclude should be '-E' and '-X' should be one-file-system
259702d1ca5Schristos.Pp
260702d1ca5SchristosNote that it would be more standard to use this option to mean ``do not
261702d1ca5Schristoscross filesystem mount points.''
2621824f8a2Swiz.It Fl Z , Fl Fl compress , Fl Fl uncompress
263b73dcc21SchristosCompress archive using compress.
2641824f8a2Swiz.It Fl Fl strict
26524dd1a7dSchristosDo not enable GNU tar extensions such as long filenames and long link names.
2661824f8a2Swiz.It Fl Fl atime-preserve
26724dd1a7dSchristosPreserve file access times.
2681824f8a2Swiz.It Fl Fl chroot
2698317fe12Sdsl.Fn chroot
2708317fe12Sdslto the current directory before extracting files.
2718317fe12SdslUse with
2728317fe12Sdsl.Fl x
2738317fe12Sdsland
2748317fe12Sdsl.Fl h
2757faf3dc4Swizto make absolute symlinks relative to the current directory.
2761824f8a2Swiz.It Fl Fl unlink
277dced68e8SgrantIgnored, only accepted for compatibility with other
278dced68e8Sgrant.Nm
279dced68e8Sgrantimplementations.
280dced68e8Sgrant.Nm
281dced68e8Sgrantalways unlinks files before creating them.
2821824f8a2Swiz.It Fl Fl use-compress-program Ar program
28324dd1a7dSchristosUse the named program as the program to decompress the input.
2841824f8a2Swiz.It Fl Fl force-local
285900b115eSgrantDo not interpret filenames that contain a
286900b115eSgrant.Sq \&:
287900b115eSgrantas remote files.
2881824f8a2Swiz.It Fl Fl insecure
28924dd1a7dSchristosNormally
29024dd1a7dSchristos.Nm
291900b115eSgrantignores filenames that contain
29273f0c105Swiz.Dq ..
293900b115eSgrantas a path component.
294900b115eSgrantWith this option, files that contain
29573f0c105Swiz.Dq ..
296900b115eSgrantcan be processed.
2971824f8a2Swiz.It Fl Fl no-recursion
2988dcba567SchristosCause files of type directory being copied or archived, or archive members of
2998dcba567Schristostype directory being extracted, to match only the directory file or archive
3008dcba567Schristosmember and not the file hierarchy rooted at the directory.
3019158fb65Schristos.It Fl Fl timestamp Ar timestamp
3029158fb65SchristosStore all modification times in the archive with the
3039158fb65Schristos.Ar timestamp
3049158fb65Schristosgiven instead of the actual modification time of the individual archive member
3059158fb65Schristosso that repeatable builds are possible.
3069158fb65SchristosThe
3079158fb65Schristos.Ar timestamp
3089158fb65Schristoscan be a
3099158fb65Schristos.Pa pathname ,
3109158fb65Schristoswhere the timestamps are derived from that file, a parseable date for
3119158fb65Schristos.Xr parsedate 3
3129158fb65Schristos(this option is not yet available in the tools build), or an integer value
3139158fb65Schristosinterpreted as the number of seconds from the Epoch.
314b73dcc21Schristos.El
315b73dcc21Schristos.Pp
316b73dcc21SchristosThe options
317b73dcc21Schristos.Op Fl 014578
318b73dcc21Schristoscan be used to select one of the compiled-in backup devices,
319b73dcc21Schristos.Pa /dev/rstN .
320eb12ddd1Swiz.Sh FILES
321eb12ddd1Swiz.Bl -tag -width "/dev/rst0"
322eb12ddd1Swiz.It Pa /dev/rst0
323eb12ddd1Swizdefault archive name
324eb12ddd1Swiz.El
325b73dcc21Schristos.Sh DIAGNOSTICS
326b73dcc21Schristos.Nm
327b73dcc21Schristoswill exit with one of the following values:
328b73dcc21Schristos.Bl -tag -width 2n
329b73dcc21Schristos.It 0
330b73dcc21SchristosAll files were processed successfully.
331b73dcc21Schristos.It 1
332b73dcc21SchristosAn error occurred.
333b73dcc21Schristos.El
334b73dcc21Schristos.Pp
335b73dcc21SchristosWhenever
336b73dcc21Schristos.Nm
337b73dcc21Schristoscannot create a file or a link when extracting an archive or cannot
338b73dcc21Schristosfind a file while writing an archive, or cannot preserve the user
339b73dcc21SchristosID, group ID, file mode, or access and modification times when the
340b73dcc21Schristos.Fl p
341b73dcc21Schristosoption is specified, a diagnostic message is written to standard
342b73dcc21Schristoserror and a non-zero exit value will be returned, but processing
343b73dcc21Schristoswill continue.
344b73dcc21SchristosIn the case where
345b73dcc21Schristos.Nm
346b73dcc21Schristoscannot create a link to a file,
347b73dcc21Schristos.Nm
348b73dcc21Schristoswill not create a second copy of the file.
349b73dcc21Schristos.Pp
350b73dcc21SchristosIf the extraction of a file from an archive is prematurely terminated
351b73dcc21Schristosby a signal or error,
352b73dcc21Schristos.Nm
353b73dcc21Schristosmay have only partially extracted the file the user wanted.
354b73dcc21SchristosAdditionally, the file modes of extracted files and directories may
355b73dcc21Schristoshave incorrect file bits, and the modification and access times may
356b73dcc21Schristosbe wrong.
357b73dcc21Schristos.Pp
358b73dcc21SchristosIf the creation of an archive is prematurely terminated by a signal
359b73dcc21Schristosor error,
360b73dcc21Schristos.Nm
361b73dcc21Schristosmay have only partially created the archive which may violate the
362b73dcc21Schristosspecific archive format specification.
363b73dcc21Schristos.Sh SEE ALSO
364b73dcc21Schristos.Xr cpio 1 ,
365b73dcc21Schristos.Xr pax 1
366b73dcc21Schristos.Sh HISTORY
367b73dcc21SchristosA
368b73dcc21Schristos.Nm
369b73dcc21Schristoscommand first appeared in
370b73dcc21Schristos.At v7 .
371eb12ddd1Swiz.Sh AUTHORS
3725fe5275dSwiz.An Keith Muller
3735fe5275dSwizat the University of California, San Diego.
374