xref: /netbsd/bin/pax/tar.1 (revision 2fa09966)
1.\" $NetBSD: tar.1,v 1.15 2004/09/15 19:45:17 hubertf 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, 2004
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 befhjklmopqvwzHLOPXZ014578
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 cross filesystems.
119.It Fl m , -modification-time
120Do not preserve modification time.
121.It Fl O
122When creating and appending to an archive, write old-style (non-POSIX) archives.
123When extracting from an archive, extract to standard output.
124.It Fl o , -portability , -old-archive
125Don't write directory information that the older (V7) style
126.Nm
127is unable to decode.
128This implies the
129.Fl O
130flag.
131.It Fl p , -preserve-permissions , -preserve
132Preserve user and group ID as well as file mode regardless of
133the current
134.Xr umask 2 .
135The setuid and setgid bits are only preserved if the user is
136the superuser.
137Only meaningful in conjunction with the
138.Fl x
139flag.
140.It Fl q , -fast-read
141Select the first archive member that matches each
142.Ar pattern
143operand.
144No more than one archive member is matched for each
145.Ar pattern .
146When members of type directory are matched, the file hierarchy rooted at that
147directory is also matched.
148.It Fl s Ar replstr
149Modify the file or archive member names specified by the
150.Ar pattern
151or
152.Ar file
153operands according to the substitution expression
154.Ar replstr ,
155using the syntax of the
156.Xr ed 1
157utility regular expressions.
158The format of these regular expressions are:
159.Dl /old/new/[gp]
160As in
161.Xr ed 1 ,
162.Cm old
163is a basic regular expression and
164.Cm new
165can contain an ampersand (\*[Am]), \\n (where n is a digit) back-references,
166or subexpression matching.
167The
168.Cm old
169string may also contain
170.Aq Dv newline
171characters.
172Any non-null character can be used as a delimiter (/ is shown here).
173Multiple
174.Fl s
175expressions can be specified.
176The expressions are applied in the order they are specified on the
177command line, terminating with the first successful substitution.
178The optional trailing
179.Cm g
180continues to apply the substitution expression to the pathname substring
181which starts with the first character following the end of the last successful
182substitution.
183The first unsuccessful substitution stops the operation of the
184.Cm g
185option.
186The optional trailing
187.Cm p
188will cause the final result of a successful substitution to be written to
189.Dv standard error
190in the following format:
191.Dl \*[Lt]original pathname\*[Gt] \*[Gt]\*[Gt] \*[Lt]new pathname\*[Gt]
192File or archive member names that substitute to the empty string
193are not selected and will be skipped.
194.It Fl v
195Verbose operation mode.
196.It Fl w , -interactive , -confirmation
197Interactively rename files.
198This option causes
199.Nm
200to prompt the user for the filename to use when storing or
201extracting files in an archive.
202.It Fl z , -gzip , -gunzip
203Compress archive using gzip.
204.It Fl B , -read-full-blocks
205Reassemble small reads into full blocks (For reading from 4.2BSD pipes).
206.It Fl C Ar directory , Fl -directory Ar directory
207This is a positional argument which sets the working directory for the
208following files.
209When extracting, files will be extracted into
210the specified directory; when creating, the specified files will be matched
211from the directory.
212This argument and its parameter may also appear in a file list specified by
213.Fl T .
214.It Fl H
215Follow symlinks given on command line only.
216.It Fl P , -absolute-paths
217Do not strip leading slashes
218.Pq Sq /
219from pathnames.
220The default is to strip leading slashes.
221.It Fl T Ar file , Fl -files-from Ar file
222Read the names of files to archive or extract from the given file, one
223per line.
224A line may also specify the positional argument
225.Dq Fl C Ar directory .
226.It Fl X Ar file , Fl -exclude-from Ar file
227Exclude files listed in the given file.
228.It Fl Z , -compress , -uncompress
229Compress archive using compress.
230.It Fl -strict
231Do not enable GNU tar extensions such as long filenames and long link names.
232.It Fl -atime-preserve
233Preserve file access times.
234.It Fl -unlink
235Ignored, only accepted for compatibility with other
236.Nm
237implementations.
238.Nm
239always unlinks files before creating them.
240.It Fl -use-compress-program Ar program
241Use the named program as the program to decompress the input.
242.It Fl -force-local
243Do not interpret filenames that contain a
244.Sq \&:
245as remote files.
246.It Fl -insecure
247Normally
248.Nm
249ignores filenames that contain
250.Sq ..
251as a path component.
252With this option, files that contain
253.Sq ..
254can be processed.
255.El
256.Pp
257The options
258.Op Fl 014578
259can be used to select one of the compiled-in backup devices,
260.Pa /dev/rstN .
261.Sh FILES
262.Bl -tag -width "/dev/rst0"
263.It Pa /dev/rst0
264default archive name
265.El
266.Sh DIAGNOSTICS
267.Nm
268will exit with one of the following values:
269.Bl -tag -width 2n
270.It 0
271All files were processed successfully.
272.It 1
273An error occurred.
274.El
275.Pp
276Whenever
277.Nm
278cannot create a file or a link when extracting an archive or cannot
279find a file while writing an archive, or cannot preserve the user
280ID, group ID, file mode, or access and modification times when the
281.Fl p
282option is specified, a diagnostic message is written to standard
283error and a non-zero exit value will be returned, but processing
284will continue.
285In the case where
286.Nm
287cannot create a link to a file,
288.Nm
289will not create a second copy of the file.
290.Pp
291If the extraction of a file from an archive is prematurely terminated
292by a signal or error,
293.Nm
294may have only partially extracted the file the user wanted.
295Additionally, the file modes of extracted files and directories may
296have incorrect file bits, and the modification and access times may
297be wrong.
298.Pp
299If the creation of an archive is prematurely terminated by a signal
300or error,
301.Nm
302may have only partially created the archive which may violate the
303specific archive format specification.
304.Sh SEE ALSO
305.Xr cpio 1 ,
306.Xr pax 1
307.Sh HISTORY
308A
309.Nm
310command first appeared in
311.At v7 .
312.Sh AUTHORS
313Keith Muller at the University of California, San Diego.
314