]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - gnu/usr.bin/tar/tar.1
$Id$ -> $FreeBSD$
[FreeBSD/FreeBSD.git] / gnu / usr.bin / tar / tar.1
1 .\" Copyright (c) 1991, 1992, 1993 Free Software Foundation     -*- nroff -*-
2 .\" See /usr/src/gnu/COPYING for conditions of redistribution
3 .\"
4 .\"     Written by John F. Woods <jfw@jfwhome.funhouse.com>
5 .\"     Updated by Robert Eckardt <roberte@mep.ruhr-uni-bochum.de>
6 .\"
7 .\" $FreeBSD$
8 .\"
9 .Dd 25 August 1997
10 .Os FreeBSD
11 .Dt TAR 1
12 .Sh NAME
13 .Nm tar
14 .Nd
15 tape archiver; manipulate "tar" archive files
16 .Sh SYNOPSIS
17 .Nm tar
18 .Op [-] Ns Ar bundled-options Ar Args
19 .Op Ar gnu-style-flags
20 .Oo
21 .Ar filenames | Fl C Ar directory-name
22 .Oc ...
23 .Sh DESCRIPTION
24 .Nm Tar
25 is short for 
26 .Dq tape archiver,
27 so named for historical reasons; the
28 .Nm
29 program creates, adds files to, or extracts files from an archive file
30 in
31 .Dq tar
32 format, called a
33 .Ar tarfile .
34 A tarfile is often a magnetic tape, but can be a floppy diskette or any
35 regular disk file.
36 .Pp
37 The first argument word of the
38 .Nm
39 command line is usually a command word of bundled function and modifier
40 letters, optionally preceded by a dash;
41 it must contain exactly one function letter from the set
42 .Cm A ,
43 .Cm c ,
44 .Cm d ,
45 .Cm r ,
46 .Cm t ,
47 .Cm u ,
48 .Cm x ,
49 for append, create, difference, replace, table of contents, update, and
50 extract (further described below).  The command word can also contain other
51 function modifiers described below, some of which will take arguments from
52 the command line in the order they are specified in the command word (review
53 the EXAMPLES section).  Functions and function modifiers can also be specified
54 with the GNU argument convention (preceded by two dashes, one function or
55 modifier per word.  Command-line arguments that specify files to
56 add to, extract from, or list from an archive may be given as shell
57 pattern matching strings.
58 .Sh FUNCTIONS
59 Exactly one of the following functions must be specified.
60 .Pp
61 .Bl -tag -width "--concatenate" -compact
62 .It Fl A
63 .It Fl -catenate
64 .It Fl "-concatenate"
65 Append the contents of named file, which must itself be a tar archive,
66 to the end of the archive (erasing the old end-of-archive block).
67 This has the effect of adding the files contained in the named file to
68 the first archive, rather than adding the second archive as an element
69 of the first.
70 .Em Note:
71 This option requires a rewritable tarfile,
72 and therefore does not work on quarter-inch cartridge tapes.
73 .It Fl c
74 .It Fl -create
75 Create a new archive (or truncates an old one) and writes the named files
76 to it.
77 .It Fl d
78 .It Fl -diff
79 .It Fl -compare
80 Find differences between files in the archive and corresponding files in
81 the file system.
82 .It Fl -delete
83 Delete named files from the archive (Does not work on quarter-inch tapes).
84 .It Fl r
85 .It Fl -append
86 Append files to the end of an archive (Does not work on quarter-inch tapes).
87 .It Fl t
88 .It Fl -list
89 List the contents of an archive; if filename arguments are given, only those
90 files are listed, otherwise the entire table of contents is listed.
91 .It Fl u
92 .It Fl -update
93 Append the named files if the on-disk version has a modification date
94 more recent than their copy in the archive (if any).  Does not work on
95 quarter-inch tapes.
96 .It Fl x
97 .It Fl -extract
98 .It Fl -get
99 Extract files from an archive.  The owner, modification time, and file
100 permissions are restored, if possible.  If no
101 .Ar file
102 arguments are given, extract all the files in the archive.  If a
103 .Ar filename
104 argument matches the name of a directory on the tape, that directory and
105 its contents are extracted (as well as all directories under that directory).
106 If the archive contains multiple entries corresponding to the same file
107 (see the
108 .Fl -append
109 command above), the last one extracted will overwrite all earlier versions.
110 .El
111 .Sh OPTIONS
112 The other options to
113 .Nm
114 may be combined arbitrarily; single-letter options may be bundled in with
115 the command word.  Verbose options which take arguments will be
116 followed by the argument; single-letter options will consume
117 successive command line arguments (see the
118 .Sx EXAMPLES
119 below).
120 .Pp
121 .Bl -tag -width "--preserve-permissions" -compact
122 .It Fl -help
123 Prints a message listing and briefly describing all the command
124 options to
125 .Nm tar.
126 .It Fl -atime-preserve
127 Restore the access times on files which are written to tape (note that
128 this will change the inode-change time!).
129 .It Fl b
130 .It Fl -block-size Ar number
131 Sets the block size for reading or writing to
132 .Ar number
133 * 512-byte blocks.
134 .It Fl B
135 .It Fl -read-full-blocks
136 Re-assemble short reads into full blocks (for reading 4.2BSD pipes).
137 .It Fl C Ar directory
138 .It Fl -directory Ar directory
139 Change to
140 .Ar directory
141 before processing the remaining arguments.
142 .It Fl -checkpoint
143 Print number of buffer reads/writes while reading/writing the archive.
144 .It Fl f Ar [hostname:]file
145 .It Fl -file  Ar [hostname:]file
146 Read or write the specified
147 .Ar file
148 (default is /dev/rsa0).  If a
149 .Ar hostname
150 is specified,
151 .Nm
152 will use
153 .Xr rmt 8
154 to read or write the specified
155 .Ar file
156 on a remote machine. "-" may be used is a filename, for reading
157 or writing to/from stdin/stdout.
158 .It Fl -force-local
159 Archive file is local even if it has a colon
160 .It Fl F Ar file
161 .It Fl -info-script Ar file
162 .It Fl -new-volume-script Ar file
163 Run a script at the end of each archive volume (implies
164 .Fl M ) .
165 .It Fl -fast-read
166 Stop after all non-wildcard extraction targets have been found
167 in the archive.
168 .It Fl G
169 .It Fl -incremental
170 Create/list/extract old GNU-format incremental backup.
171 .It Fl g Ar file
172 .It Fl -listed-incremental Ar file
173 Create/list/extract new GNU-format incremental backup.
174 .It Fl h
175 .It Fl -dereference
176 Don't write symlinks as symlinks; write the data of the files they name.
177 .It Fl i
178 .It Fl -ignore-zeros
179 Ignore blocks of zeroes in archive (usually means End-Of-File).
180 .It Fl -ignore-failed-read
181 Don't exit with non-zero status on unreadable files.
182 .It Fl k
183 .It Fl -keep-old-files
184 Keep files which already exist on disk; don't overwrite them from the archive.
185 .It Fl K Ar file
186 .It Fl -starting-file Ar file
187 Begin at
188 .Ar file
189 in the archive.
190 .It Fl l
191 .It Fl -one-file-system
192 Stay in local filesystem when creating an archive (do not cross mount
193 points).
194 .It Fl L Ar number
195 .It Fl -tape-length Ar number
196 Change tapes after writing 
197 .Ar number
198 * 1024 bytes.
199 .It Fl m
200 .It Fl -modification-time
201 Don't extract file modified time.
202 .It Fl M
203 .It Fl -multi-volume
204 Create/list/extract multi-volume archive.
205 .It Fl n
206 .It Fl -norecurse
207 Don't recurse into subdirectories when creating.
208 .It Fl -volno-file Ar file
209 File name with volume number to start with.
210 .It Fl N Ar date
211 .It Fl -after-date Ar date
212 .It Fl -newer Ar date
213 Only store files with creation time newer than
214 .Ar date .
215 .It Fl -newer-mtime Ar date
216 Only store files with modification time newer than
217 .Ar date .
218 .It Fl o
219 .It Fl -old-archive
220 .It Fl -portability
221 Write a V7 format archive, rather than POSIX format.
222 .It Fl O
223 .It Fl -to-stdout
224 Extract files to standard output.
225 .It Fl p
226 .It Fl -same-permissions
227 .It Fl -preserve-permissions
228 Extract all protection information.
229 .It Fl -preserve
230 Has the effect of
231 .Fl p s.
232 .It Fl P
233 .It Fl -absolute-paths
234 Don't strip leading `/' from file names.
235 .It Fl R
236 .It Fl -record-number
237 Show record number within archive with each message.
238 .It Fl -remove-files
239 Remove files after adding them to the archive.
240 .It Fl s
241 .It Fl -same-order
242 .It Fl -preserve-order
243 List of names to extract is sorted to match archive.
244 .It Fl -show-omitted-dirs
245 Show directories which were omitted while processing the archive.
246 .It Fl S
247 .It Fl -sparse
248 Handle "sparse" files efficiently.
249 .It Fl T Ar file
250 .It Fl -files-from Ar file
251 Get names of files to extract or create from
252 .Ar file ,
253 one per line.
254 .It Fl -null
255 Modifies behavior of
256 .Fl T
257 to expect null-terminated names; disables
258 .Fl C.
259 .It Fl -totals
260 Prints total bytes written with
261 .Fl -create.
262 .It Fl v
263 .It Fl -verbose
264 Lists files written to archive with
265 .Fl -create
266 or extracted with
267 .Fl -extract;
268 lists file protection information along with file names with
269 .Fl -list.
270 .It Fl V Ar volume-name
271 .It Fl -label Ar volume-name
272 Create archive with the given
273 .Ar volume-name .
274 .It Fl -version
275 Print
276 .Nm tar
277 program version number.
278 .It Fl w
279 .It Fl -interactive
280 .It Fl -confirmation
281 Ask for confirmation for every action.
282 .It Fl W
283 .It Fl -verify
284 Attempt to verify the archive after writing it.
285 .It Fl -exclude Ar pattern
286 Exclude files matching the
287 .Ar pattern
288 (don't extract them, don't add them, don't list them).
289 .It Fl X Ar file
290 .It Fl -exclude-from Ar file
291 Exclude files listed in
292 .Ar file .
293 .It Fl y
294 .It Fl -bzip2
295 .It Fl -bunzip2
296 Filter the archive through
297 .Xr bzip2 1 .
298 .It Fl Z
299 .It Fl -compress
300 .It Fl -uncompress
301 Filter the archive through
302 .Xr compress 1 .
303 .It Fl z
304 .It Fl -gzip
305 .It Fl -gunzip
306 Filter the archive through
307 .Xr gzip 1 .
308 .It Fl -use-compress-program Ar program
309 Filter the archive through
310 .Ar program
311 (which must accept
312 .Fl d
313 to mean ``decompress'').
314 .It Fl -block-compress
315 Block the output of compression program for tapes or floppies
316 (otherwise writes will be of odd length, which device drivers may reject).
317 .It Fl [0-7][lmh]
318 Specify tape drive and density.
319 .It Fl -unlink
320 Unlink files before creating them.
321 .El
322 .Sh EXAMPLES
323 To create an archive on tape drive /dev/rsa0 with a block size of 20
324 blocks, containing files named "bert" and "ernie", you can enter
325 .Dl tar cfb /dev/rsa0 20 bert ernie
326 or
327 .Dl tar\ --create\ --file\ /dev/rsa0\ --block-size\ 20\ bert\ ernie
328 Note that the
329 .Fl f
330 and
331 .Fl b
332 flags both require arguments, which they take from the command line in
333 the order they were listed in the command word.
334 .Pp
335 Because /dev/rsa0 is the default device, and 20 is the default block
336 size, the above example could have simply been
337 .Dl tar c bert ernie
338 .Pp
339 To extract all the C sources and headers from an archive named
340 "backup.tar", type
341 .Dl tar xf backup.tar '*.[ch]'
342 Note that the pattern must be quoted to prevent the shell from
343 attempting to expand it according the files in the current working
344 directory (the shell does not have access to the list of files in
345 the archive, of course).
346 .Pp
347 To move file hierarchies, use a command line like this:
348 .Bd -literal
349 tar -cf - -C srcdir . | tar xpf - -C destdir
350 .Ed
351 .Pp
352 To create a compressed archive on diskette, using gzip, use a command-line like
353 .Dl tar --block-compress -z -c -v -f /dev/rfd1a -b 36 tar/
354 .Pp
355 Note that you cannot mix bundled flags and --style flags; you can use
356 single-letter flags in the manner above, rather than having to type
357 .Dl tar --block-compress --gzip --verbose --file /dev/rfd1a --block-size 20 tar/
358 .Pp
359 The above-created diskette can be listed with
360 .Dl tar tvfbz /dev/rfd1a 36
361 .Pp
362 To join two tar archives into a single archive, use
363 .Dl tar Af archive1.tar archive2.tar
364 which will add the files contained in archive2.tar onto the end of
365 archive1.tar (note that this can't be done by simply typing
366 .Dl cat archive2.tar >> archive1.tar
367 because of the end-of-file block at the end of a tar archive).
368 .Pp
369 To archive all files from the directory srcdir, which were modified
370 after Feb. 9th 1997, 13:00 h, use
371 .Dl tar\ -c\ -f\ backup.tar\ --newer-mtime\ 'Feb\ 9\ 13:15\ 1997'\ srcdir/
372 .Pp
373 Other possible time specifications are '02/09/97 13:15',
374 \&'1997-02-09 13:15', '13:15 9 Feb 1997', '9 Feb 1997 13:15', 
375 \&'Feb. 9, 1997 1:15pm', '09-Feb', '3 weeks ago' or 'May first Sunday'.
376 To specify the correct time zone use either e.g. `13:15 CEST' or `13:15+200'.
377
378 .Sh ENVIRONMENT
379 The
380 .Nm tar
381 program examines the following environment variables.
382 .Bl -tag -width "POSIXLY_CORRECT"
383 .It POSIXLY_CORRECT
384 Normally,
385 .Nm tar
386 will process flag arguments that appear in the file list.
387 If set in the environment, this causes
388 .Nm tar
389 to consider the first
390 non-flag argument to terminate flag processing, as per the POSIX specification.
391 .It SHELL
392 In interactive mode, a permissible response to the prompt is to
393 request to spawn a subshell, which will be "/bin/sh" unless the SHELL variable
394 is set.
395 .It TAPE
396 Changes tar's default tape drive (which is still overridden by the
397 .Fl f
398 flag).
399 .El
400 .Sh FILES
401 .Bl -tag -width "/dev/rsa0"
402 .It Pa /dev/rsa0
403 The default tape drive.
404 .El
405 .\" This next request is for sections 1, 6, 7 & 8 only
406 .\"     (command return values (to shell) and fprintf/stderr type diagnostics)
407 .\" .Sh DIAGNOSTICS
408 .Sh SEE ALSO
409 .Xr bzip2 1 ,
410 .Xr compress 1 ,
411 .Xr gzip 1 ,
412 .Xr pax 1 ,
413 .Xr ft 8 ,
414 .Xr rmt 8
415 .\" .Sh STANDARDS
416 .Sh HISTORY
417 The tar format has a rich history, dating back to Sixth Edition UNIX.
418 The current implementation of
419 .Nm tar
420 is the GNU implementation, which
421 originated as the public-domain tar written by John Gilmore.
422 .Sh AUTHORS
423 A cast of thousands, including [as listed in the ChangeLog file in the
424 source]
425 .An John Gilmore
426 (author of original public domain version),
427 .An Jay Fenlason
428 (first GNU author),
429 .An Joy Kendall ,
430 .An Jim Kingdon ,
431 .An David J. MacKenzie ,
432 .An Michael I Bushnell ,
433 .An Noah Friedman ,
434 and innumerable others who have contributed fixes and additions.
435 .Pp
436 Man page obtained by the
437 .Bx Free
438 group from the NetBSD 1.0 release.
439 .Sh BUGS
440 The
441 .Fl C
442 feature does not work like historical tar programs, and is probably
443 untrustworthy.
444 .Pp
445 The 
446 .Fl A 
447 command should work to join an arbitrary number of tar archives
448 together, but it does not; attempting to do so leaves the
449 end-of-archive blocks in place for the second and subsequent archives.