xref: /netbsd/bin/pax/tar.1 (revision 206f4182)
1.\" $NetBSD: tar.1,v 1.25 2007/05/04 21:19:37 christos Exp $
2.\"
3.\" Copyright (c) 1996 SigmaSoft, Th. Lockert
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.\"	OpenBSD: tar.1,v 1.28 2000/11/09 23:58:56 aaron Exp
27.\"
28.Dd May 4, 2007
29.Dt TAR 1
30.Os
31.Sh NAME
32.Nm tar
33.Nd tape archiver
34.Sh SYNOPSIS
35.Nm tar
36.Sm off
37.Oo \&- Oc {crtux} Op Fl befhjklmopqvwzHOPSXZ014578
38.Sm on
39.Op Ar archive
40.Op Ar blocksize
41.\" XXX how to do this right?
42.Op Fl C Ar directory
43.Op Fl T Ar file
44.Op Fl s Ar replstr
45.Op Ar file ...
46.Sh DESCRIPTION
47The
48.Nm
49command creates, adds files to, or extracts files from an
50archive file in
51.Dq tar
52format.
53A tar archive is often stored on a magnetic tape, but can be
54stored equally well on a floppy, CD-ROM, or in a regular disk file.
55.Pp
56One of the following flags must be present:
57.Bl -tag -width Ar
58.It Fl c , -create
59Create new archive, or overwrite an existing archive,
60adding the specified files to it.
61.It Fl r , -append
62Append the named new files to existing archive.
63Note that this will only work on media on which an end-of-file mark
64can be overwritten.
65.It Fl t , -list
66List contents of archive.
67If any files are named on the
68command line, only those files will be listed.
69.It Fl u , -update
70Alias for
71.Fl r .
72.It Fl x , -extract , -get
73Extract files from archive.
74If any files are named on the
75command line, only those files will be extracted from the
76archive.
77If more than one copy of a file exists in the
78archive, later copies will overwrite earlier copies during
79extraction.
80The file mode and modification time are preserved
81if possible.
82The file mode is subject to modification by the
83.Xr umask 2 .
84.El
85.Pp
86In addition to the flags mentioned above, any of the following
87flags may be used:
88.Bl -tag -width Ar
89.It Fl b Ar "blocking factor" , Fl -block-size Ar "blocking factor"
90Set blocking factor to use for the archive.
91.Nm
92uses 512 byte blocks.
93The default is 20, the maximum is 126.
94Archives with a blocking factor larger 63 violate the
95.Tn POSIX
96standard and will not be portable to all systems.
97.It Fl e
98Stop after first error.
99.It Fl f Ar archive , Fl -file Ar archive
100Filename where the archive is stored.
101Defaults to
102.Pa /dev/rst0 .
103If the archive is of the form:
104.Ar [[user@]host:]file
105then the archive will be processed using
106.Xr rmt 8 .
107.It Fl h , -dereference
108Follow symbolic links as if they were normal files
109or directories.
110.It Fl j, -bzip2, -bunzip2
111Use
112.Xr bzip2 1
113for compression of the archive.
114This option is a GNU extension.
115.It Fl k , -keep-old-files
116Keep existing files; don't overwrite them from archive.
117.It Fl l , -one-file-system
118Do not descend across mount points.
119.\" should be '-X'
120.It Fl m , -modification-time
121Do not preserve modification time.
122.It Fl O
123When creating and appending to an archive, write old-style (non-POSIX) archives.
124When extracting from an archive, extract to standard output.
125.It Fl o , -portability , -old-archive
126Don't write directory information that the older (V7) style
127.Nm
128is unable to decode.
129This implies the
130.Fl O
131flag.
132.It Fl p , -preserve-permissions , -preserve
133Preserve user and group ID as well as file mode regardless of
134the current
135.Xr umask 2 .
136The setuid and setgid bits are only preserved if the user is
137the superuser.
138Only meaningful in conjunction with the
139.Fl x
140flag.
141.It Fl q , -fast-read
142Select the first archive member that matches each
143.Ar pattern
144operand.
145No more than one archive member is matched for each
146.Ar pattern .
147When members of type directory are matched, the file hierarchy rooted at that
148directory is also matched.
149.It Fl S , -sparse
150This flag has no effect as
151.Nm
152always generates sparse files.
153.It Fl s Ar replstr
154Modify the file or archive member names specified by the
155.Ar pattern
156or
157.Ar file
158operands according to the substitution expression
159.Ar replstr ,
160using the syntax of the
161.Xr ed 1
162utility regular expressions.
163The format of these regular expressions are:
164.Dl /old/new/[gps]
165As in
166.Xr ed 1 ,
167.Cm old
168is a basic regular expression and
169.Cm new
170can contain an ampersand (\*[Am]), \\n (where n is a digit) back-references,
171or subexpression matching.
172The
173.Cm old
174string may also contain
175.Aq Dv newline
176characters.
177Any non-null character can be used as a delimiter (/ is shown here).
178Multiple
179.Fl s
180expressions can be specified.
181The expressions are applied in the order they are specified on the
182command line, terminating with the first successful substitution.
183The optional trailing
184.Cm g
185continues to apply the substitution expression to the pathname substring
186which starts with the first character following the end of the last successful
187substitution.
188The first unsuccessful substitution stops the operation of the
189.Cm g
190option.
191The optional trailing
192.Cm p
193will cause the final result of a successful substitution to be written to
194.Dv standard error
195in the following format:
196.Dl \*[Lt]original pathname\*[Gt] \*[Gt]\*[Gt] \*[Lt]new pathname\*[Gt]
197File or archive member names that substitute to the empty string
198are not selected and will be skipped.
199The substitutions are applied by default to the destination hard and symbolic
200links. The optional trailing
201.Cm s
202prevents the substitutions from being performed on symbolic link destinations.
203.It Fl v
204Verbose operation mode.
205.It Fl w , -interactive , -confirmation
206Interactively rename files.
207This option causes
208.Nm
209to prompt the user for the filename to use when storing or
210extracting files in an archive.
211.It Fl z , -gzip , -gunzip
212Compress archive using gzip.
213.It Fl B , -read-full-blocks
214Reassemble small reads into full blocks (For reading from 4.2BSD pipes).
215.It Fl C Ar directory , Fl -directory Ar directory
216This is a positional argument which sets the working directory for the
217following files.
218When extracting, files will be extracted into
219the specified directory; when creating, the specified files will be matched
220from the directory.
221This argument and its parameter may also appear in a file list specified by
222.Fl T .
223.It Fl H
224Only follow symlinks given on command line.
225.Pp
226Note SysVr3/i386 picked up ISC/SCO UNIX compatabilty which implemented
227.Dq Fl F Ar file
228which was defined as obtaining a list of command line switches and files
229on which to operate from the specified file,
230but SunOS-5 uses
231.Dq Fl I Ar file
232because they use
233.Sq Fl F
234to mean something else.  We might someday provide SunOS-5 compatability
235but it makes little sense to confuse things with ISC/SCO compatability.
236.\".It Fl L
237.\"Do not follow any symlinks (do the opposite of
238.\".Fl h ).
239.It Fl P , -absolute-paths
240Do not strip leading slashes
241.Pq Sq /
242from pathnames.
243The default is to strip leading slashes.
244.It Fl T Ar file , Fl -files-from Ar file
245Read the names of files to archive or extract from the given file, one
246per line.
247A line may also specify the positional argument
248.Dq Fl C Ar directory .
249.It Fl X Ar file , Fl -exclude-from Ar file
250Exclude files listed in the given file.
251.\" exclude should be '-E' and '-X' should be one-file-system
252.Pp
253Note that it would be more standard to use this option to mean ``do not
254cross filesystem mount points.''
255.It Fl Z , -compress , -uncompress
256Compress archive using compress.
257.It Fl -strict
258Do not enable GNU tar extensions such as long filenames and long link names.
259.It Fl -atime-preserve
260Preserve file access times.
261.It Fl -chroot
262.Fn chroot
263to the current directory before extracting files.
264Use with
265.Fl x
266and
267.Fl h
268to make absolute symlinks relative to the current directory.
269.It Fl -unlink
270Ignored, only accepted for compatibility with other
271.Nm
272implementations.
273.Nm
274always unlinks files before creating them.
275.It Fl -use-compress-program Ar program
276Use the named program as the program to decompress the input.
277.It Fl -force-local
278Do not interpret filenames that contain a
279.Sq \&:
280as remote files.
281.It Fl -insecure
282Normally
283.Nm
284ignores filenames that contain
285.Sq ..
286as a path component.
287With this option, files that contain
288.Sq ..
289can be processed.
290.It Fl -no-recursion
291Cause files of type directory being copied or archived, or archive members of
292type directory being extracted, to match only the directory file or archive
293member and not the file hierarchy rooted at the directory.
294.El
295.Pp
296The options
297.Op Fl 014578
298can be used to select one of the compiled-in backup devices,
299.Pa /dev/rstN .
300.Sh FILES
301.Bl -tag -width "/dev/rst0"
302.It Pa /dev/rst0
303default archive name
304.El
305.Sh DIAGNOSTICS
306.Nm
307will exit with one of the following values:
308.Bl -tag -width 2n
309.It 0
310All files were processed successfully.
311.It 1
312An error occurred.
313.El
314.Pp
315Whenever
316.Nm
317cannot create a file or a link when extracting an archive or cannot
318find a file while writing an archive, or cannot preserve the user
319ID, group ID, file mode, or access and modification times when the
320.Fl p
321option is specified, a diagnostic message is written to standard
322error and a non-zero exit value will be returned, but processing
323will continue.
324In the case where
325.Nm
326cannot create a link to a file,
327.Nm
328will not create a second copy of the file.
329.Pp
330If the extraction of a file from an archive is prematurely terminated
331by a signal or error,
332.Nm
333may have only partially extracted the file the user wanted.
334Additionally, the file modes of extracted files and directories may
335have incorrect file bits, and the modification and access times may
336be wrong.
337.Pp
338If the creation of an archive is prematurely terminated by a signal
339or error,
340.Nm
341may have only partially created the archive which may violate the
342specific archive format specification.
343.Sh SEE ALSO
344.Xr cpio 1 ,
345.Xr pax 1
346.Sh HISTORY
347A
348.Nm
349command first appeared in
350.At v7 .
351.Sh AUTHORS
352Keith Muller at the University of California, San Diego.
353