apply new hurd patch to my tree
[debian/pax] / tar.1
1 .\"     $OpenBSD: tar.1,v 1.51 2008/12/27 13:35:34 sobrado 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.51 2008/12/27 13:35:34 sobrado Exp $
27 .\"
28 .Dd $Mdocdate: December 27 2008 $
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 .No { Cm crtux No } Op Cm 014578befHhjLmOoPpqsvwXZz
38 .Sm on
39 .Bk -words
40 .Op Ar blocking-factor | archive | replstr
41 .Op Fl C Ar directory
42 .Op Fl I Ar file
43 .Op Ar
44 .Ek
45 .Nm tar
46 .No { Ns Fl crtux Ns }
47 .Bk -words
48 .Op Fl 014578eHhjLmOoPpqvwXZz
49 .Op Fl b Ar blocking-factor
50 .Op Fl C Ar directory
51 .Op Fl f Ar archive
52 .Op Fl I Ar file
53 .Op Fl s Ar replstr
54 .Op Ar
55 .Ek
56 .Sh DESCRIPTION
57 The
58 .Nm
59 command creates, adds files to, or extracts files from an
60 archive file in
61 .Dq tar
62 format.
63 A tar archive is often stored on a magnetic tape, but can be
64 stored equally well on a floppy, CD-ROM, or in a regular disk file.
65 .Pp
66 In the first (legacy) form, all option flags except for
67 .Fl C
68 and
69 .Fl I
70 must be contained within the first argument to
71 .Nm
72 and must not be prefixed by a hyphen
73 .Pq Sq - .
74 Option arguments, if any, are processed as subsequent arguments to
75 .Nm
76 and are processed in the order in which their corresponding option
77 flags have been presented on the command line.
78 .Pp
79 In the second and preferred form, option flags may be given in any order
80 and are immediately followed by their corresponding option argument
81 values.
82 .Pp
83 One of the following flags must be present:
84 .Bl -tag -width Ds
85 .It Fl c
86 Create new archive, or overwrite an existing archive,
87 adding the specified files to it.
88 .It Fl r
89 Append the named new files to existing archive.
90 Note that this will only work on media on which an end-of-file mark
91 can be overwritten.
92 .It Fl t
93 List contents of archive.
94 If any files are named on the
95 command line, only those files will be listed.
96 The
97 .Ar file
98 arguments may be specified as glob patterns (see
99 .Xr glob 3
100 for more information), in which case
101 .Nm
102 will list all archive members that match each pattern.
103 .It Fl u
104 Alias for
105 .Fl r .
106 .It Fl x
107 Extract files from archive.
108 If any files are named on the
109 command line, only those files will be extracted from the
110 archive.
111 The
112 .Ar file
113 arguments may be specified as glob patterns (see
114 .Xr glob 3
115 for more information), in which case
116 .Nm
117 will extract all archive members that match each pattern.
118 .Pp
119 If more than one copy of a file exists in the
120 archive, later copies will overwrite earlier copies during
121 extraction.
122 The file mode and modification time are preserved
123 if possible.
124 The file mode is subject to modification by the
125 .Xr umask 2 .
126 .El
127 .Pp
128 In addition to the flags mentioned above, any of the following
129 flags may be used:
130 .Bl -tag -width Ds
131 .It Fl b Ar blocking-factor
132 Set blocking factor to use for the archive.
133 .Nm
134 uses 512-byte blocks.
135 The default is 20, the maximum is 126.
136 Archives with a blocking factor larger than 63 violate the
137 .Tn POSIX
138 standard and will not be portable to all systems.
139 .It Fl C Ar directory
140 This is a positional argument which sets the working directory for the
141 following files.
142 When extracting, files will be extracted into
143 the specified directory; when creating, the specified files will be matched
144 from the directory.
145 .It Fl e
146 Stop after the first error.
147 .It Fl f Ar archive
148 Filename where the archive is stored.
149 Defaults to
150 .Pa /dev/rst0 .
151 .It Fl H
152 Follow symlinks given on the command line only.
153 .It Fl h
154 Follow symbolic links as if they were normal files
155 or directories.
156 In extract mode this means that a directory entry in the archive
157 will not overwrite an existing symbolic link, but rather what the
158 link ultimately points to.
159 .It Fl I Ar file
160 This is a positional argument which reads the names of files to
161 archive or extract from the given file, one per line.
162 .It Fl j
163 Compress archive using bzip2.
164 The bzip2 utility must be installed separately.
165 .It Fl L
166 Synonym for the
167 .Fl h
168 option.
169 .It Fl m
170 Do not preserve modification time.
171 .It Fl O
172 Write old-style (non-POSIX) archives.
173 .It Fl o
174 Don't write directory information that the older (V7) style
175 .Nm
176 is unable to decode.
177 This implies the
178 .Fl O
179 flag.
180 .It Fl P
181 Do not strip leading slashes
182 .Pq Sq /
183 from pathnames.
184 The default is to strip leading slashes.
185 .It Fl p
186 Preserve user and group ID as well as file mode regardless of
187 the current
188 .Xr umask 2 .
189 The setuid and setgid bits are only preserved if the user is
190 the superuser.
191 Only meaningful in conjunction with the
192 .Fl x
193 flag.
194 .It Fl q
195 Select the first archive member that matches each
196 .Ar file
197 operand.
198 No more than one archive member is matched for each
199 .Ar file .
200 When members of type directory are matched, the file hierarchy rooted at that
201 directory is also matched.
202 .It Fl s Ar replstr
203 Modify the archive member names according to the substitution expression
204 .Ar replstr ,
205 using the syntax of the
206 .Xr ed 1
207 utility regular expressions.
208 .Ar file
209 arguments may be given to restrict the list of archive members to those
210 specified.
211 .Pp
212 The format of these regular expressions is
213 .Pp
214 .Dl /old/new/[gp]
215 .Pp
216 As in
217 .Xr ed 1 ,
218 .Va old
219 is a basic regular expression (see
220 .Xr re_format 7 )
221 and
222 .Va new
223 can contain an ampersand
224 .Pq Ql & ,
225 .Ql \e Ns Em n
226 (where
227 .Em n
228 is a digit) back-references,
229 or subexpression matching.
230 The
231 .Va old
232 string may also contain newline characters.
233 Any non-null character can be used as a delimiter
234 .Po
235 .Ql /
236 is shown here
237 .Pc .
238 Multiple
239 .Fl s
240 expressions can be specified.
241 The expressions are applied in the order they are specified on the
242 command line, terminating with the first successful substitution.
243 .Pp
244 The optional trailing
245 .Cm g
246 continues to apply the substitution expression to the pathname substring,
247 which starts with the first character following the end of the last successful
248 substitution.
249 The first unsuccessful substitution stops the operation of the
250 .Cm g
251 option.
252 The optional trailing
253 .Cm p
254 will cause the final result of a successful substitution to be written to
255 standard error in the following format:
256 .Pp
257 .D1 Em original-pathname No >> Em new-pathname
258 .Pp
259 File or archive member names that substitute to the empty string
260 are not selected and will be skipped.
261 .It Fl v
262 Verbose operation mode.
263 .It Fl w
264 Interactively rename files.
265 This option causes
266 .Nm
267 to prompt the user for the filename to use when storing or
268 extracting files in an archive.
269 .It Fl X
270 Do not cross mount points in the file system.
271 .It Fl Z
272 Compress archive using
273 .Xr compress 1 .
274 .It Fl z
275 Compress archive using
276 .Xr gzip 1 .
277 .El
278 .Pp
279 The options
280 .Op Fl 014578
281 can be used to select one of the compiled-in backup devices,
282 .Pa /dev/rstN .
283 .Sh ENVIRONMENT
284 .Bl -tag -width Fl
285 .It Ev TMPDIR
286 Path in which to store temporary files.
287 .It Ev TAPE
288 Default tape device to use instead of
289 .Pa /dev/rst0 .
290 .El
291 .Sh FILES
292 .Bl -tag -width "/dev/rst0"
293 .It Pa /dev/rst0
294 default archive name
295 .El
296 .Sh EXAMPLES
297 Create an archive on the default tape drive, containing the files named
298 .Pa bonvole
299 and
300 .Pa sekve :
301 .Pp
302 .Dl $ tar c bonvole sekve
303 .Pp
304 Output a
305 .Xr gzip 1
306 compressed archive containing the files
307 .Pa bonvole
308 and
309 .Pa sekve
310 to a file called
311 .Pa foriru.tar.gz :
312 .Pp
313 .Dl $ tar zcf foriru.tar.gz bonvole sekve
314 .Pp
315 Verbosely create an archive, called
316 .Pa backup.tar.gz ,
317 of all files matching the shell
318 .Xr glob 3
319 function
320 .Pa *.c :
321 .Pp
322 .Dl $ tar zcvf backup.tar.gz *.c
323 .Pp
324 Verbosely list, but do not extract, all files ending in
325 .Pa .jpeg
326 from a compressed archive named
327 .Pa backup.tar.gz .
328 Note that the glob pattern has been quoted to avoid expansion by the shell:
329 .Pp
330 .Dl $ tar tvzf backup.tar.gz '*.jpeg'
331 .Pp
332 For more detailed examples, see
333 .Xr pax 1 .
334 .Sh DIAGNOSTICS
335 .Nm
336 will exit with one of the following values:
337 .Bl -tag -width 2n -offset indent
338 .It 0
339 All files were processed successfully.
340 .It 1
341 An error occurred.
342 .El
343 .Pp
344 Whenever
345 .Nm
346 cannot create a file or a link when extracting an archive or cannot
347 find a file while writing an archive, or cannot preserve the user
348 ID, group ID, file mode, or access and modification times when the
349 .Fl p
350 option is specified, a diagnostic message is written to standard
351 error and a non-zero exit value will be returned, but processing
352 will continue.
353 In the case where
354 .Nm
355 cannot create a link to a file,
356 .Nm
357 will not create a second copy of the file.
358 .Pp
359 If the extraction of a file from an archive is prematurely terminated
360 by a signal or error,
361 .Nm
362 may have only partially extracted the file the user wanted.
363 Additionally, the file modes of extracted files and directories may
364 have incorrect file bits, and the modification and access times may
365 be wrong.
366 .Pp
367 If the creation of an archive is prematurely terminated by a signal
368 or error,
369 .Nm
370 may have only partially created the archive, which may violate the
371 specific archive format specification.
372 .Sh SEE ALSO
373 .Xr cpio 1 ,
374 .Xr pax 1
375 .Sh HISTORY
376 A
377 .Nm
378 command first appeared in
379 .At v7 .
380 .Sh AUTHORS
381 Keith Muller at the University of California, San Diego.
382 .Sh CAVEATS
383 The
384 .Fl j
385 and
386 .Fl L
387 flags are not portable to other versions of
388 .Nm
389 where they may have a different meaning.