]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Updated
[chaz/tar] / doc / tar.texi
1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename tar.info
4 @include version.texi
5 @settitle GNU tar @value{VERSION}
6 @setchapternewpage odd
7
8 @finalout
9
10 @smallbook
11 @c %**end of header
12
13 @c ======================================================================
14 @c This document has three levels of rendition: PUBLISH, DISTRIB or PROOF,
15 @c as decided by @set symbols. The PUBLISH rendition does not show
16 @c notes or marks asking for revision. Most users will prefer having more
17 @c information, even if this information is not fully revised for adequacy,
18 @c so DISTRIB is the default for tar distributions. The PROOF rendition
19 @c show all marks to the point of ugliness, but is nevertheless useful to
20 @c those working on the manual itself.
21 @c ======================================================================
22
23 @ifclear PUBLISH
24 @ifclear DISTRIB
25 @ifclear PROOF
26 @set DISTRIB
27 @end ifclear
28 @end ifclear
29 @end ifclear
30
31 @ifset PUBLISH
32 @set RENDITION The book, version
33 @end ifset
34
35 @ifset DISTRIB
36 @set RENDITION FTP release, version
37 @end ifset
38
39 @ifset PROOF
40 @set RENDITION Proof reading version
41 @end ifset
42
43 @c ---------------------------------------------------------------------
44 @c The @FIXME's, @UNREVISED and @c comments are part Fran@,{c}ois's work
45 @c plan. These annotations are somewhat precious to him; he asks that I
46 @c do not alter them inconsiderately. Much work is needed for GNU tar
47 @c internals (the sources, the programs themselves). Revising the
48 @c adequacy of the manual while revising the sources, and cleaning them
49 @c both at the same time, is a good way to proceed.
50 @c ---------------------------------------------------------------------
51
52 @c Output marks for nodes needing revision, but not in PUBLISH rendition.
53
54 @macro UNREVISED
55 @ifclear PUBLISH
56 @quotation
57 @emph{(This message will disappear, once this node revised.)}
58 @end quotation
59 @end ifclear
60 @end macro
61
62 @c Output various FIXME information only in PROOF rendition.
63
64 @macro FIXME{string}
65 @allow-recursion
66 @quote-arg
67 @ifset PROOF
68 @strong{<FIXME>} \string\ @strong{</>}
69 @end ifset
70
71 @end macro
72
73 @macro FIXME-ref{string}
74 @quote-arg
75 @ifset PROOF
76 @strong{<REF>} \string\ @strong{</>}
77 @end ifset
78
79 @end macro
80
81 @macro FIXME-pxref{string}
82 @quote-arg
83 @ifset PROOF
84 @strong{<PXREF>} \string\ @strong{</>}
85 @end ifset
86
87 @end macro
88
89 @macro FIXME-xref{string}
90 @quote-arg
91 @ifset PROOF
92 @strong{<XREF>} \string\ @strong{</>}
93 @end ifset
94
95 @end macro
96
97 @c @macro option{entry}
98 @c @quote-arg
99 @c @opindex{--\entry\}
100 @c @value{\entry\}
101 @c @end macro
102
103 @macro GNUTAR
104 @acronym{GNU} @command{tar}
105 @end macro
106
107 @set op-absolute-names @kbd{--absolute-names} (@kbd{-P})
108 @set ref-absolute-names @ref{absolute}
109 @set xref-absolute-names @xref{absolute}
110 @set pxref-absolute-names @pxref{absolute}
111
112 @set op-after-date @kbd{--after-date=@var{date}} (@kbd{--newer=@var{date}}, @kbd{-N @var{date}})
113 @set ref-after-date @ref{after}
114 @set xref-after-date @xref{after}
115 @set pxref-after-date @pxref{after}
116
117 @set op-append @kbd{--append} (@kbd{-r})
118 @set ref-append @ref{add}
119 @set xref-append @xref{add}
120 @set pxref-append @pxref{add}
121
122 @set op-atime-preserve @kbd{--atime-preserve}
123 @set ref-atime-preserve @ref{Attributes}
124 @set xref-atime-preserve @xref{Attributes}
125 @set pxref-atime-preserve @pxref{Attributes}
126
127 @set op-backup @kbd{--backup}
128 @set ref-backup @ref{Backup options}
129 @set xref-backup @xref{Backup options}
130 @set pxref-backup @pxref{Backup options}
131
132 @set op-block-number @kbd{--block-number} (@kbd{-R})
133 @set ref-block-number @ref{verbose}
134 @set xref-block-number @xref{verbose}
135 @set pxref-block-number @pxref{verbose}
136
137 @set op-blocking-factor @kbd{--blocking-factor=@var{512-size}} (@kbd{-b @var{512-size}})
138 @set ref-blocking-factor @ref{Blocking Factor}
139 @set xref-blocking-factor @xref{Blocking Factor}
140 @set pxref-blocking-factor @pxref{Blocking Factor}
141
142 @set op-bzip2 @kbd{--bzip2} (@kbd{-j})
143 @set ref-bzip2 @ref{gzip}
144 @set xref-bzip2 @xref{gzip}
145 @set pxref-bzip2 @pxref{gzip}
146
147 @set op-check-links @kbd{--check-links} (@kbd{-l})
148 @set ref-check-links @ref{--check-links}
149 @set xref-check-links @xref{--check-links}
150 @set pxref-check-links @pxref{--check-links}
151
152 @set op-checkpoint @kbd{--checkpoint}
153 @set ref-checkpoint @ref{verbose}
154 @set xref-checkpoint @xref{verbose}
155 @set pxref-checkpoint @pxref{verbose}
156
157 @set op-check-links @kbd{--check-links}
158
159 @set op-compare @kbd{--compare} (@kbd{--diff}, @kbd{-d})
160 @set ref-compare @ref{compare}
161 @set xref-compare @xref{compare}
162 @set pxref-compare @pxref{compare}
163
164 @set op-compress @kbd{--compress} (@kbd{--uncompress}, @kbd{-Z})
165 @set ref-compress @ref{gzip}
166 @set xref-compress @xref{gzip}
167 @set pxref-compress @pxref{gzip}
168
169 @set op-concatenate @kbd{--concatenate} (@kbd{--catenate}, @kbd{-A})
170 @set ref-concatenate @ref{concatenate}
171 @set xref-concatenate @xref{concatenate}
172 @set pxref-concatenate @pxref{concatenate}
173
174 @set op-create @kbd{--create} (@kbd{-c})
175 @set ref-create @ref{create}
176 @set xref-create @xref{create}
177 @set pxref-create @pxref{create}
178
179 @set op-delete @kbd{--delete}
180 @set ref-delete @ref{delete}
181 @set xref-delete @xref{delete}
182 @set pxref-delete @pxref{delete}
183
184 @set op-dereference @kbd{--dereference} (@kbd{-h})
185 @set ref-dereference @ref{dereference}
186 @set xref-dereference @xref{dereference}
187 @set pxref-dereference @pxref{dereference}
188
189 @set op-directory @kbd{--directory=@var{directory}} (@kbd{-C @var{directory}})
190 @set ref-directory @ref{directory}
191 @set xref-directory @xref{directory}
192 @set pxref-directory @pxref{directory}
193
194 @set op-exclude @kbd{--exclude=@var{pattern}}
195 @set ref-exclude @ref{exclude}
196 @set xref-exclude @xref{exclude}
197 @set pxref-exclude @pxref{exclude}
198
199 @set op-exclude-from @kbd{--exclude-from=@var{file-of-patterns}} (@kbd{-X @var{file-of-patterns}})
200 @set ref-exclude-from @ref{exclude}
201 @set xref-exclude-from @xref{exclude}
202 @set pxref-exclude-from @pxref{exclude}
203
204 @set op-extract @kbd{--extract} (@kbd{--get}, @kbd{-x})
205 @set ref-extract @ref{extract}
206 @set xref-extract @xref{extract}
207 @set pxref-extract @pxref{extract}
208
209 @set op-file @kbd{--file=@var{archive-name}} (@kbd{-f @var{archive-name}})
210 @set ref-file @ref{file}
211 @set xref-file @xref{file}
212 @set pxref-file @pxref{file}
213
214 @set op-files-from @kbd{--files-from=@var{file-of-names}} (@kbd{-T @var{file-of-names}})
215 @set ref-files-from @ref{files}
216 @set xref-files-from @xref{files}
217 @set pxref-files-from @pxref{files}
218
219 @set op-force-local @kbd{--force-local}
220 @set ref-force-local @ref{file}
221 @set xref-force-local @xref{file}
222 @set pxref-force-local @pxref{file}
223
224 @set op-group @kbd{--group=@var{group}}
225 @set ref-group @ref{Option Summary}
226 @set xref-group @xref{Option Summary}
227 @set pxref-group @pxref{Option Summary}
228
229 @set op-gzip @kbd{--gzip} (@kbd{--gunzip}, @kbd{--ungzip}, @kbd{-z})
230 @set ref-gzip @ref{gzip}
231 @set xref-gzip @xref{gzip}
232 @set pxref-gzip @pxref{gzip}
233
234 @set op-help @kbd{--help}
235 @set ref-help @ref{help}
236 @set xref-help @xref{help}
237 @set pxref-help @pxref{help}
238
239 @set op-ignore-failed-read @kbd{--ignore-failed-read}
240 @set ref-ignore-failed-read @ref{create options}
241 @set xref-ignore-failed-read @xref{create options}
242 @set pxref-ignore-failed-read @pxref{create options}
243
244 @set op-ignore-zeros @kbd{--ignore-zeros} (@kbd{-i})
245 @set ref-ignore-zeros @ref{Reading}
246 @set xref-ignore-zeros @xref{Reading}
247 @set pxref-ignore-zeros @pxref{Reading}
248
249 @set op-incremental @kbd{--incremental} (@kbd{-G})
250 @set ref-incremental @ref{Inc Dumps}
251 @set xref-incremental @xref{Inc Dumps}
252 @set pxref-incremental @pxref{Inc Dumps}
253
254 @set op-info-script @kbd{--info-script=@var{script-name}} (@kbd{--new-volume-script=@var{script-name}}, @kbd{-F @var{script-name}})
255 @set ref-info-script @ref{Multi-Volume Archives}
256 @set xref-info-script @xref{Multi-Volume Archives}
257 @set pxref-info-script @pxref{Multi-Volume Archives}
258
259 @set op-interactive @kbd{--interactive} (@kbd{-w})
260 @set ref-interactive @ref{interactive}
261 @set xref-interactive @xref{interactive}
262 @set pxref-interactive @pxref{interactive}
263
264 @set op-keep-old-files @kbd{--keep-old-files} (@kbd{-k})
265 @set ref-keep-old-files @ref{Keep Old Files}
266 @set xref-keep-old-files @xref{Keep Old Files}
267 @set pxref-keep-old-files @pxref{Keep Old Files}
268
269 @set op-keep-newer-files @kbd{--keep-old-files}
270 @set ref-keep-newer-files @ref{Keep Newer Files}
271 @set xref-keep-newer-files @xref{Keep Newer Files}
272 @set pxref-keep-newer-files @pxref{Keep Newer Files}
273
274 @set op-label @kbd{--label=@var{archive-label}} (@kbd{-V @var{archive-label}})
275 @set ref-label @ref{label}
276 @set xref-label @xref{label}
277 @set pxref-label @pxref{label}
278
279 @set op-list @kbd{--list} (@kbd{-t})
280 @set ref-list @ref{list}
281 @set xref-list @xref{list}
282 @set pxref-list @pxref{list}
283
284 @set op-listed-incremental @kbd{--listed-incremental=@var{snapshot-file}} (@kbd{-g @var{snapshot-file}})
285 @set ref-listed-incremental @ref{Inc Dumps}
286 @set xref-listed-incremental @xref{Inc Dumps}
287 @set pxref-listed-incremental @pxref{Inc Dumps}
288
289 @set op-mode @kbd{--mode=@var{permissions}}
290 @set ref-mode @ref{Option Summary}
291 @set xref-mode @xref{Option Summary}
292 @set pxref-mode @pxref{Option Summary}
293
294 @set op-multi-volume @kbd{--multi-volume} (@kbd{-M})
295 @set ref-multi-volume @ref{Multi-Volume Archives}
296 @set xref-multi-volume @xref{Multi-Volume Archives}
297 @set pxref-multi-volume @pxref{Multi-Volume Archives}
298
299 @set op-newer-mtime @kbd{--newer-mtime=@var{date}}
300 @set ref-newer-mtime @ref{after}
301 @set xref-newer-mtime @xref{after}
302 @set pxref-newer-mtime @pxref{after}
303
304 @set op-no-recursion @kbd{--no-recursion}
305 @set ref-no-recursion @ref{recurse}
306 @set xref-no-recursion @xref{recurse}
307 @set pxref-no-recursion @pxref{recurse}
308
309 @set op-no-same-owner @kbd{--no-same-owner} (@kbd{-o})
310 @set ref-no-same-owner @ref{Attributes}
311 @set xref-no-same-owner @xref{Attributes}
312 @set pxref-no-same-owner @pxref{Attributes}
313
314 @set op-no-same-permissions @kbd{--no-same-permissions}
315 @set ref-no-same-permissions @ref{Attributes}
316 @set xref-no-same-permissions @xref{Attributes}
317 @set pxref-no-same-permissions @pxref{Attributes}
318
319 @set op-null @kbd{--null}
320 @set ref-null @ref{files}
321 @set xref-null @xref{files}
322 @set pxref-null @pxref{files}
323
324 @set op-numeric-owner @kbd{--numeric-owner}
325 @set ref-numeric-owner @ref{Attributes}
326 @set xref-numeric-owner @xref{Attributes}
327 @set pxref-numeric-owner @pxref{Attributes}
328
329 @set op-occurrence @kbd{--occurrence}
330 @set ref-occurrence @ref{--occurrence}
331 @set xref-occurrence @xref{--occurrence}
332 @set pxref-occurrence @pxref{--occurrence}
333
334 @set op-old-archive @kbd{--old-archive} (@kbd{-o})
335 @set ref-old-archive @ref{old}
336 @set xref-old-archive @xref{old}
337 @set pxref-old-archive @pxref{old}
338
339 @set op-one-file-system @kbd{--one-file-system} (@kbd{-l})
340 @set ref-one-file-system @ref{one}
341 @set xref-one-file-system @xref{one}
342 @set pxref-one-file-system @pxref{one}
343
344 @set op-overwrite @kbd{--overwrite}
345 @set ref-overwrite @ref{Overwrite Old Files}
346 @set xref-overwrite @xref{Overwrite Old Files}
347 @set pxref-overwrite @pxref{Overwrite Old Files}
348
349 @set op-owner @kbd{--owner=@var{user}}
350 @set ref-owner @ref{Option Summary}
351 @set xref-owner @xref{Option Summary}
352 @set pxref-owner @pxref{Option Summary}
353
354 @set op-format @kbd{--format} (@kbd{-H})
355 @set ref-format @ref{format}
356 @set xref-format @xref{format}
357 @set pxref-format @pxref{format}
358
359 @set op-format-v7 @kbd{--format=v7}
360 @set op-format-gnu @kbd{--format=gnu}
361 @set op-format-oldgnu @kbd{--format=oldgnu}
362 @set op-format-posix @kbd{--format=posix}
363 @set op-format-ustar @kbd{--format=ustar}
364
365 @set op-posix @kbd{--posix}
366 @set ref-posix @ref{posix}
367 @set xref-posix @xref{posix}
368 @set pxref-posix @pxref{posix}
369
370 @set op-preserve @kbd{--preserve}
371 @set ref-preserve @ref{Attributes}
372 @set xref-preserve @xref{Attributes}
373 @set pxref-preserve @pxref{Attributes}
374
375 @set op-record-size @kbd{--record-size=@var{size}}
376 @set ref-record-size @ref{Blocking}
377 @set xref-record-size @xref{Blocking}
378 @set pxref-record-size @pxref{Blocking}
379
380 @set op-recursive-unlink @kbd{--recursive-unlink}
381 @set ref-recursive-unlink @ref{Writing}
382 @set xref-recursive-unlink @xref{Writing}
383 @set pxref-recursive-unlink @pxref{Writing}
384
385 @set op-read-full-records @kbd{--read-full-records} (@kbd{-B})
386 @set ref-read-full-records @ref{Blocking}
387 @set xref-read-full-records @xref{Blocking}
388 @set pxref-read-full-records @pxref{Blocking}
389 @c FIXME: or should it be Reading, or Blocking Factor
390
391 @set op-remove-files @kbd{--remove-files}
392 @set ref-remove-files @ref{Writing}
393 @set xref-remove-files @xref{Writing}
394 @set pxref-remove-files @pxref{Writing}
395
396 @set op-rmt-command @kbd{rmt-command=@var{command}}
397 @set op-rsh-command @kbd{rsh-command=@var{command}}
398
399 @set op-same-order @kbd{--same-order} (@kbd{--preserve-order}, @kbd{-s})
400 @set ref-same-order @ref{Scarce}
401 @set xref-same-order @xref{Scarce}
402 @set pxref-same-order @pxref{Scarce}
403 @c FIXME: or should it be Reading, or Attributes?
404
405 @set op-same-owner @kbd{--same-owner}
406 @set ref-same-owner @ref{Attributes}
407 @set xref-same-owner @xref{Attributes}
408 @set pxref-same-owner @pxref{Attributes}
409
410 @set op-same-permissions @kbd{--same-permissions} (@kbd{--preserve-permissions}, @kbd{-p})
411 @set ref-same-permissions @ref{Attributes}
412 @set xref-same-permissions @xref{Attributes}
413 @set pxref-same-permissions @pxref{Attributes}
414 @c FIXME: or should it be Writing?
415
416 @set op-show-omitted-dirs @kbd{--show-omitted-dirs}
417 @set ref-show-omitted-dirs @ref{verbose}
418 @set xref-show-omitted-dirs @xref{verbose}
419 @set pxref-show-omitted-dirs @pxref{verbose}
420
421 @set op-sparse @kbd{--sparse} (@kbd{-S})
422 @set ref-sparse @ref{sparse}
423 @set xref-sparse @xref{sparse}
424 @set pxref-sparse @pxref{sparse}
425
426 @set op-starting-file @kbd{--starting-file=@var{name}} (@kbd{-K @var{name}})
427 @set ref-starting-file @ref{Scarce}
428 @set xref-starting-file @xref{Scarce}
429 @set pxref-starting-file @pxref{Scarce}
430
431 @set op-strip-components @kbd{--strip-components}
432 @set ref-strip-components @ref{--strip-components}
433 @set xref-strip-components @xref{--strip-components}
434 @set pxref-strip-components @pxref{--strip-components}
435
436 @set op-suffix @kbd{--suffix=@var{suffix}}
437 @set ref-suffix @ref{Backup options}
438 @set xref-suffix @xref{Backup options}
439 @set pxref-suffix @pxref{Backup options}
440
441 @set op-tape-length @kbd{--tape-length=@var{1024-size}} (@kbd{-L @var{1024-size}})
442 @set ref-tape-length @ref{Using Multiple Tapes}
443 @set xref-tape-length @xref{Using Multiple Tapes}
444 @set pxref-tape-length @pxref{Using Multiple Tapes}
445
446 @set op-to-stdout @kbd{--to-stdout} (@kbd{-O})
447 @set ref-to-stdout @ref{Writing}
448 @set xref-to-stdout @xref{Writing}
449 @set pxref-to-stdout @pxref{Writing}
450
451 @set op-totals @kbd{--totals}
452 @set ref-totals @ref{verbose}
453 @set xref-totals @xref{verbose}
454 @set pxref-totals @pxref{verbose}
455
456 @set op-touch @kbd{--touch} (@kbd{-m})
457 @set ref-touch @ref{Writing}
458 @set xref-touch @xref{Writing}
459 @set pxref-touch @pxref{Writing}
460
461 @set op-unlink-first @kbd{--unlink-first} (@kbd{-U})
462 @set ref-unlink-first @ref{Writing}
463 @set xref-unlink-first @xref{Writing}
464 @set pxref-unlink-first @pxref{Writing}
465
466 @set op-update @kbd{--update} (@kbd{-u})
467 @set ref-update @ref{update}
468 @set xref-update @xref{update}
469 @set pxref-update @pxref{update}
470
471 @set op-use-compress-prog @kbd{--use-compress-prog=@var{program}}
472 @set ref-use-compress-prog @ref{gzip}
473 @set xref-use-compress-prog @xref{gzip}
474 @set pxref-use-compress-prog @pxref{gzip}
475
476 @set op-verbose @kbd{--verbose} (@kbd{-v})
477 @set ref-verbose @ref{verbose}
478 @set xref-verbose @xref{verbose}
479 @set pxref-verbose @pxref{verbose}
480
481 @set op-verify @kbd{--verify} (@kbd{-W})
482 @set ref-verify @ref{verify}
483 @set xref-verify @xref{verify}
484 @set pxref-verify @pxref{verify}
485
486 @set op-version @kbd{--version}
487 @set ref-version @ref{help}
488 @set xref-version @xref{help}
489 @set pxref-version @pxref{help}
490
491 @set op-volno-file @kbd{--volno-file=@var{file-of-number}}
492 @set ref-volno-file @ref{Using Multiple Tapes}
493 @set xref-volno-file @xref{Using Multiple Tapes}
494 @set pxref-volno-file @pxref{Using Multiple Tapes}
495
496 @c Put everything in one index (arbitrarily chosen to be the concept index).
497 @syncodeindex fn cp
498 @syncodeindex ky cp
499 @syncodeindex pg cp
500 @syncodeindex vr cp
501
502 @defindex op
503 @syncodeindex op cp
504
505 @copying
506
507 This manual is for @acronym{GNU} @command{tar} (version
508 @value{VERSION}, @value{UPDATED}), which creates and extracts files
509 from archives.
510
511 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
512 2003, 2004 Free Software Foundation, Inc.
513
514 @quotation
515 Permission is granted to copy, distribute and/or modify this document
516 under the terms of the GNU Free Documentation License, Version 1.1 or
517 any later version published by the Free Software Foundation; with the
518 Invariant Sections being "GNU General Public License", with the
519 Front-Cover Texts being ``A GNU Manual,'' and with the Back-Cover Texts
520 as in (a) below. A copy of the license is included in the section
521 entitled "GNU Free Documentation License".
522
523 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
524 this GNU Manual. Buying copies from GNU Press supports the FSF in
525 developing GNU and promoting software freedom.''
526 @end quotation
527 @end copying
528
529 @dircategory Archiving
530 @direntry
531 * Tar: (tar). Making tape (or disk) archives.
532 @end direntry
533
534 @dircategory Individual utilities
535 @direntry
536 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
537 @end direntry
538
539 @shorttitlepage @acronym{GNU} @command{tar}
540
541 @titlepage
542 @title @acronym{GNU} tar: an archiver tool
543 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
544 @author Melissa Weisshaus, Jay Fenlason,
545 @author Thomas Bushnell, n/BSG, Amy Gorin
546 @c he said to remove it: Fran@,{c}ois Pinard
547 @c i'm thinking about how the author page *should* look. -mew 2may96
548
549 @page
550 @vskip 0pt plus 1filll
551 @insertcopying
552 @end titlepage
553
554 @ifnottex
555 @node Top
556 @top @acronym{GNU} tar: an archiver tool
557
558 @insertcopying
559
560 @cindex file archival
561 @cindex archiving files
562
563 The first part of this master menu lists the major nodes in this Info
564 document. The rest of the menu lists all the lower level nodes.
565 @end ifnottex
566
567 @c The master menu, created with texinfo-master-menu, goes here.
568 @c (However, getdate.texi's menu is interpolated by hand.)
569
570 @menu
571 * Introduction::
572 * Tutorial::
573 * tar invocation::
574 * operations::
575 * Backups::
576 * Choosing::
577 * Date input formats::
578 * Formats::
579 * Media::
580 * Free Software Needs Free Documentation::
581 * Copying This Manual::
582 * Index::
583
584 @detailmenu
585 --- The Detailed Node Listing ---
586
587 Introduction
588
589 * Book Contents:: What this Book Contains
590 * Definitions:: Some Definitions
591 * What tar Does:: What @command{tar} Does
592 * Naming tar Archives:: How @command{tar} Archives are Named
593 * Current status:: Current development status of @GNUTAR{}
594 * Authors:: @GNUTAR{} Authors
595 * Reports:: Reporting bugs or suggestions
596
597 Tutorial Introduction to @command{tar}
598
599 * assumptions::
600 * stylistic conventions::
601 * basic tar options:: Basic @command{tar} Operations and Options
602 * frequent operations::
603 * Two Frequent Options::
604 * create:: How to Create Archives
605 * list:: How to List Archives
606 * extract:: How to Extract Members from an Archive
607 * going further::
608
609 Two Frequently Used Options
610
611 * file tutorial::
612 * verbose tutorial::
613 * help tutorial::
614
615 How to Create Archives
616
617 * prepare for examples::
618 * Creating the archive::
619 * create verbose::
620 * short create::
621 * create dir::
622
623 How to List Archives
624
625 * list dir::
626
627 How to Extract Members from an Archive
628
629 * extracting archives::
630 * extracting files::
631 * extract dir::
632 * failing commands::
633
634 Invoking @GNUTAR{}
635
636 * Synopsis::
637 * using tar options::
638 * Styles::
639 * All Options::
640 * help::
641 * verbose::
642 * interactive::
643
644 The Three Option Styles
645
646 * Mnemonic Options:: Mnemonic Option Style
647 * Short Options:: Short Option Style
648 * Old Options:: Old Option Style
649 * Mixing:: Mixing Option Styles
650
651 All @command{tar} Options
652
653 * Operation Summary::
654 * Option Summary::
655 * Short Option Summary::
656
657 @GNUTAR{} Operations
658
659 * Basic tar::
660 * Advanced tar::
661 * create options::
662 * extract options::
663 * backup::
664 * Applications::
665 * looking ahead::
666
667 Advanced @GNUTAR{} Operations
668
669 * Operations::
670 * append::
671 * update::
672 * concatenate::
673 * delete::
674 * compare::
675
676 How to Add Files to Existing Archives: @code{--append}
677
678 * appending files:: Appending Files to an Archive
679 * multiple::
680
681 Updating an Archive
682
683 * how to update::
684
685 Options Used by @code{--create}
686
687 * Ignore Failed Read::
688
689 Options Used by @code{--extract}
690
691 * Reading:: Options to Help Read Archives
692 * Writing:: Changing How @command{tar} Writes Files
693 * Scarce:: Coping with Scarce Resources
694
695 Options to Help Read Archives
696
697 * read full records::
698 * Ignore Zeros::
699
700 Changing How @command{tar} Writes Files
701
702 * Dealing with Old Files::
703 * Overwrite Old Files::
704 * Keep Old Files::
705 * Keep Newer Files::
706 * Unlink First::
707 * Recursive Unlink::
708 * Modification Times::
709 * Setting Access Permissions::
710 * Writing to Standard Output::
711 * remove files::
712
713 Coping with Scarce Resources
714
715 * Starting File::
716 * Same Order::
717
718 Performing Backups and Restoring Files
719
720 * Full Dumps:: Using @command{tar} to Perform Full Dumps
721 * Inc Dumps:: Using @command{tar} to Perform Incremental Dumps
722 * incremental and listed-incremental:: The Incremental Options
723 * Backup Levels:: Levels of Backups
724 * Backup Parameters:: Setting Parameters for Backups and Restoration
725 * Scripted Backups:: Using the Backup Scripts
726 * Scripted Restoration:: Using the Restore Script
727
728 Setting Parameters for Backups and Restoration
729
730 * General-Purpose Variables::
731 * Magnetic Tape Control::
732 * User Hooks::
733 * backup-specs example:: An Example Text of @file{Backup-specs}
734
735 Choosing Files and Names for @command{tar}
736
737 * file:: Choosing the Archive's Name
738 * Selecting Archive Members::
739 * files:: Reading Names from a File
740 * exclude:: Excluding Some Files
741 * Wildcards::
742 * after:: Operating Only on New Files
743 * recurse:: Descending into Directories
744 * one:: Crossing Filesystem Boundaries
745
746 Reading Names from a File
747
748 * nul::
749
750 Excluding Some Files
751
752 * controlling pattern-patching with exclude::
753 * problems with exclude::
754
755 Crossing Filesystem Boundaries
756
757 * directory:: Changing Directory
758 * absolute:: Absolute File Names
759
760 Date input formats
761
762 * General date syntax:: Common rules.
763 * Calendar date items:: 19 Dec 1994.
764 * Time of day items:: 9:20pm.
765 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}, ...
766 * Day of week items:: Monday and others.
767 * Relative items in date strings:: next tuesday, 2 years ago.
768 * Pure numbers in date strings:: 19931219, 1440.
769 * Seconds since the Epoch:: @@1078100502.
770 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
771
772 Controlling the Archive Format
773
774 * Portability:: Making @command{tar} Archives More Portable
775 * Compression:: Using Less Space through Compression
776 * Attributes:: Handling File Attributes
777 * Standard:: The Standard Format
778 * Extensions:: @acronym{GNU} Extensions to the Archive Format
779 * cpio:: Comparison of @command{tar} and @command{cpio}
780
781 Making @command{tar} Archives More Portable
782
783 * Portable Names:: Portable Names
784 * dereference:: Symbolic Links
785 * old:: Old V7 Archives
786 * posix:: @acronym{POSIX} archives
787 * Checksumming:: Checksumming Problems
788 * Large or Negative Values:: Large files, negative time stamps, etc.
789
790 Using Less Space through Compression
791
792 * gzip:: Creating and Reading Compressed Archives
793 * sparse:: Archiving Sparse Files
794
795 Tapes and Other Archive Media
796
797 * Device:: Device selection and switching
798 * Remote Tape Server::
799 * Common Problems and Solutions::
800 * Blocking:: Blocking
801 * Many:: Many archives on one tape
802 * Using Multiple Tapes:: Using Multiple Tapes
803 * label:: Including a Label in the Archive
804 * verify::
805 * Write Protection::
806
807 Blocking
808
809 * Format Variations:: Format Variations
810 * Blocking Factor:: The Blocking Factor of an Archive
811
812 Many Archives on One Tape
813
814 * Tape Positioning:: Tape Positions and Tape Marks
815 * mt:: The @command{mt} Utility
816
817 Using Multiple Tapes
818
819 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
820 * Tape Files:: Tape Files
821
822 Copying This Manual
823
824 * GNU Free Documentation License:: License for copying this manual
825
826 @end detailmenu
827 @end menu
828
829 @node Introduction
830 @chapter Introduction
831
832 @GNUTAR{} creates
833 and manipulates @dfn{archives} which are actually collections of
834 many other files; the program provides users with an organized and
835 systematic method for controlling a large amount of data.
836 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
837 archives need not (and these days, typically do not) reside on tapes.
838
839 @menu
840 * Book Contents:: What this Book Contains
841 * Definitions:: Some Definitions
842 * What tar Does:: What @command{tar} Does
843 * Naming tar Archives:: How @command{tar} Archives are Named
844 * Current status:: Current development status of @GNUTAR{}
845 * Authors:: @GNUTAR{} Authors
846 * Reports:: Reporting bugs or suggestions
847 @end menu
848
849 @node Book Contents
850 @section What this Book Contains
851
852 The first part of this chapter introduces you to various terms that will
853 recur throughout the book. It also tells you who has worked on @GNUTAR{}
854 and its documentation, and where you should send bug reports
855 or comments.
856
857 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
858 gentle introduction for people who are new to using @command{tar}. It is
859 meant to be self contained, not requiring any reading from subsequent
860 chapters to make sense. It moves from topic to topic in a logical,
861 progressive order, building on information already explained.
862
863 Although the tutorial is paced and structured to allow beginners to
864 learn how to use @command{tar}, it is not intended solely for beginners.
865 The tutorial explains how to use the three most frequently used
866 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
867 two frequently used options (@samp{file} and @samp{verbose}). The other
868 chapters do not refer to the tutorial frequently; however, if a section
869 discusses something which is a complex variant of a basic concept, there
870 may be a cross reference to that basic concept. (The entire book,
871 including the tutorial, assumes that the reader understands some basic
872 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
873
874 The third chapter presents the remaining five operations, and
875 information about using @command{tar} options and option syntax.
876
877 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
878 than the reality. should think about whether this makes sense to say
879 here, or not.} The other chapters are meant to be used as a
880 reference. Each chapter presents everything that needs to be said
881 about a specific topic.
882
883 One of the chapters (@pxref{Date input formats}) exists in its
884 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
885 In addition, one section of this manual (@pxref{Standard}) contains a
886 big quote which is taken directly from @command{tar} sources.
887
888 In general, we give both long and short (abbreviated) option names
889 at least once in each section where the relevant option is covered, so
890 that novice readers will become familiar with both styles. (A few
891 options have no short versions, and the relevant sections will
892 indicate this.)
893
894 @node Definitions
895 @section Some Definitions
896
897 @cindex archive
898 @cindex tar archive
899 The @command{tar} program is used to create and manipulate @command{tar}
900 archives. An @dfn{archive} is a single file which contains the contents
901 of many files, while still identifying the names of the files, their
902 owner(s), and so forth. (In addition, archives record access
903 permissions, user and group, size in bytes, and last modification time.
904 Some archives also record the file names in each archived directory, as
905 well as other file and directory information.) You can use @command{tar}
906 to @dfn{create} a new archive in a specified directory.
907
908 @cindex member
909 @cindex archive member
910 @cindex file name
911 @cindex member name
912 The files inside an archive are called @dfn{members}. Within this
913 manual, we use the term @dfn{file} to refer only to files accessible in
914 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
915 @dfn{member} to refer only to the members of an archive. Similarly, a
916 @dfn{file name} is the name of a file, as it resides in the filesystem,
917 and a @dfn{member name} is the name of an archive member within the
918 archive.
919
920 @cindex extraction
921 @cindex unpacking
922 The term @dfn{extraction} refers to the process of copying an archive
923 member (or multiple members) into a file in the filesystem. Extracting
924 all the members of an archive is often called @dfn{extracting the
925 archive}. The term @dfn{unpack} can also be used to refer to the
926 extraction of many or all the members of an archive. Extracting an
927 archive does not destroy the archive's structure, just as creating an
928 archive does not destroy the copies of the files that exist outside of
929 the archive. You may also @dfn{list} the members in a given archive
930 (this is often thought of as ``printing'' them to the standard output,
931 or the command line), or @dfn{append} members to a pre-existing archive.
932 All of these operations can be performed using @command{tar}.
933
934 @node What tar Does
935 @section What @command{tar} Does
936
937 @cindex tar
938 The @command{tar} program provides the ability to create @command{tar}
939 archives, as well as various other kinds of manipulation. For example,
940 you can use @command{tar} on previously created archives to extract files,
941 to store additional files, or to update or list files which were already
942 stored.
943
944 Initially, @command{tar} archives were used to store files conveniently on
945 magnetic tape. The name @command{tar} comes from this use; it stands for
946 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
947 direct its output to available devices, files, or other programs (using
948 pipes). @command{tar} may even access remote devices or files (as archives).
949
950 @FIXME{the following table entries need a bit of work..}
951
952 You can use @command{tar} archives in many ways. We want to stress a few
953 of them: storage, backup, and transportation.
954
955 @table @asis
956 @item Storage
957 Often, @command{tar} archives are used to store related files for
958 convenient file transfer over a network. For example, the
959 @acronym{GNU} Project distributes its software bundled into
960 @command{tar} archives, so that all the files relating to a particular
961 program (or set of related programs) can be transferred as a single
962 unit.
963
964 A magnetic tape can store several files in sequence. However, the tape
965 has no names for these files; it only knows their relative position on
966 the tape. One way to store several files on one tape and retain their
967 names is by creating a @command{tar} archive. Even when the basic transfer
968 mechanism can keep track of names, as FTP can, the nuisance of handling
969 multiple files, directories, and multiple links makes @command{tar}
970 archives useful.
971
972 Archive files are also used for long-term storage. You can think of
973 this as transportation from the present into the future. (It is a
974 science-fiction idiom that you can move through time as well as in
975 space; the idea here is that @command{tar} can be used to move archives in
976 all dimensions, even time!)
977
978 @item Backup
979 Because the archive created by @command{tar} is capable of preserving
980 file information and directory structure, @command{tar} is commonly
981 used for performing full and incremental backups of disks. A backup
982 puts a collection of files (possibly pertaining to many users and
983 projects) together on a disk or a tape. This guards against
984 accidental destruction of the information in those files.
985 @GNUTAR{} has special features that allow it to be
986 used to make incremental and full dumps of all the files in a
987 filesystem.
988
989 @item Transportation
990 You can create an archive on one system, transfer it to another system,
991 and extract the contents there. This allows you to transport a group of
992 files from one system to another.
993 @end table
994
995 @node Naming tar Archives
996 @section How @command{tar} Archives are Named
997
998 Conventionally, @command{tar} archives are given names ending with
999 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
1000 but this manual follows that convention in order to accustom readers to
1001 it and to make examples more clear.
1002
1003 @cindex tar file
1004 @cindex entry
1005 @cindex tar entry
1006 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
1007 archive members as ``files'' or ``entries''. For people familiar with
1008 the operation of @command{tar}, this causes no difficulty. However, in
1009 this manual, we consistently refer to ``archives'' and ``archive
1010 members'' to make learning to use @command{tar} easier for novice users.
1011
1012 @node Current status
1013 @section Current development status of @GNUTAR{}
1014
1015 @GNUTAR{} is currently in the process of active development, whose
1016 primary aims are:
1017
1018 @itemize @bullet
1019 @item Improve compatibility between @GNUTAR{} and other @command{tar}
1020 implementations.
1021 @item Switch to using @acronym{POSIX} archives.
1022 @item Revise sparse file handling and multiple volume processing.
1023 @item Merge with the @acronym{GNU} @code{paxutils} project.
1024 @end itemize
1025
1026 Some of these aims are already attained, while others are still
1027 being worked upon. From the point of view of an end user, the
1028 following issues need special mentioning:
1029
1030 @table @asis
1031 @item Use of short option @option{-o}.
1032
1033 Earlier versions of @GNUTAR{} understood @option{-o} command line
1034 option as a synonym for @option{--old-archive}.
1035
1036 @GNUTAR{} starting from version 1.13.90 understands this option as
1037 a synonym for @option{--no-same-owner}. This is compatible with
1038 UNIX98 @command{tar} implementations.
1039
1040 However, to facilitate transition, @option{-o} option retains its
1041 old semantics when it is used with one of archive-creation commands.
1042 Users are encouraged to use @value{op-format-oldgnu} instead.
1043
1044 It is especially important, since versions of @acronym{GNU} Automake
1045 up to and including 1.8.4 invoke tar with this option to produce
1046 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
1047 of this issue and its implications.
1048
1049 Future versions of @GNUTAR{} will understand @option{-o} only as a
1050 synonym for @option{--no-same-owner}.
1051
1052 @item Use of short option @option{-l}
1053
1054 Earlier versions of @GNUTAR{} understood @option{-l} option as a
1055 synonym for @samp{--one-file-system}. Such usage is deprecated.
1056 For compatibility with other implementations future versions of
1057 @GNUTAR{} will understand this option as a synonym for
1058 @option{--check-links}.
1059
1060 @item Use of options @option{--portability} and @option{--old-archive}
1061
1062 These options are deprecated. Please use @option{--format=v7} instead.
1063
1064 @item Use of option @option{--posix}
1065
1066 This option is deprecated. Please use @option{--format=posix} instead.
1067 @end table
1068
1069 @node Authors
1070 @section @GNUTAR{} Authors
1071
1072 @GNUTAR{} was originally written by John Gilmore,
1073 and modified by many people. The @acronym{GNU} enhancements were
1074 written by Jay Fenlason, then Joy Kendall, and the whole package has
1075 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
1076 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
1077 numerous and kind users.
1078
1079 We wish to stress that @command{tar} is a collective work, and owes much to
1080 all those people who reported problems, offered solutions and other
1081 insights, or shared their thoughts and suggestions. An impressive, yet
1082 partial list of those contributors can be found in the @file{THANKS}
1083 file from the @GNUTAR{} distribution.
1084
1085 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
1086 sure i want to spell out the history in this detail, at least not for
1087 the printed book. i'm just not sure it needs to be said this way.
1088 i'll think about it.}
1089
1090 @FIXME{History is more important, and surely more interesting, than
1091 actual names. Quoting names without history would be meaningless. FP}
1092
1093 Jay Fenlason put together a draft of a @GNUTAR{}
1094 manual, borrowing notes from the original man page from John Gilmore.
1095 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
1096 Gorin worked on a tutorial and manual for @GNUTAR{}.
1097 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
1098 taking information from all these sources and merging them. Melissa
1099 Weisshaus finally edited and redesigned the book to create version
1100 1.12. @FIXME{update version number as necessary; i'm being
1101 optimistic!} @FIXME{Someone [maybe karl berry? maybe bob chassell?
1102 maybe melissa? maybe julie sussman?] needs to properly index the
1103 thing.}
1104
1105 For version 1.12, Daniel Hagerty contributed a great deal of technical
1106 consulting. In particular, he is the primary author of @ref{Backups}.
1107
1108 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
1109 (see @url{http://savannah.gnu.org/projects/tar}), and
1110 active development and maintenance work has started
1111 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
1112 Poznyakoff and Jeff Bailey.
1113
1114 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
1115
1116 @node Reports
1117 @section Reporting bugs or suggestions
1118
1119 @cindex bug reports
1120 @cindex reporting bugs
1121 If you find problems or have suggestions about this program or manual,
1122 please report them to @file{bug-tar@@gnu.org}.
1123
1124 When reporting a bug, please be sure to include as much detail as
1125 possible, in order to reproduce it. @FIXME{Be more specific, I'd
1126 like to make this node as detailed as 'Bug reporting' node in Emacs
1127 manual}.
1128
1129 @node Tutorial
1130 @chapter Tutorial Introduction to @command{tar}
1131
1132 This chapter guides you through some basic examples of three @command{tar}
1133 operations: @samp{--create}, @samp{--list}, and @samp{--extract}. If
1134 you already know how to use some other version of @command{tar}, then you
1135 may not need to read this chapter. This chapter omits most complicated
1136 details about how @command{tar} works.
1137
1138 @menu
1139 * assumptions::
1140 * stylistic conventions::
1141 * basic tar options:: Basic @command{tar} Operations and Options
1142 * frequent operations::
1143 * Two Frequent Options::
1144 * create:: How to Create Archives
1145 * list:: How to List Archives
1146 * extract:: How to Extract Members from an Archive
1147 * going further::
1148 @end menu
1149
1150 @node assumptions
1151 @section Assumptions this Tutorial Makes
1152
1153 This chapter is paced to allow beginners to learn about @command{tar}
1154 slowly. At the same time, we will try to cover all the basic aspects of
1155 these three operations. In order to accomplish both of these tasks, we
1156 have made certain assumptions about your knowledge before reading this
1157 manual, and the hardware you will be using:
1158
1159 @itemize @bullet
1160 @item
1161 Before you start to work through this tutorial, you should understand
1162 what the terms ``archive'' and ``archive member'' mean
1163 (@pxref{Definitions}). In addition, you should understand something
1164 about how Unix-type operating systems work, and you should know how to
1165 use some basic utilities. For example, you should know how to create,
1166 list, copy, rename, edit, and delete files and directories; how to
1167 change between directories; and how to figure out where you are in the
1168 filesystem. You should have some basic understanding of directory
1169 structure and how files are named according to which directory they are
1170 in. You should understand concepts such as standard output and standard
1171 input, what various definitions of the term ``argument'' mean, and the
1172 differences between relative and absolute path names. @FIXME{and what
1173 else?}
1174
1175 @item
1176 This manual assumes that you are working from your own home directory
1177 (unless we state otherwise). In this tutorial, you will create a
1178 directory to practice @command{tar} commands in. When we show path names,
1179 we will assume that those paths are relative to your home directory.
1180 For example, my home directory path is @file{/home/fsf/melissa}. All of
1181 my examples are in a subdirectory of the directory named by that path
1182 name; the subdirectory is called @file{practice}.
1183
1184 @item
1185 In general, we show examples of archives which exist on (or can be
1186 written to, or worked with from) a directory on a hard disk. In most
1187 cases, you could write those archives to, or work with them on any other
1188 device, such as a tape drive. However, some of the later examples in
1189 the tutorial and next chapter will not work on tape drives.
1190 Additionally, working with tapes is much more complicated than working
1191 with hard disks. For these reasons, the tutorial does not cover working
1192 with tape drives. @xref{Media}, for complete information on using
1193 @command{tar} archives with tape drives.
1194
1195 @FIXME{this is a cop out. need to add some simple tape drive info.}
1196 @end itemize
1197
1198 @node stylistic conventions
1199 @section Stylistic Conventions
1200
1201 In the examples, @samp{$} represents a typical shell prompt. It
1202 precedes lines you should type; to make this more clear, those lines are
1203 shown in @kbd{this font}, as opposed to lines which represent the
1204 computer's response; those lines are shown in @code{this font}, or
1205 sometimes @samp{like this}.
1206
1207 @c When we have lines which are too long to be
1208 @c displayed in any other way, we will show them like this:
1209
1210 @node basic tar options
1211 @section Basic @command{tar} Operations and Options
1212
1213 @command{tar} can take a wide variety of arguments which specify and define
1214 the actions it will have on the particular set of files or the archive.
1215 The main types of arguments to @command{tar} fall into one of two classes:
1216 operations, and options.
1217
1218 Some arguments fall into a class called @dfn{operations}; exactly one of
1219 these is both allowed and required for any instance of using @command{tar};
1220 you may @emph{not} specify more than one. People sometimes speak of
1221 @dfn{operating modes}. You are in a particular operating mode when you
1222 have specified the operation which specifies it; there are eight
1223 operations in total, and thus there are eight operating modes.
1224
1225 The other arguments fall into the class known as @dfn{options}. You are
1226 not required to specify any options, and you are allowed to specify more
1227 than one at a time (depending on the way you are using @command{tar} at
1228 that time). Some options are used so frequently, and are so useful for
1229 helping you type commands more carefully that they are effectively
1230 ``required''. We will discuss them in this chapter.
1231
1232 You can write most of the @command{tar} operations and options in any
1233 of three forms: long (mnemonic) form, short form, and old style. Some
1234 of the operations and options have no short or ``old'' forms; however,
1235 the operations and options which we will cover in this tutorial have
1236 corresponding abbreviations. @FIXME{make sure this is still the case,
1237 at the end}We will indicate those abbreviations appropriately to get
1238 you used to seeing them. (Note that the ``old style'' option forms
1239 exist in @GNUTAR{} for compatibility with Unix
1240 @command{tar}. We present a full discussion of this way of writing
1241 options and operations appears in @ref{Old Options}, and we discuss
1242 the other two styles of writing options in @ref{Mnemonic Options}, and
1243 @ref{Short Options}.)
1244
1245 In the examples and in the text of this tutorial, we usually use the
1246 long forms of operations and options; but the ``short'' forms produce
1247 the same result and can make typing long @command{tar} commands easier.
1248 For example, instead of typing
1249
1250 @smallexample
1251 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
1252 @end smallexample
1253
1254 @noindent
1255 you can type
1256 @smallexample
1257 @kbd{tar -c -v -f afiles.tar apple angst aspic}
1258 @end smallexample
1259
1260 @noindent
1261 or even
1262 @smallexample
1263 @kbd{tar -cvf afiles.tar apple angst aspic}
1264 @end smallexample
1265
1266 @noindent
1267 For more information on option syntax, see @ref{Advanced tar}. In
1268 discussions in the text, when we name an option by its long form, we
1269 also give the corresponding short option in parentheses.
1270
1271 The term, ``option'', can be confusing at times, since ``operations''
1272 are often lumped in with the actual, @emph{optional} ``options'' in certain
1273 general class statements. For example, we just talked about ``short and
1274 long forms of options and operations''. However, experienced @command{tar}
1275 users often refer to these by shorthand terms such as, ``short and long
1276 options''. This term assumes that the ``operations'' are included, also.
1277 Context will help you determine which definition of ``options'' to use.
1278
1279 Similarly, the term ``command'' can be confusing, as it is often used in
1280 two different ways. People sometimes refer to @command{tar} ``commands''.
1281 A @command{tar} @dfn{command} is the entire command line of user input
1282 which tells @command{tar} what to do --- including the operation, options,
1283 and any arguments (file names, pipes, other commands, etc). However,
1284 you will also sometimes hear the term ``the @command{tar} command''. When
1285 the word ``command'' is used specifically like this, a person is usually
1286 referring to the @command{tar} @emph{operation}, not the whole line.
1287 Again, use context to figure out which of the meanings the speaker
1288 intends.
1289
1290 @node frequent operations
1291 @section The Three Most Frequently Used Operations
1292
1293 Here are the three most frequently used operations (both short and long
1294 forms), as well as a brief description of their meanings. The rest of
1295 this chapter will cover how to use these operations in detail. We will
1296 present the rest of the operations in the next chapter.
1297
1298 @table @kbd
1299 @item --create
1300 @itemx -c
1301 Create a new @command{tar} archive.
1302 @item --list
1303 @itemx -t
1304 List the contents of an archive.
1305 @item --extract
1306 @itemx -x
1307 Extract one or more members from an archive.
1308 @end table
1309
1310 @node Two Frequent Options
1311 @section Two Frequently Used Options
1312
1313 To understand how to run @command{tar} in the three operating modes listed
1314 previously, you also need to understand how to use two of the options to
1315 @command{tar}: @samp{--file} (which takes an archive file as an argument)
1316 and @samp{--verbose}. (You are usually not @emph{required} to specify
1317 either of these options when you run @command{tar}, but they can be very
1318 useful in making things more clear and helping you avoid errors.)
1319
1320 @menu
1321 * file tutorial::
1322 * verbose tutorial::
1323 * help tutorial::
1324 @end menu
1325
1326 @node file tutorial
1327 @unnumberedsubsec The @samp{--file} Option
1328
1329 @table @kbd
1330 @item --file=@var{archive-name}
1331 @itemx -f @var{archive-name}
1332 Specify the name of an archive file.
1333 @end table
1334
1335 You can specify an argument for the @value{op-file} option whenever you
1336 use @command{tar}; this option determines the name of the archive file
1337 that @command{tar} will work on.
1338
1339 If you don't specify this argument, then @command{tar} will use a
1340 default, usually some physical tape drive attached to your machine.
1341 If there is no tape drive attached, or the default is not meaningful,
1342 then @command{tar} will print an error message. The error message might
1343 look roughly like one of the following:
1344
1345 @smallexample
1346 tar: can't open /dev/rmt8 : No such device or address
1347 tar: can't open /dev/rsmt0 : I/O error
1348 @end smallexample
1349
1350 @noindent
1351 To avoid confusion, we recommend that you always specify an archive file
1352 name by using @value{op-file} when writing your @command{tar} commands.
1353 For more information on using the @value{op-file} option, see
1354 @ref{file}.
1355
1356 @node verbose tutorial
1357 @unnumberedsubsec The @samp{--verbose} Option
1358
1359 @table @kbd
1360 @item --verbose
1361 @itemx -v
1362 Show the files being worked on as @command{tar} is running.
1363 @end table
1364
1365 @value{op-verbose} shows details about the results of running
1366 @command{tar}. This can be especially useful when the results might not be
1367 obvious. For example, if you want to see the progress of @command{tar} as
1368 it writes files into the archive, you can use the @samp{--verbose}
1369 option. In the beginning, you may find it useful to use
1370 @samp{--verbose} at all times; when you are more accustomed to
1371 @command{tar}, you will likely want to use it at certain times but not at
1372 others. We will use @samp{--verbose} at times to help make something
1373 clear, and we will give many examples both using and not using
1374 @samp{--verbose} to show the differences.
1375
1376 Sometimes, a single instance of @samp{--verbose} on the command line
1377 will show a full, @samp{ls} style listing of an archive or files,
1378 @c FIXME: Describe the exact output format, e.g., how hard links are displayed.
1379 giving sizes, owners, and similar information. Other times,
1380 @samp{--verbose} will only show files or members that the particular
1381 operation is operating on at the time. In the latter case, you can
1382 use @samp{--verbose} twice in a command to get a listing such as that
1383 in the former case. For example, instead of saying
1384
1385 @smallexample
1386 @kbd{tar -cvf afiles.tar apple angst aspic}
1387 @end smallexample
1388
1389 @noindent
1390 above, you might say
1391
1392 @smallexample
1393 @kbd{tar -cvvf afiles.tar apple angst aspic}
1394 @end smallexample
1395
1396 @noindent
1397 This works equally well using short or long forms of options. Using
1398 long forms, you would simply write out the mnemonic form of the option
1399 twice, like this:
1400
1401 @smallexample
1402 $ @kbd{tar --create --verbose --verbose @dots{}}
1403 @end smallexample
1404
1405 @noindent
1406 Note that you must double the hyphens properly each time.
1407
1408 Later in the tutorial, we will give examples using @w{@samp{--verbose
1409 --verbose}}.
1410
1411 @node help tutorial
1412 @unnumberedsubsec Getting Help: Using the @code{--help} Option
1413
1414 @table @kbd
1415 @item --help
1416
1417 The @samp{--help} option to @command{tar} prints out a very brief list of
1418 all operations and option available for the current version of
1419 @command{tar} available on your system.
1420 @end table
1421
1422 @node create
1423 @section How to Create Archives
1424 @UNREVISED
1425
1426 One of the basic operations of @command{tar} is @value{op-create}, which
1427 you use to create a @command{tar} archive. We will explain
1428 @samp{--create} first because, in order to learn about the other
1429 operations, you will find it useful to have an archive available to
1430 practice on.
1431
1432 To make this easier, in this section you will first create a directory
1433 containing three files. Then, we will show you how to create an
1434 @emph{archive} (inside the new directory). Both the directory, and
1435 the archive are specifically for you to practice on. The rest of this
1436 chapter and the next chapter will show many examples using this
1437 directory and the files you will create: some of those files may be
1438 other directories and other archives.
1439
1440 The three files you will archive in this example are called
1441 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1442 @file{collection.tar}.
1443
1444 This section will proceed slowly, detailing how to use @samp{--create}
1445 in @code{verbose} mode, and showing examples using both short and long
1446 forms. In the rest of the tutorial, and in the examples in the next
1447 chapter, we will proceed at a slightly quicker pace. This section
1448 moves more slowly to allow beginning users to understand how
1449 @command{tar} works.
1450
1451 @menu
1452 * prepare for examples::
1453 * Creating the archive::
1454 * create verbose::
1455 * short create::
1456 * create dir::
1457 @end menu
1458
1459 @node prepare for examples
1460 @subsection Preparing a Practice Directory for Examples
1461
1462 To follow along with this and future examples, create a new directory
1463 called @file{practice} containing files called @file{blues}, @file{folk}
1464 and @file{jazz}. The files can contain any information you like:
1465 ideally, they should contain information which relates to their names,
1466 and be of different lengths. Our examples assume that @file{practice}
1467 is a subdirectory of your home directory.
1468
1469 Now @command{cd} to the directory named @file{practice}; @file{practice}
1470 is now your @dfn{working directory}. (@emph{Please note}: Although
1471 the full path name of this directory is
1472 @file{/@var{homedir}/practice}, in our examples we will refer to
1473 this directory as @file{practice}; the @var{homedir} is presumed.
1474
1475 In general, you should check that the files to be archived exist where
1476 you think they do (in the working directory) by running @command{ls}.
1477 Because you just created the directory and the files and have changed to
1478 that directory, you probably don't need to do that this time.
1479
1480 It is very important to make sure there isn't already a file in the
1481 working directory with the archive name you intend to use (in this case,
1482 @samp{collection.tar}), or that you don't care about its contents.
1483 Whenever you use @samp{create}, @command{tar} will erase the current
1484 contents of the file named by @value{op-file} if it exists. @command{tar}
1485 will not tell you if you are about to overwrite an archive unless you
1486 specify an option which does this. @FIXME{xref to the node for
1487 --backup!}To add files to an existing archive, you need to use a
1488 different option, such as @value{op-append}; see @ref{append} for
1489 information on how to do this.
1490
1491 @node Creating the archive
1492 @subsection Creating the Archive
1493
1494 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1495 archive named @file{collection.tar}, use the following command:
1496
1497 @smallexample
1498 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1499 @end smallexample
1500
1501 The order of the arguments is not very important, @emph{when using long
1502 option forms}. You could also say:
1503
1504 @smallexample
1505 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1506 @end smallexample
1507
1508 @noindent
1509 However, you can see that this order is harder to understand; this is
1510 why we will list the arguments in the order that makes the commands
1511 easiest to understand (and we encourage you to do the same when you use
1512 @command{tar}, to avoid errors).
1513
1514 Note that the part of the command which says,
1515 @w{@kbd{--file=collection.tar}} is considered to be @emph{one} argument.
1516 If you substituted any other string of characters for
1517 @kbd{collection.tar}, then that string would become the name of the
1518 archive file you create.
1519
1520 The order of the options becomes more important when you begin to use
1521 short forms. With short forms, if you type commands in the wrong order
1522 (even if you type them correctly in all other ways), you may end up with
1523 results you don't expect. For this reason, it is a good idea to get
1524 into the habit of typing options in the order that makes inherent sense.
1525 @xref{short create}, for more information on this.
1526
1527 In this example, you type the command as shown above: @samp{--create}
1528 is the operation which creates the new archive
1529 (@file{collection.tar}), and @samp{--file} is the option which lets
1530 you give it the name you chose. The files, @file{blues}, @file{folk},
1531 and @file{jazz}, are now members of the archive, @file{collection.tar}
1532 (they are @dfn{file name arguments} to the @samp{--create} operation).
1533 @FIXME{xref here to the discussion of file name args?}Now that they are
1534 in the archive, they are called @emph{archive members}, not files.
1535 (@pxref{Definitions,members}).
1536
1537 When you create an archive, you @emph{must} specify which files you
1538 want placed in the archive. If you do not specify any archive
1539 members, @GNUTAR{} will complain.
1540
1541 If you now list the contents of the working directory (@kbd{ls}), you will
1542 find the archive file listed as well as the files you saw previously:
1543
1544 @smallexample
1545 blues folk jazz collection.tar
1546 @end smallexample
1547
1548 @noindent
1549 Creating the archive @samp{collection.tar} did not destroy the copies of
1550 the files in the directory.
1551
1552 Keep in mind that if you don't indicate an operation, @command{tar} will not
1553 run and will prompt you for one. If you don't name any files, @command{tar}
1554 will complain. You must have write access to the working directory,
1555 or else you will not be able to create an archive in that directory.
1556
1557 @emph{Caution}: Do not attempt to use @value{op-create} to add files to
1558 an existing archive; it will delete the archive and write a new one.
1559 Use @value{op-append} instead. @xref{append}.
1560
1561 @node create verbose
1562 @subsection Running @samp{--create} with @samp{--verbose}
1563
1564 If you include the @value{op-verbose} option on the command line,
1565 @command{tar} will list the files it is acting on as it is working. In
1566 verbose mode, the @code{create} example above would appear as:
1567
1568 @smallexample
1569 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1570 blues
1571 folk
1572 jazz
1573 @end smallexample
1574
1575 This example is just like the example we showed which did not use
1576 @samp{--verbose}, except that @command{tar} generated the remaining lines
1577 @iftex
1578 (note the different font styles).
1579 @end iftex
1580 @ifinfo
1581 .
1582 @end ifinfo
1583
1584 In the rest of the examples in this chapter, we will frequently use
1585 @code{verbose} mode so we can show actions or @command{tar} responses that
1586 you would otherwise not see, and which are important for you to
1587 understand.
1588
1589 @node short create
1590 @subsection Short Forms with @samp{create}
1591
1592 As we said before, the @value{op-create} operation is one of the most
1593 basic uses of @command{tar}, and you will use it countless times.
1594 Eventually, you will probably want to use abbreviated (or ``short'')
1595 forms of options. A full discussion of the three different forms that
1596 options can take appears in @ref{Styles}; for now, here is what the
1597 previous example (including the @value{op-verbose} option) looks like
1598 using short option forms:
1599
1600 @smallexample
1601 $ @kbd{tar -cvf collection.tar blues folk jazz}
1602 blues
1603 folk
1604 jazz
1605 @end smallexample
1606
1607 @noindent
1608 As you can see, the system responds the same no matter whether you use
1609 long or short option forms.
1610
1611 @FIXME{i don't like how this is worded:} One difference between using
1612 short and long option forms is that, although the exact placement of
1613 arguments following options is no more specific when using short forms,
1614 it is easier to become confused and make a mistake when using short
1615 forms. For example, suppose you attempted the above example in the
1616 following way:
1617
1618 @smallexample
1619 $ @kbd{tar -cfv collection.tar blues folk jazz}
1620 @end smallexample
1621
1622 @noindent
1623 In this case, @command{tar} will make an archive file called @file{v},
1624 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1625 the @samp{v} is the closest ``file name'' to the @samp{-f} option, and
1626 is thus taken to be the chosen archive file name. @command{tar} will try
1627 to add a file called @file{collection.tar} to the @file{v} archive file;
1628 if the file @file{collection.tar} did not already exist, @command{tar} will
1629 report an error indicating that this file does not exist. If the file
1630 @file{collection.tar} does already exist (e.g., from a previous command
1631 you may have run), then @command{tar} will add this file to the archive.
1632 Because the @samp{-v} option did not get registered, @command{tar} will not
1633 run under @samp{verbose} mode, and will not report its progress.
1634
1635 The end result is that you may be quite confused about what happened,
1636 and possibly overwrite a file. To illustrate this further, we will show
1637 you how an example we showed previously would look using short forms.
1638
1639 This example,
1640
1641 @smallexample
1642 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1643 @end smallexample
1644
1645 @noindent
1646 is confusing as it is. When shown using short forms, however, it
1647 becomes much more so:
1648
1649 @smallexample
1650 $ @kbd{tar blues -c folk -f collection.tar jazz}
1651 @end smallexample
1652
1653 @noindent
1654 It would be very easy to put the wrong string of characters
1655 immediately following the @samp{-f}, but doing that could sacrifice
1656 valuable data.
1657
1658 For this reason, we recommend that you pay very careful attention to
1659 the order of options and placement of file and archive names,
1660 especially when using short option forms. Not having the option name
1661 written out mnemonically can affect how well you remember which option
1662 does what, and therefore where different names have to be placed.
1663 (Placing options in an unusual order can also cause @command{tar} to
1664 report an error if you have set the shell environment variable
1665 @env{POSIXLY_CORRECT}.)
1666
1667 @node create dir
1668 @subsection Archiving Directories
1669
1670 @cindex Archiving Directories
1671 @cindex Directories, Archiving
1672 You can archive a directory by specifying its directory name as a
1673 file name argument to @command{tar}. The files in the directory will be
1674 archived relative to the working directory, and the directory will be
1675 re-created along with its contents when the archive is extracted.
1676
1677 To archive a directory, first move to its superior directory. If you
1678 have followed the previous instructions in this tutorial, you should
1679 type:
1680
1681 @smallexample
1682 $ @kbd{cd ..}
1683 $
1684 @end smallexample
1685
1686 @noindent
1687 This will put you into the directory which contains @file{practice},
1688 i.e. your home directory. Once in the superior directory, you can
1689 specify the subdirectory, @file{practice}, as a file name argument. To
1690 store @file{practice} in the new archive file @file{music.tar}, type:
1691
1692 @smallexample
1693 $ @kbd{tar --create --verbose --file=music.tar practice}
1694 @end smallexample
1695
1696 @noindent
1697 @command{tar} should output:
1698
1699 @smallexample
1700 practice/
1701 practice/blues
1702 practice/folk
1703 practice/jazz
1704 practice/collection.tar
1705 @end smallexample
1706
1707 Note that the archive thus created is not in the subdirectory
1708 @file{practice}, but rather in the current working directory---the
1709 directory from which @command{tar} was invoked. Before trying to archive a
1710 directory from its superior directory, you should make sure you have
1711 write access to the superior directory itself, not only the directory
1712 you are trying archive with @command{tar}. For example, you will probably
1713 not be able to store your home directory in an archive by invoking
1714 @command{tar} from the root directory; @value{xref-absolute-names}. (Note
1715 also that @file{collection.tar}, the original archive file, has itself
1716 been archived. @command{tar} will accept any file as a file to be
1717 archived, regardless of its content. When @file{music.tar} is
1718 extracted, the archive file @file{collection.tar} will be re-written
1719 into the file system).
1720
1721 If you give @command{tar} a command such as
1722
1723 @smallexample
1724 $ @kbd{tar --create --file=foo.tar .}
1725 @end smallexample
1726
1727 @noindent
1728 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1729 dumped}. This happens because @command{tar} creates the archive
1730 @file{foo.tar} in the current directory before putting any files into
1731 it. Then, when @command{tar} attempts to add all the files in the
1732 directory @file{.} to the archive, it notices that the file
1733 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1734 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1735 will continue in this case, and create the archive
1736 normally, except for the exclusion of that one file. (@emph{Please
1737 note:} Other versions of @command{tar} are not so clever; they will
1738 enter an infinite loop when this happens, so you should not depend on
1739 this behavior unless you are certain you are running @GNUTAR{}.)
1740 @FIXME{bob doesn't like this sentence, since he does
1741 it all the time, and we've been doing it in the editing passes for
1742 this manual: In general, make sure that the archive is not inside a
1743 directory being dumped.}
1744
1745 @node list
1746 @section How to List Archives
1747
1748 Frequently, you will find yourself wanting to determine exactly what a
1749 particular archive contains. You can use the @value{op-list} operation
1750 to get the member names as they currently appear in the archive, as well
1751 as various attributes of the files at the time they were archived. For
1752 example, you can examine the archive @file{collection.tar} that you
1753 created in the last section with the command,
1754
1755 @smallexample
1756 $ @kbd{tar --list --file=collection.tar}
1757 @end smallexample
1758
1759 @noindent
1760 The output of @command{tar} would then be:
1761
1762 @smallexample
1763 blues
1764 folk
1765 jazz
1766 @end smallexample
1767
1768 @FIXME{we hope this will change. if it doesn't, need to show the
1769 creation of bfiles somewhere above!!! : }
1770
1771 @noindent
1772 The archive @file{bfiles.tar} would list as follows:
1773
1774 @smallexample
1775 ./birds
1776 baboon
1777 ./box
1778 @end smallexample
1779
1780 @noindent
1781 Be sure to use a @value{op-file} option just as with @value{op-create}
1782 to specify the name of the archive.
1783
1784 If you use the @value{op-verbose} option with @samp{--list}, then
1785 @command{tar} will print out a listing reminiscent of @w{@samp{ls -l}},
1786 showing owner, file size, and so forth.
1787
1788 If you had used @value{op-verbose} mode, the example above would look
1789 like:
1790
1791 @smallexample
1792 $ @kbd{tar --list --verbose --file=collection.tar folk}
1793 -rw-rw-rw- myself user 62 1990-05-23 10:55 folk
1794 @end smallexample
1795
1796 @cindex File name arguments, using @code{--list} with
1797 @cindex @code{--list} with file name arguments
1798 You can specify one or more individual member names as arguments when
1799 using @samp{list}. In this case, @command{tar} will only list the
1800 names of members you identify. For example, @w{@kbd{tar --list
1801 --file=afiles.tar apple}} would only print @file{apple}.
1802
1803 @FIXME{we hope the relevant aspects of this will change:}Because
1804 @command{tar} preserves paths, file names must be specified as they appear
1805 in the archive (ie., relative to the directory from which the archive
1806 was created). Therefore, it is essential when specifying member names
1807 to @command{tar} that you give the exact member names. For example,
1808 @w{@kbd{tar --list --file=bfiles birds}} would produce an error message
1809 something like @samp{tar: birds: Not found in archive}, because there is
1810 no member named @file{birds}, only one named @file{./birds}. While the
1811 names @file{birds} and @file{./birds} name the same file, @emph{member}
1812 names are compared using a simplistic name comparison, in which an exact
1813 match is necessary. @xref{absolute}.
1814
1815 However, @w{@kbd{tar --list --file=collection.tar folk}} would respond
1816 with @file{folk}, because @file{folk} is in the archive file
1817 @file{collection.tar}. If you are not sure of the exact file name, try
1818 listing all the files in the archive and searching for the one you
1819 expect to find; remember that if you use @samp{--list} with no file
1820 names as arguments, @command{tar} will print the names of all the members
1821 stored in the specified archive.
1822
1823 @menu
1824 * list dir::
1825 @end menu
1826
1827 @node list dir
1828 @unnumberedsubsec Listing the Contents of a Stored Directory
1829
1830 To get information about the contents of an archived directory,
1831 use the directory name as a file name argument in conjunction with
1832 @value{op-list}. To find out file attributes, include the
1833 @value{op-verbose} option.
1834
1835 For example, to find out about files in the directory @file{practice}, in
1836 the archive file @file{music.tar}, type:
1837
1838 @smallexample
1839 $ @kbd{tar --list --verbose --file=music.tar practice}
1840 @end smallexample
1841
1842 @command{tar} responds:
1843
1844 @smallexample
1845 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1846 -rw-rw-rw- myself user 42 1990-05-21 13:29 practice/blues
1847 -rw-rw-rw- myself user 62 1990-05-23 10:55 practice/folk
1848 -rw-rw-rw- myself user 40 1990-05-21 13:30 practice/jazz
1849 -rw-rw-rw- myself user 10240 1990-05-31 21:49 practice/collection.tar
1850 @end smallexample
1851
1852 When you use a directory name as a file name argument, @command{tar} acts on
1853 all the files (including sub-directories) in that directory.
1854
1855 @node extract
1856 @section How to Extract Members from an Archive
1857 @UNREVISED
1858 @cindex Extraction
1859 @cindex Retrieving files from an archive
1860 @cindex Resurrecting files from an archive
1861
1862 Creating an archive is only half the job---there is no point in storing
1863 files in an archive if you can't retrieve them. The act of retrieving
1864 members from an archive so they can be used and manipulated as
1865 unarchived files again is called @dfn{extraction}. To extract files
1866 from an archive, use the @value{op-extract} operation. As with
1867 @value{op-create}, specify the name of the archive with @value{op-file}.
1868 Extracting an archive does not modify the archive in any way; you can
1869 extract it multiple times if you want or need to.
1870
1871 Using @samp{--extract}, you can extract an entire archive, or specific
1872 files. The files can be directories containing other files, or not. As
1873 with @value{op-create} and @value{op-list}, you may use the short or the
1874 long form of the operation without affecting the performance.
1875
1876 @menu
1877 * extracting archives::
1878 * extracting files::
1879 * extract dir::
1880 * extracting untrusted archives::
1881 * failing commands::
1882 @end menu
1883
1884 @node extracting archives
1885 @subsection Extracting an Entire Archive
1886
1887 To extract an entire archive, specify the archive file name only, with
1888 no individual file names as arguments. For example,
1889
1890 @smallexample
1891 $ @kbd{tar -xvf collection.tar}
1892 @end smallexample
1893
1894 @noindent
1895 produces this:
1896
1897 @smallexample
1898 -rw-rw-rw- me user 28 1996-10-18 16:31 jazz
1899 -rw-rw-rw- me user 21 1996-09-23 16:44 blues
1900 -rw-rw-rw- me user 20 1996-09-23 16:44 folk
1901 @end smallexample
1902
1903 @node extracting files
1904 @subsection Extracting Specific Files
1905
1906 To extract specific archive members, give their exact member names as
1907 arguments, as printed by @value{op-list}. If you had mistakenly deleted
1908 one of the files you had placed in the archive @file{collection.tar}
1909 earlier (say, @file{blues}), you can extract it from the archive without
1910 changing the archive's structure. It will be identical to the original
1911 file @file{blues} that you deleted. @FIXME{At the time of this
1912 writing, atime and ctime are not restored. Since this is a tutorial
1913 for a beginnig user, it should hardly be mentioned here. Maybe in
1914 a footnote? --gray}.
1915
1916 First, make sure you are in the @file{practice} directory, and list the
1917 files in the directory. Now, delete the file, @samp{blues}, and list
1918 the files in the directory again.
1919
1920 You can now extract the member @file{blues} from the archive file
1921 @file{collection.tar} like this:
1922
1923 @smallexample
1924 $ @kbd{tar --extract --file=collection.tar blues}
1925 @end smallexample
1926
1927 @noindent
1928 If you list the files in the directory again, you will see that the file
1929 @file{blues} has been restored, with its original permissions, creation
1930 times, and owner.@FIXME{This is only accidentally true, but not in
1931 general. In most cases, one has to be root for restoring the owner, and
1932 use a special option for restoring permissions. Here, it just happens
1933 that the restoring user is also the owner of the archived members, and
1934 that the current @code{umask} is compatible with original permissions.}
1935 (These parameters will be identical to those which
1936 the file had when you originally placed it in the archive; any changes
1937 you may have made before deleting the file from the file system,
1938 however, will @emph{not} have been made to the archive member.) The
1939 archive file, @samp{collection.tar}, is the same as it was before you
1940 extracted @samp{blues}. You can confirm this by running @command{tar} with
1941 @value{op-list}.
1942
1943 @FIXME{we hope this will change:}Remember that as with other operations,
1944 specifying the exact member name is important. @w{@kbd{tar --extract
1945 --file=bfiles.tar birds}} will fail, because there is no member named
1946 @file{birds}. To extract the member named @file{./birds}, you must
1947 specify @w{@kbd{tar --extract --file=bfiles.tar ./birds}}. To find the
1948 exact member names of the members of an archive, use @value{op-list}
1949 (@pxref{list}).
1950
1951 You can extract a file to standard output by combining the above options
1952 with the @value{op-to-stdout} option (@pxref{Writing to Standard
1953 Output}).
1954
1955 If you give the @value{op-verbose} option, then @value{op-extract} will
1956 print the names of the archive members as it extracts them.
1957
1958 @node extract dir
1959 @subsection Extracting Files that are Directories
1960
1961 Extracting directories which are members of an archive is similar to
1962 extracting other files. The main difference to be aware of is that if
1963 the extracted directory has the same name as any directory already in
1964 the working directory, then files in the extracted directory will be
1965 placed into the directory of the same name. Likewise, if there are
1966 files in the pre-existing directory with the same names as the members
1967 which you extract, the files from the extracted archive will replace
1968 the files already in the working directory (and possible
1969 subdirectories). This will happen regardless of whether or not the
1970 files in the working directory were more recent than those extracted
1971 (there exist, however, special options that alter this behavior
1972 @pxref{Writing}).
1973
1974 However, if a file was stored with a directory name as part of its file
1975 name, and that directory does not exist under the working directory when
1976 the file is extracted, @command{tar} will create the directory.
1977
1978 We can demonstrate how to use @samp{--extract} to extract a directory
1979 file with an example. Change to the @file{practice} directory if you
1980 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1981 go back to the parent directory and extract the archive
1982 @file{music.tar}. You may either extract the entire archive, or you may
1983 extract only the files you just deleted. To extract the entire archive,
1984 don't give any file names as arguments after the archive name
1985 @file{music.tar}. To extract only the files you deleted, use the
1986 following command:
1987
1988 @smallexample
1989 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1990 practice/folk
1991 practice/jazz
1992 @end smallexample
1993
1994 @noindent
1995 If you were to specify two @value{op-verbose} options, @command{tar}
1996 would have displayed more detail about the extracted files, as shown
1997 in the example below:
1998
1999 @smallexample
2000 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
2001 -rw-rw-rw- me user 28 1996-10-18 16:31 practice/jazz
2002 -rw-rw-rw- me user 20 1996-09-23 16:44 practice/folk
2003 @end smallexample
2004
2005 @noindent
2006 Because you created the directory with @file{practice} as part of the
2007 file names of each of the files by archiving the @file{practice}
2008 directory as @file{practice}, you must give @file{practice} as part
2009 of the file names when you extract those files from the archive.
2010
2011 @FIXME{IMPORTANT! show the final structure, here. figure out what it
2012 will be.}
2013
2014 @node extracting untrusted archives
2015 @subsection Extracting Archives from Untrusted Sources
2016
2017 Extracting files from archives can overwrite files that already exist.
2018 If you receive an archive from an untrusted source, you should make a
2019 new directory and extract into that directory, so that you don't have
2020 to worry about the extraction overwriting one of your existing files.
2021 For example, if @file{untrusted.tar} came from somewhere else on the
2022 Internet, and you don't necessarily trust its contents, you can
2023 extract it as follows:
2024
2025 @smallexample
2026 $ @kbd{mkdir newdir}
2027 $ @kbd{cd newdir}
2028 $ @kbd{tar -xvf ../untrusted.tar}
2029 @end smallexample
2030
2031 It is also a good practice to examine contents of the archive
2032 before extracting it, using @value{op-list} option, possibly combined
2033 with @value{op-verbose}.
2034
2035 @node failing commands
2036 @subsection Commands That Will Fail
2037
2038 Here are some sample commands you might try which will not work, and why
2039 they won't work.
2040
2041 If you try to use this command,
2042
2043 @smallexample
2044 $ @kbd{tar -xvf music.tar folk jazz}
2045 @end smallexample
2046
2047 @noindent
2048 you will get the following response:
2049
2050 @smallexample
2051 tar: folk: Not found in archive
2052 tar: jazz: Not found in archive
2053 $
2054 @end smallexample
2055
2056 @noindent
2057 This is because these files were not originally @emph{in} the parent
2058 directory @file{..}, where the archive is located; they were in the
2059 @file{practice} directory, and their file names reflect this:
2060
2061 @smallexample
2062 $ @kbd{tar -tvf music.tar}
2063 practice/folk
2064 practice/jazz
2065 practice/rock
2066 @end smallexample
2067
2068 @FIXME{make sure the above works when going through the examples in
2069 order...}
2070
2071 @noindent
2072 Likewise, if you try to use this command,
2073
2074 @smallexample
2075 $ @kbd{tar -tvf music.tar folk jazz}
2076 @end smallexample
2077
2078 @noindent
2079 you would get a similar response. Members with those names are not in the
2080 archive. You must use the correct member names in order to extract the
2081 files from the archive.
2082
2083 If you have forgotten the correct names of the files in the archive,
2084 use @w{@kbd{tar --list --verbose}} to list them correctly.
2085
2086 @FIXME{more examples, here? hag thinks it's a good idea.}
2087
2088 @node going further
2089 @section Going Further Ahead in this Manual
2090
2091 @FIXME{need to write up a node here about the things that are going to
2092 be in the rest of the manual.}
2093
2094 @node tar invocation
2095 @chapter Invoking @GNUTAR{}
2096 @UNREVISED
2097
2098 This chapter is about how one invokes the @GNUTAR{}
2099 command, from the command synopsis (@pxref{Synopsis}). There are
2100 numerous options, and many styles for writing them. One mandatory
2101 option specifies the operation @command{tar} should perform
2102 (@pxref{Operation Summary}), other options are meant to detail how
2103 this operation should be performed (@pxref{Option Summary}).
2104 Non-option arguments are not always interpreted the same way,
2105 depending on what the operation is.
2106
2107 You will find in this chapter everything about option styles and rules for
2108 writing them (@pxref{Styles}). On the other hand, operations and options
2109 are fully described elsewhere, in other chapters. Here, you will find
2110 only synthetic descriptions for operations and options, together with
2111 pointers to other parts of the @command{tar} manual.
2112
2113 Some options are so special they are fully described right in this
2114 chapter. They have the effect of inhibiting the normal operation of
2115 @command{tar} or else, they globally alter the amount of feedback the user
2116 receives about what is going on. These are the @value{op-help} and
2117 @value{op-version} (@pxref{help}), @value{op-verbose} (@pxref{verbose})
2118 and @value{op-interactive} options (@pxref{interactive}).
2119
2120 @menu
2121 * Synopsis::
2122 * using tar options::
2123 * Styles::
2124 * All Options::
2125 * help::
2126 * verbose::
2127 * interactive::
2128 @end menu
2129
2130 @node Synopsis
2131 @section General Synopsis of @command{tar}
2132
2133 The @GNUTAR{} program is invoked as either one of:
2134
2135 @smallexample
2136 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
2137 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
2138 @end smallexample
2139
2140 The second form is for when old options are being used.
2141
2142 You can use @command{tar} to store files in an archive, to extract them from
2143 an archive, and to do other types of archive manipulation. The primary
2144 argument to @command{tar}, which is called the @dfn{operation}, specifies
2145 which action to take. The other arguments to @command{tar} are either
2146 @dfn{options}, which change the way @command{tar} performs an operation,
2147 or file names or archive members, which specify the files or members
2148 @command{tar} is to act on.
2149
2150 You can actually type in arguments in any order, even if in this manual
2151 the options always precede the other arguments, to make examples easier
2152 to understand. Further, the option stating the main operation mode
2153 (the @command{tar} main command) is usually given first.
2154
2155 Each @var{name} in the synopsis above is interpreted as an archive member
2156 name when the main command is one of @value{op-compare}, @value{op-delete},
2157 @value{op-extract}, @value{op-list} or @value{op-update}. When naming
2158 archive members, you must give the exact name of the member in the
2159 archive, as it is printed by @value{op-list}. For @value{op-append}
2160 and @value{op-create}, these @var{name} arguments specify the names
2161 of either files or directory hierarchies to place in the archive.
2162 These files or hierarchies should already exist in the file system,
2163 prior to the execution of the @command{tar} command.
2164
2165 @command{tar} interprets relative file names as being relative to the
2166 working directory. @command{tar} will make all file names relative
2167 (by removing leading slashes when archiving or restoring files),
2168 unless you specify otherwise (using the @value{op-absolute-names}
2169 option). @value{xref-absolute-names}, for more information about
2170 @value{op-absolute-names}.
2171
2172 If you give the name of a directory as either a file name or a member
2173 name, then @command{tar} acts recursively on all the files and directories
2174 beneath that directory. For example, the name @file{/} identifies all
2175 the files in the filesystem to @command{tar}.
2176
2177 The distinction between file names and archive member names is especially
2178 important when shell globbing is used, and sometimes a source of confusion
2179 for newcomers. @xref{Wildcards}, for more information about globbing.
2180 The problem is that shells may only glob using existing files in the
2181 file system. Only @command{tar} itself may glob on archive members, so when
2182 needed, you must ensure that wildcard characters reach @command{tar} without
2183 being interpreted by the shell first. Using a backslash before @samp{*}
2184 or @samp{?}, or putting the whole argument between quotes, is usually
2185 sufficient for this.
2186
2187 Even if @var{name}s are often specified on the command line, they
2188 can also be read from a text file in the file system, using the
2189 @value{op-files-from} option.
2190
2191 If you don't use any file name arguments, @value{op-append},
2192 @value{op-delete} and @value{op-concatenate} will do nothing, while
2193 @value{op-create} will usually yield a diagnostic and inhibit @command{tar}
2194 execution. The other operations of @command{tar} (@value{op-list},
2195 @value{op-extract}, @value{op-compare}, and @value{op-update}) will act
2196 on the entire contents of the archive.
2197
2198 @cindex exit status
2199 @cindex return status
2200 Besides successful exits, @GNUTAR{} may fail for
2201 many reasons. Some reasons correspond to bad usage, that is, when the
2202 @command{tar} command is improperly written. Errors may be
2203 encountered later, while encountering an error processing the archive
2204 or the files. Some errors are recoverable, in which case the failure
2205 is delayed until @command{tar} has completed all its work. Some
2206 errors are such that it would not meaningful, or at least risky, to
2207 continue processing: @command{tar} then aborts processing immediately.
2208 All abnormal exits, whether immediate or delayed, should always be
2209 clearly diagnosed on @code{stderr}, after a line stating the nature of
2210 the error.
2211
2212 @GNUTAR{} returns only a few exit statuses. I'm really
2213 aiming simplicity in that area, for now. If you are not using the
2214 @value{op-compare} option, zero means that everything went well, besides
2215 maybe innocuous warnings. Nonzero means that something went wrong.
2216 Right now, as of today, ``nonzero'' is almost always 2, except for
2217 remote operations, where it may be 128.
2218
2219 @node using tar options
2220 @section Using @command{tar} Options
2221
2222 @GNUTAR{} has a total of eight operating modes which
2223 allow you to perform a variety of tasks. You are required to choose
2224 one operating mode each time you employ the @command{tar} program by
2225 specifying one, and only one operation as an argument to the
2226 @command{tar} command (two lists of four operations each may be found
2227 at @ref{frequent operations} and @ref{Operations}). Depending on
2228 circumstances, you may also wish to customize how the chosen operating
2229 mode behaves. For example, you may wish to change the way the output
2230 looks, or the format of the files that you wish to archive may require
2231 you to do something special in order to make the archive look right.
2232
2233 You can customize and control @command{tar}'s performance by running
2234 @command{tar} with one or more options (such as @value{op-verbose}, which
2235 we used in the tutorial). As we said in the tutorial, @dfn{options} are
2236 arguments to @command{tar} which are (as their name suggests) optional.
2237 Depending on the operating mode, you may specify one or more options.
2238 Different options will have different effects, but in general they all
2239 change details of the operation, such as archive format, archive name,
2240 or level of user interaction. Some options make sense with all
2241 operating modes, while others are meaningful only with particular modes.
2242 You will likely use some options frequently, while you will only use
2243 others infrequently, or not at all. (A full list of options is
2244 available in @pxref{All Options}.)
2245
2246 The @env{TAR_OPTIONS} environment variable specifies default options to
2247 be placed in front of any explicit options. For example, if
2248 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
2249 if the two options @option{-v} and @option{--unlink-first} had been
2250 specified before any explicit options. Option specifications are
2251 separated by whitespace. A backslash escapes the next character, so it
2252 can be used to specify an option containing whitespace or a backslash.
2253
2254 Note that @command{tar} options are case sensitive. For example, the
2255 options @samp{-T} and @samp{-t} are different; the first requires an
2256 argument for stating the name of a file providing a list of @var{name}s,
2257 while the second does not require an argument and is another way to
2258 write @value{op-list}.
2259
2260 In addition to the eight operations, there are many options to
2261 @command{tar}, and three different styles for writing both: long (mnemonic)
2262 form, short form, and old style. These styles are discussed below.
2263 Both the options and the operations can be written in any of these three
2264 styles.
2265
2266 @FIXME{menu at end of this node. need to think of an actual outline
2267 for this chapter; probably do that after stuff from chap. 4 is
2268 incorporated.}
2269
2270 @node Styles
2271 @section The Three Option Styles
2272
2273 There are three styles for writing operations and options to the command
2274 line invoking @command{tar}. The different styles were developed at
2275 different times during the history of @command{tar}. These styles will be
2276 presented below, from the most recent to the oldest.
2277
2278 Some options must take an argument. (For example, @value{op-file} takes
2279 the name of an archive file as an argument. If you do not supply an
2280 archive file name, @command{tar} will use a default, but this can be
2281 confusing; thus, we recommend that you always supply a specific archive
2282 file name.) Where you @emph{place} the arguments generally depends on
2283 which style of options you choose. We will detail specific information
2284 relevant to each option style in the sections on the different option
2285 styles, below. The differences are subtle, yet can often be very
2286 important; incorrect option placement can cause you to overwrite a
2287 number of important files. We urge you to note these differences, and
2288 only use the option style(s) which makes the most sense to you until you
2289 feel comfortable with the others.
2290
2291 Some options @emph{may} take an argument (currently, there are
2292 two such options: @value{op-backup} and @value{op-occurrence}). Such
2293 options may have at most long and short forms, they do not have old style
2294 equivalent. The rules for specifying an argument for such options
2295 are stricter than those for specifying mandatory arguments. Please,
2296 pay special attention to them.
2297
2298 @menu
2299 * Mnemonic Options:: Mnemonic Option Style
2300 * Short Options:: Short Option Style
2301 * Old Options:: Old Option Style
2302 * Mixing:: Mixing Option Styles
2303 @end menu
2304
2305 @node Mnemonic Options
2306 @subsection Mnemonic Option Style
2307
2308 @FIXME{have to decide whether or not to replace other occurrences of
2309 "mnemonic" with "long", or *ugh* vice versa.}
2310
2311 Each option has at least one long (or mnemonic) name starting with two
2312 dashes in a row, e.g.@: @samp{--list}. The long names are more clear than
2313 their corresponding short or old names. It sometimes happens that a
2314 single mnemonic option has many different different names which are
2315 synonymous, such as @samp{--compare} and @samp{--diff}. In addition,
2316 long option names can be given unique abbreviations. For example,
2317 @samp{--cre} can be used in place of @samp{--create} because there is no
2318 other mnemonic option which begins with @samp{cre}. (One way to find
2319 this out is by trying it and seeing what happens; if a particular
2320 abbreviation could represent more than one option, @command{tar} will tell
2321 you that that abbreviation is ambiguous and you'll know that that
2322 abbreviation won't work. You may also choose to run @samp{tar --help}
2323 to see a list of options. Be aware that if you run @command{tar} with a
2324 unique abbreviation for the long name of an option you didn't want to
2325 use, you are stuck; @command{tar} will perform the command as ordered.)
2326
2327 Mnemonic options are meant to be obvious and easy to remember, and their
2328 meanings are generally easier to discern than those of their
2329 corresponding short options (see below). For example:
2330
2331 @smallexample
2332 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2333 @end smallexample
2334
2335 @noindent
2336 gives a fairly good set of hints about what the command does, even
2337 for those not fully acquainted with @command{tar}.
2338
2339 Mnemonic options which require arguments take those arguments
2340 immediately following the option name. There are two ways of
2341 specifying a mandatory argument. It can be separated from the
2342 option name either by an equal sign, or by any amount of
2343 white space characters. For example, the @samp{--file} option (which
2344 tells the name of the @command{tar} archive) is given a file such as
2345 @file{archive.tar} as argument by using any of the following notations:
2346 @samp{--file=archive.tar} or @samp{--file archive.tar}.
2347
2348 In contrast, optional arguments must always be introduced using
2349 an equal sign. For example, the @samp{--backup} option takes
2350 an optional argument specifying backup type. It must be used
2351 as @samp{--backup=@var{backup-type}}.
2352
2353 @node Short Options
2354 @subsection Short Option Style
2355
2356 Most options also have a short option name. Short options start with
2357 a single dash, and are followed by a single character, e.g.@: @samp{-t}
2358 (which is equivalent to @samp{--list}). The forms are absolutely
2359 identical in function; they are interchangeable.
2360
2361 The short option names are faster to type than long option names.
2362
2363 Short options which require arguments take their arguments immediately
2364 following the option, usually separated by white space. It is also
2365 possible to stick the argument right after the short option name, using
2366 no intervening space. For example, you might write @w{@samp{-f
2367 archive.tar}} or @samp{-farchive.tar} instead of using
2368 @samp{--file=archive.tar}. Both @samp{--file=@var{archive-name}} and
2369 @w{@samp{-f @var{archive-name}}} denote the option which indicates a
2370 specific archive, here named @file{archive.tar}.
2371
2372 Short options which take optional arguments take their arguments
2373 immediately following the option letter, @emph{without any intervening
2374 white space characters}.
2375
2376 Short options' letters may be clumped together, but you are not
2377 required to do this (as compared to old options; see below). When
2378 short options are clumped as a set, use one (single) dash for them
2379 all, e.g.@: @w{@samp{@command{tar} -cvf}}. Only the last option in
2380 such a set is allowed to have an argument@footnote{Clustering many
2381 options, the last of which has an argument, is a rather opaque way to
2382 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2383 even be made helpful enough for considering such usages as invalid.}.
2384
2385 When the options are separated, the argument for each option which requires
2386 an argument directly follows that option, as is usual for Unix programs.
2387 For example:
2388
2389 @smallexample
2390 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2391 @end smallexample
2392
2393 If you reorder short options' locations, be sure to move any arguments
2394 that belong to them. If you do not move the arguments properly, you may
2395 end up overwriting files.
2396
2397 @node Old Options
2398 @subsection Old Option Style
2399 @UNREVISED
2400
2401 Like short options, old options are single letters. However, old options
2402 must be written together as a single clumped set, without spaces separating
2403 them or dashes preceding them@footnote{Beware that if you precede options
2404 with a dash, you are announcing the short option style instead of the
2405 old option style; short options are decoded differently.}. This set
2406 of letters must be the first to appear on the command line, after the
2407 @command{tar} program name and some white space; old options cannot appear
2408 anywhere else. The letter of an old option is exactly the same letter as
2409 the corresponding short option. For example, the old option @samp{t} is
2410 the same as the short option @samp{-t}, and consequently, the same as the
2411 mnemonic option @samp{--list}. So for example, the command @w{@samp{tar
2412 cv}} specifies the option @samp{-v} in addition to the operation @samp{-c}.
2413
2414 @FIXME{bob suggests having an uglier example. :-) }
2415
2416 When options that need arguments are given together with the command,
2417 all the associated arguments follow, in the same order as the options.
2418 Thus, the example given previously could also be written in the old
2419 style as follows:
2420
2421 @smallexample
2422 $ @kbd{tar cvbf 20 /dev/rmt0}
2423 @end smallexample
2424
2425 @noindent
2426 Here, @samp{20} is the argument of @samp{-b} and @samp{/dev/rmt0} is
2427 the argument of @samp{-f}.
2428
2429 On the other hand, this old style syntax makes it difficult to match
2430 option letters with their corresponding arguments, and is often
2431 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2432 @samp{20} is the argument for @samp{-b}, @samp{/dev/rmt0} is the
2433 argument for @samp{-f}, and @samp{-v} does not have a corresponding
2434 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2435 /dev/rmt0}} is clearer, putting all arguments next to the option they
2436 pertain to.
2437
2438 If you want to reorder the letters in the old option argument, be
2439 sure to reorder any corresponding argument appropriately.
2440
2441 This old way of writing @command{tar} options can surprise even experienced
2442 users. For example, the two commands:
2443
2444 @smallexample
2445 @kbd{tar cfz archive.tar.gz file}
2446 @kbd{tar -cfz archive.tar.gz file}
2447 @end smallexample
2448
2449 @noindent
2450 are quite different. The first example uses @file{archive.tar.gz} as
2451 the value for option @samp{f} and recognizes the option @samp{z}. The
2452 second example, however, uses @file{z} as the value for option
2453 @samp{f} --- probably not what was intended.
2454
2455 Old options are kept for compatibility with old versions of @command{tar}.
2456
2457 This second example could be corrected in many ways, among which the
2458 following are equivalent:
2459
2460 @smallexample
2461 @kbd{tar -czf archive.tar.gz file}
2462 @kbd{tar -cf archive.tar.gz -z file}
2463 @kbd{tar cf archive.tar.gz -z file}
2464 @end smallexample
2465
2466 @FIXME{still could explain this better; it's redundant:}
2467
2468 @cindex option syntax, traditional
2469 As far as we know, all @command{tar} programs, @acronym{GNU} and
2470 non-@acronym{GNU}, support old options. @GNUTAR{}
2471 supports them not only for historical reasons, but also because many
2472 people are used to them. For compatibility with Unix @command{tar},
2473 the first argument is always treated as containing command and option
2474 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2475 equivalent to @w{@samp{tar -c}:} both of them specify the
2476 @value{op-create} command to create an archive.
2477
2478 @node Mixing
2479 @subsection Mixing Option Styles
2480
2481 All three styles may be intermixed in a single @command{tar} command,
2482 so long as the rules for each style are fully
2483 respected@footnote{Before @GNUTAR{} version 1.11.6,
2484 a bug prevented intermixing old style options with mnemonic options in
2485 some cases.}. Old style options and either of the modern styles of
2486 options may be mixed within a single @command{tar} command. However,
2487 old style options must be introduced as the first arguments only,
2488 following the rule for old options (old options must appear directly
2489 after the @command{tar} command and some white space). Modern options
2490 may be given only after all arguments to the old options have been
2491 collected. If this rule is not respected, a modern option might be
2492 falsely interpreted as the value of the argument to one of the old
2493 style options.
2494
2495 For example, all the following commands are wholly equivalent, and
2496 illustrate the many combinations and orderings of option styles.
2497
2498 @smallexample
2499 @kbd{tar --create --file=archive.tar}
2500 @kbd{tar --create -f archive.tar}
2501 @kbd{tar --create -farchive.tar}
2502 @kbd{tar --file=archive.tar --create}
2503 @kbd{tar --file=archive.tar -c}
2504 @kbd{tar -c --file=archive.tar}
2505 @kbd{tar -c -f archive.tar}
2506 @kbd{tar -c -farchive.tar}
2507 @kbd{tar -cf archive.tar}
2508 @kbd{tar -cfarchive.tar}
2509 @kbd{tar -f archive.tar --create}
2510 @kbd{tar -f archive.tar -c}
2511 @kbd{tar -farchive.tar --create}
2512 @kbd{tar -farchive.tar -c}
2513 @kbd{tar c --file=archive.tar}
2514 @kbd{tar c -f archive.tar}
2515 @kbd{tar c -farchive.tar}
2516 @kbd{tar cf archive.tar}
2517 @kbd{tar f archive.tar --create}
2518 @kbd{tar f archive.tar -c}
2519 @kbd{tar fc archive.tar}
2520 @end smallexample
2521
2522 On the other hand, the following commands are @emph{not} equivalent to
2523 the previous set:
2524
2525 @smallexample
2526 @kbd{tar -f -c archive.tar}
2527 @kbd{tar -fc archive.tar}
2528 @kbd{tar -fcarchive.tar}
2529 @kbd{tar -farchive.tarc}
2530 @kbd{tar cfarchive.tar}
2531 @end smallexample
2532
2533 @noindent
2534 These last examples mean something completely different from what the
2535 user intended (judging based on the example in the previous set which
2536 uses long options, whose intent is therefore very clear). The first
2537 four specify that the @command{tar} archive would be a file named
2538 @samp{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2539 respectively. The first two examples also specify a single non-option,
2540 @var{name} argument having the value @samp{archive.tar}. The last
2541 example contains only old style option letters (repeating option
2542 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2543 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2544 the first sentence of this paragraph..}
2545
2546 @node All Options
2547 @section All @command{tar} Options
2548
2549 The coming manual sections contain an alphabetical listing of all
2550 @command{tar} operations and options, with brief descriptions and cross
2551 references to more in-depth explanations in the body of the manual.
2552 They also contain an alphabetically arranged table of the short option
2553 forms with their corresponding long option. You can use this table as
2554 a reference for deciphering @command{tar} commands in scripts.
2555
2556 @menu
2557 * Operation Summary::
2558 * Option Summary::
2559 * Short Option Summary::
2560 @end menu
2561
2562 @node Operation Summary
2563 @subsection Operations
2564
2565 @table @kbd
2566
2567 @item --append
2568 @itemx -r
2569
2570 Appends files to the end of the archive. @xref{append}.
2571
2572 @item --catenate
2573 @itemx -A
2574
2575 Same as @samp{--concatenate}. @xref{concatenate}.
2576
2577 @item --compare
2578 @itemx -d
2579
2580 Compares archive members with their counterparts in the file
2581 system, and reports differences in file size, mode, owner,
2582 modification date and contents. @xref{compare}.
2583
2584 @item --concatenate
2585 @itemx -A
2586
2587 Appends other @command{tar} archives to the end of the archive.
2588 @xref{concatenate}.
2589
2590 @item --create
2591 @itemx -c
2592
2593 Creates a new @command{tar} archive. @xref{create}.
2594
2595 @item --delete
2596
2597 Deletes members from the archive. Don't try this on a archive on a
2598 tape! @xref{delete}.
2599
2600 @item --diff
2601 @itemx -d
2602
2603 Same @samp{--compare}. @xref{compare}.
2604
2605 @item --extract
2606 @itemx -x
2607
2608 Extracts members from the archive into the file system. @xref{extract}.
2609
2610 @item --get
2611 @itemx -x
2612
2613 Same as @samp{--extract}. @xref{extract}.
2614
2615 @item --list
2616 @itemx -t
2617
2618 Lists the members in an archive. @xref{list}.
2619
2620 @item --update
2621 @itemx -u
2622
2623 @FIXME{It was: A combination of the @samp{--compare} and
2624 @samp{--append} operations. This is not true and rather misleading,
2625 as @value{op-compare} does a lot more than @value{op-update} for
2626 ensuring files are identical.} Adds files to the end of the archive,
2627 but only if they are newer than their counterparts already in the
2628 archive, or if they do not already exist in the archive.
2629 @xref{update}.
2630
2631 @end table
2632
2633 @node Option Summary
2634 @subsection @command{tar} Options
2635
2636 @table @kbd
2637
2638 @item --absolute-names
2639 @itemx -P
2640
2641 Normally when creating an archive, @command{tar} strips an initial
2642 @samp{/} from member names. This option disables that behavior.
2643 @FIXME-xref{}
2644
2645 @item --after-date
2646
2647 (See @samp{--newer}.) @FIXME-pxref{}
2648
2649 @item --anchored
2650 An exclude pattern must match an initial subsequence of the name's components.
2651 @FIXME-xref{}
2652
2653 @item --atime-preserve
2654
2655 Tells @command{tar} to preserve the access time field in a file's inode when
2656 reading it. Due to limitations in the @code{utimes} system call, the
2657 modification time field is also preserved, which may cause problems if
2658 the file is simultaneously being modified by another program.
2659 This option is incompatible with incremental backups, because
2660 preserving the access time involves updating the last-changed time.
2661 Also, this option does not work on files that you do not own,
2662 unless you're root.
2663 @FIXME-xref{}
2664
2665 @item --backup=@var{backup-type}
2666
2667 Rather than deleting files from the file system, @command{tar} will
2668 back them up using simple or numbered backups, depending upon
2669 @var{backup-type}. @FIXME-xref{}
2670
2671 @item --block-number
2672 @itemx -R
2673
2674 With this option present, @command{tar} prints error messages for read errors
2675 with the block number in the archive file. @FIXME-xref{}
2676
2677 @item --blocking-factor=@var{blocking}
2678 @itemx -b @var{blocking}
2679
2680 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2681 record. @FIXME-xref{}
2682
2683 @item --bzip2
2684 @itemx -j
2685
2686 This option tells @command{tar} to read or write archives through
2687 @code{bzip2}. @FIXME-xref{}
2688
2689 @item --checkpoint
2690
2691 This option directs @command{tar} to print periodic checkpoint messages as it
2692 reads through the archive. Its intended for when you want a visual
2693 indication that @command{tar} is still running, but don't want to see
2694 @samp{--verbose} output. @FIXME-xref{}
2695
2696 @item --check-links
2697 @itemx -l
2698 If this option was given, @command{tar} will check the number of links
2699 dumped for each processed file. If this number does not match the
2700 total number of hard links for the file, a warning message will be
2701 output.
2702
2703 Future versions will take @option{-l} as a short version of
2704 @option{--check-links}. However, current release still retains the old
2705 semantics for @option{-l}.
2706
2707 @xref{Current status}, for more information.
2708
2709 @item --compress
2710 @itemx --uncompress
2711 @itemx -Z
2712
2713 @command{tar} will use the @command{compress} program when reading or
2714 writing the archive. This allows you to directly act on archives
2715 while saving space. @FIXME-xref{}
2716
2717 @item --confirmation
2718
2719 (See @samp{--interactive}.) @FIXME-pxref{}
2720
2721 @item --dereference
2722 @itemx -h
2723
2724 When creating a @command{tar} archive, @command{tar} will archive the
2725 file that a symbolic link points to, rather than archiving the
2726 symlink. @FIXME-xref{}
2727
2728 @item --directory=@var{dir}
2729 @itemx -C @var{dir}
2730
2731 When this option is specified, @command{tar} will change its current directory
2732 to @var{dir} before performing any operations. When this option is used
2733 during archive creation, it is order sensitive. @FIXME-xref{}
2734
2735 @item --exclude=@var{pattern}
2736
2737 When performing operations, @command{tar} will skip files that match
2738 @var{pattern}. @FIXME-xref{}
2739
2740 @item --exclude-from=@var{file}
2741 @itemx -X @var{file}
2742
2743 Similar to @samp{--exclude}, except @command{tar} will use the list of
2744 patterns in the file @var{file}. @FIXME-xref{}
2745
2746 @item --file=@var{archive}
2747 @itemx -f @var{archive}
2748
2749 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2750 performs operations on, rather than @command{tar}'s compilation dependent
2751 default. @FIXME-xref{}
2752
2753 @item --files-from=@var{file}
2754 @itemx -T @var{file}
2755
2756 @command{tar} will use the contents of @var{file} as a list of archive members
2757 or files to operate on, in addition to those specified on the
2758 command-line. @FIXME-xref{}
2759
2760 @item --force-local
2761
2762 Forces @command{tar} to interpret the filename given to @samp{--file}
2763 as a local file, even if it looks like a remote tape drive name.
2764 @FIXME-xref{}
2765
2766 @item --format=@var{format}
2767
2768 Selects output archive format. @var{Format} may be one of the
2769 following:
2770
2771 @table @samp
2772 @item v7
2773 Creates an archive that is compatible with Unix V7 @command{tar}.
2774
2775 @item oldgnu
2776 Creates an archive that is compatible with GNU @command{tar} version
2777 1.12 or earlier.
2778
2779 @item gnu
2780 Creates archive in GNU tar 1.13 format. Basically it is the same as
2781 @samp{oldgnu} with the only difference in the way it handles long
2782 numeric fields.
2783
2784 @item ustar
2785 Creates a @acronym{POSIX.1-1988} compatible archive.
2786
2787 @item posix
2788 Creates a @acronym{POSIX.1-2001 archive}.
2789
2790 @end table
2791
2792 @xref{Formats}, for a detailed discussion of these formats.
2793
2794 @item --group=@var{group}
2795
2796 Files added to the @command{tar} archive will have a group id of @var{group},
2797 rather than the group from the source file. @var{group} is first decoded
2798 as a group symbolic name, but if this interpretation fails, it has to be
2799 a decimal numeric group ID. @FIXME-xref{}
2800
2801 Also see the comments for the @value{op-owner} option.
2802
2803 @item --gzip
2804 @itemx --gunzip
2805 @itemx --ungzip
2806 @itemx -z
2807
2808 This option tells @command{tar} to read or write archives through
2809 @command{gzip}, allowing @command{tar} to directly operate on several
2810 kinds of compressed archives transparently. @FIXME-xref{}
2811
2812 @item --help
2813
2814 @command{tar} will print out a short message summarizing the operations and
2815 options to @command{tar} and exit. @FIXME-xref{}
2816
2817 @item --ignore-case
2818 Ignore case when excluding files.
2819 @FIXME-xref{}
2820
2821 @item --ignore-failed-read
2822
2823 Do not exit unsuccessfully merely because an unreadable file was encountered.
2824 @xref{Reading}.
2825
2826 @item --ignore-zeros
2827 @itemx -i
2828
2829 With this option, @command{tar} will ignore zeroed blocks in the
2830 archive, which normally signals EOF. @xref{Reading}.
2831
2832 @item --incremental
2833 @itemx -G
2834
2835 Used to inform @command{tar} that it is working with an old
2836 @acronym{GNU}-format incremental backup archive. It is intended
2837 primarily for backwards compatibility only. @FIXME-xref{}
2838
2839 @item --index-file=@var{file}
2840
2841 Send verbose output to @var{file} instead of to standard output.
2842
2843 @item --info-script=@var{script-file}
2844 @itemx --new-volume-script=@var{script-file}
2845 @itemx -F @var{script-file}
2846
2847 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2848 at the end of each tape. If @var{script-file} exits with nonzero status,
2849 @command{tar} fails immediately. @FIXME-xref{}
2850
2851 @item --interactive
2852 @itemx --confirmation
2853 @itemx -w
2854
2855 Specifies that @command{tar} should ask the user for confirmation before
2856 performing potentially destructive options, such as overwriting files.
2857 @FIXME-xref{}
2858
2859 @item --keep-newer-files
2860
2861 Do not replace existing files that are newer than their archive copies
2862 when extracting files from an archive.
2863
2864 @item --keep-old-files
2865 @itemx -k
2866
2867 Do not overwrite existing files when extracting files from an archive.
2868 @xref{Writing}.
2869
2870 @item --label=@var{name}
2871 @itemx -V @var{name}
2872
2873 When creating an archive, instructs @command{tar} to write @var{name}
2874 as a name record in the archive. When extracting or listing archives,
2875 @command{tar} will only operate on archives that have a label matching
2876 the pattern specified in @var{name}. @FIXME-xref{}
2877
2878 @item --listed-incremental=@var{snapshot-file}
2879 @itemx -g @var{snapshot-file}
2880
2881 During a @samp{--create} operation, specifies that the archive that
2882 @command{tar} creates is a new @acronym{GNU}-format incremental
2883 backup, using @var{snapshot-file} to determine which files to backup.
2884 With other operations, informs @command{tar} that the archive is in
2885 incremental format. @FIXME-xref{}
2886
2887 @item --mode=@var{permissions}
2888
2889 When adding files to an archive, @command{tar} will use
2890 @var{permissions} for the archive members, rather than the permissions
2891 from the files. The program @command{chmod} and this @command{tar}
2892 option share the same syntax for what @var{permissions} might be.
2893 @xref{File permissions, Permissions, File permissions, fileutils,
2894 @acronym{GNU} file utilities}. This reference also has useful
2895 information for those not being overly familiar with the Unix
2896 permission system.
2897
2898 Of course, @var{permissions} might be plainly specified as an octal number.
2899 However, by using generic symbolic modifications to mode bits, this allows
2900 more flexibility. For example, the value @samp{a+rw} adds read and write
2901 permissions for everybody, while retaining executable bits on directories
2902 or on any other file already marked as executable.
2903
2904 @item --multi-volume
2905 @itemx -M
2906
2907 Informs @command{tar} that it should create or otherwise operate on a
2908 multi-volume @command{tar} archive. @FIXME-xref{}
2909
2910 @item --new-volume-script
2911
2912 (see --info-script)
2913
2914 @item --newer=@var{date}
2915 @itemx --after-date=@var{date}
2916 @itemx -N
2917
2918 When creating an archive, @command{tar} will only add files that have changed
2919 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2920 is taken to be the name of a file whose last-modified time specifies
2921 the date. @FIXME-xref{}
2922
2923 @item --newer-mtime=@var{date}
2924
2925 Like @samp{--newer}, but add only files whose
2926 contents have changed (as opposed to just @samp{--newer}, which will
2927 also back up files for which any status information has changed).
2928
2929 @item --no-anchored
2930 An exclude pattern can match any subsequence of the name's components.
2931 @FIXME-xref{}
2932
2933 @item --no-ignore-case
2934 Use case-sensitive matching when excluding files.
2935 @FIXME-xref{}
2936
2937 @item --no-recursion
2938
2939 With this option, @command{tar} will not recurse into directories.
2940 @FIXME-xref{}
2941
2942 @item --no-same-owner
2943 @itemx -o
2944
2945 When extracting an archive, do not attempt to preserve the owner
2946 specified in the @command{tar} archive. This the default behavior
2947 for ordinary users; this option has an effect only for the superuser.
2948
2949 @item --no-same-permissions
2950
2951 When extracting an archive, subtract the user's umask from files from
2952 the permissions specified in the archive. This is the default behavior
2953 for ordinary users; this option has an effect only for the superuser.
2954
2955 @item --no-wildcards
2956 Do not use wildcards when excluding files.
2957 @FIXME-xref{}
2958
2959 @item --no-wildcards-match-slash
2960 Wildcards do not match @samp{/} when excluding files.
2961 @FIXME-xref{}
2962
2963 @item --null
2964
2965 When @command{tar} is using the @samp{--files-from} option, this option
2966 instructs @command{tar} to expect filenames terminated with @kbd{NUL}, so
2967 @command{tar} can correctly work with file names that contain newlines.
2968 @FIXME-xref{}
2969
2970 @item --numeric-owner
2971
2972 This option will notify @command{tar} that it should use numeric user
2973 and group IDs when creating a @command{tar} file, rather than names.
2974 @FIXME-xref{}
2975
2976 @item -o
2977 When extracting files, this option is a synonym for
2978 @option{--no-same-owner}, i.e. it prevents @command{tar} from
2979 restoring ownership of files being extracted.
2980
2981 When creating an archive, @option{-o} is a synonym for
2982 @option{--old-archive}. This behavior is for compatibility
2983 with previous versions of @GNUTAR{}, and will be
2984 removed in the future releases.
2985
2986 @xref{Current status}, for more information.
2987
2988 @item --occurrence[=@var{number}]
2989
2990 This option can be used in conjunction with one of the subcommands
2991 @option{--delete}, @option{--diff}, @option{--extract} or
2992 @option{--list} when a list of files is given either on the command
2993 line or via @option{-T} option.
2994
2995 This option instructs @command{tar} to process only the @var{number}th
2996 occurrence of each named file. @var{Number} defaults to 1, so
2997
2998 @smallexample
2999 tar -x -f archive.tar --occurrence filename
3000 @end smallexample
3001
3002 @noindent
3003 will extract the first occurrence of @file{filename} from @file{archive.tar}
3004 and will terminate without scanning to the end of the archive.
3005
3006 @item --old-archive
3007 Synonym for @option{--format=v7}.
3008
3009 @item --one-file-system
3010 @itemx -l
3011 Used when creating an archive. Prevents @command{tar} from recursing into
3012 directories that are on different file systems from the current
3013 directory.
3014
3015 Earlier versions of @GNUTAR{} understood @option{-l} as a
3016 synonym for @option{--one-file-system}. Although such usage is still
3017 allowed in the present version, it is @emph{strongly discouraged}.
3018 The future versions of @GNUTAR{} will use @option{-l} as
3019 a synonym for @option{--check-links}.
3020
3021 @xref{Current status}, for more information.
3022
3023 @item --overwrite
3024
3025 Overwrite existing files and directory metadata when extracting files
3026 from an archive. @xref{Overwrite Old Files}.
3027
3028 @item --overwrite-dir
3029
3030 Overwrite the metadata of existing directories when extracting files
3031 from an archive. @xref{Overwrite Old Files}.
3032
3033 @item --owner=@var{user}
3034
3035 Specifies that @command{tar} should use @var{user} as the owner of members
3036 when creating archives, instead of the user associated with the source
3037 file. @var{user} is first decoded as a user symbolic name, but if
3038 this interpretation fails, it has to be a decimal numeric user ID.
3039 @FIXME-xref{}
3040
3041 There is no value indicating a missing number, and @samp{0} usually means
3042 @code{root}. Some people like to force @samp{0} as the value to offer in
3043 their distributions for the owner of files, because the @code{root} user is
3044 anonymous anyway, so that might as well be the owner of anonymous archives.
3045
3046 This option does not affect extraction from archives.
3047
3048 @item --pax-option=@var{keyword-list}
3049
3050 This option is meaningful only with @acronym{POSIX.1-2001} archives
3051 (@FIXME-xref{}). It modifies the way @command{tar} handles the
3052 extended header keywords. @var{Keyword-list} is a comma-separated
3053 list of keyword options, each keyword option taking one of
3054 the following forms:
3055
3056 @table @asis
3057 @item delete=@var{pattern}
3058 When used with one of archive-creation command (@FIXME-xref{}),
3059 this option instructs @command{tar} to omit from extended header records
3060 that it produces any keywords matching the string @var{pattern}.
3061
3062 When used in extract or list mode, this option instructs tar
3063 to ignore any keywords matching the given @var{pattern} in the extended
3064 header records. In both cases, matching is performed using the pattern
3065 matching notation described in @acronym{POSIX 1003.2}, 3.13 @FIXME-xref{see
3066 man 7 glob}. For example:
3067
3068 @smallexample
3069 --pax-option delete=security.*
3070 @end smallexample
3071
3072 would suppress security-related information.
3073
3074 @item exthdr.name=@var{string}
3075
3076 This keyword allows user control over the name that is written into the
3077 ustar header blocks for the extended headers. The name is obtained
3078 from @var{string} after substituting the following meta-characters:
3079
3080 @multitable @columnfractions .30 .70
3081 @item Meta-character @tab Replaced By
3082 @item %d @tab The directory name of the file, equivalent to the
3083 result of the @command{dirname} utility on the translated pathname.
3084 @item %f @tab The filename of the file, equivalent to the result
3085 of the @command{basename} utility on the translated pathname.
3086 @item %p @tab The process ID of the @command{tar} process.
3087 @item %% @tab A @samp{%} character.
3088 @end multitable
3089
3090 Any other @samp{%} characters in @var{string} produce undefined
3091 results.
3092
3093 If no option @samp{exthdr.name=string} is specified, @command{tar}
3094 will use the following default value:
3095
3096 @smallexample
3097 %d/PaxHeaders.%p/%f
3098 @end smallexample
3099
3100 @item globexthdr.name=@var{string}
3101 This keyword allows user control over the name that is written into
3102 the ustar header blocks for global extended header records. The name
3103 shall will be obtained from the contents of @var{string}, after the
3104 following character substitutions have been made:
3105
3106 @multitable @columnfractions .30 .70
3107 @item Meta-character @tab Replaced By
3108 @item %n @tab An integer that represents the
3109 sequence number of the global extended header record in the archive,
3110 starting at 1.
3111 @item %p @tab The process ID of the @command{tar} process.
3112 @item %% @tab A @samp{%} character.
3113 @end multitable
3114
3115 Any other @samp{%} characters in string produce undefined results.
3116
3117 If no option @samp{globexthdr.name=string} is specified, @command{tar}
3118 will use the following default value:
3119
3120 @smallexample
3121 $TMPDIR/GlobalHead.%p.%n
3122 @end smallexample
3123
3124 @noindent
3125 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
3126 environment variable. If @var{TMPDIR} is not set, @command{tar}
3127 uses @samp{/tmp}.
3128
3129 @item @var{keyword}=@var{value}
3130 When used with one of archive-creation commands, these keyword/value pairs
3131 will be included at the beginning of the archive in a global extended
3132 header record. When used with one of archive-reading commands,
3133 @command{tar} will behave as if it has encountered these keyword/value
3134 pairs at the beginning of the archive in a global extended header
3135 record.
3136
3137 @item @var{keyword}:=@var{value}
3138 When used with one of archive-creation commands, these keyword/value pairs
3139 will be included as records at the beginning of an extended header for
3140 each file. This is effectively equivalent to @var{keyword}=@var{value}
3141 form except that it creates no global extended header records.
3142
3143 When used with one of archive-reading commands, @command{tar} will
3144 behave as if these keyword/value pairs were included as records at the
3145 end of each extended header; thus, they will override any global or
3146 file-specific extended header record keywords of the same names.
3147 For example, in the command:
3148
3149 @smallexample
3150 tar --format=posix --create \
3151 --file archive --pax-option gname:=user .
3152 @end smallexample
3153
3154 the group name will be forced to a new value for all files
3155 stored in the archive.
3156 @end table
3157
3158 @item --portability
3159 @itemx --old-archive
3160 Synonym for @option{--format=v7}.
3161
3162 @item --posix
3163 Same as @option{--format=posix}.
3164
3165 @item --preserve
3166
3167 Synonymous with specifying both @samp{--preserve-permissions} and
3168 @samp{--same-order}. @FIXME-xref{}
3169
3170 @item --preserve-order
3171
3172 (See @samp{--same-order}; @pxref{Reading}.)
3173
3174 @item --preserve-permissions
3175 @itemx --same-permissions
3176 @itemx -p
3177
3178 When @command{tar} is extracting an archive, it normally subtracts the
3179 users' umask from the permissions specified in the archive and uses
3180 that number as the permissions to create the destination file.
3181 Specifying this option instructs @command{tar} that it should use the
3182 permissions directly from the archive. @xref{Writing}.
3183
3184 @item --read-full-records
3185 @itemx -B
3186
3187 Specifies that @command{tar} should reblock its input, for reading
3188 from pipes on systems with buggy implementations. @xref{Reading}.
3189
3190 @item --record-size=@var{size}
3191
3192 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3193 archive. @FIXME-xref{}
3194
3195 @item --recursion
3196
3197 With this option, @command{tar} recurses into directories.
3198 @FIXME-xref{}
3199
3200 @item --recursive-unlink
3201
3202 Remove existing
3203 directory hierarchies before extracting directories of the same name
3204 from the archive. @xref{Writing}.
3205
3206 @item --remove-files
3207
3208 Directs @command{tar} to remove the source file from the file system after
3209 appending it to an archive. @FIXME-xref{}
3210
3211 @item --rmt-command=@var{cmd}
3212
3213 Notifies @command{tar} that it should use @var{cmd} instead of
3214 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3215
3216 @item --rsh-command=@var{cmd}
3217
3218 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3219 devices. @FIXME-xref{}
3220
3221 @item --same-order
3222 @itemx --preserve-order
3223 @itemx -s
3224
3225 This option is an optimization for @command{tar} when running on machines with
3226 small amounts of memory. It informs @command{tar} that the list of file
3227 arguments has already been sorted to match the order of files in the
3228 archive. @xref{Reading}.
3229
3230 @item --same-owner
3231
3232 When extracting an archive, @command{tar} will attempt to preserve the owner
3233 specified in the @command{tar} archive with this option present.
3234 This is the default behavior for the superuser; this option has an
3235 effect only for ordinary users. @FIXME-xref{}
3236
3237 @item --same-permissions
3238
3239 (See @samp{--preserve-permissions}; @pxref{Writing}.)
3240
3241 @item --show-defaults
3242
3243 Displays the default options used by @command{tar} and exits
3244 successfully. This option is intended for use in shell scripts.
3245 Here is an example of what you can see using this option:
3246
3247 @smallexample
3248 $ tar --show-defaults
3249 --format=gnu -f- -b20
3250 @end smallexample
3251
3252 @item --show-omitted-dirs
3253
3254 Instructs @command{tar} to mention directories its skipping over when
3255 operating on a @command{tar} archive. @FIXME-xref{}
3256
3257 @item --sparse
3258 @itemx -S
3259
3260 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3261 sparse files efficiently. @FIXME-xref{}
3262
3263 @item --starting-file=@var{name}
3264 @itemx -K @var{name}
3265
3266 This option affects extraction only; @command{tar} will skip extracting
3267 files in the archive until it finds one that matches @var{name}.
3268 @xref{Scarce}.
3269
3270 @item --strip-components=@var{number}
3271 Strip given @var{number} of leading components from file names before
3272 extraction.@footnote{This option was called @option{--strip-path} in
3273 version 1.14.} For example, if archive @file{archive.tar} contained
3274 @file{/some/file/name}, then running
3275
3276 @smallexample
3277 tar --extract --file archive.tar --strip-components=2
3278 @end smallexample
3279
3280 @noindent
3281 would extracted this file to file @file{name}.
3282
3283 @item --suffix=@var{suffix}
3284
3285 Alters the suffix @command{tar} uses when backing up files from the default
3286 @samp{~}. @FIXME-xref{}
3287
3288 @item --tape-length=@var{num}
3289 @itemx -L @var{num}
3290
3291 Specifies the length of tapes that @command{tar} is writing as being
3292 @w{@var{num} x 1024} bytes long. @FIXME-xref{}
3293
3294 @item --to-stdout
3295 @itemx -O
3296
3297 During extraction, @command{tar} will extract files to stdout rather
3298 than to the file system. @xref{Writing}.
3299
3300 @item --totals
3301
3302 Displays the total number of bytes written after creating an archive.
3303 @FIXME-xref{}
3304
3305 @item --touch
3306 @itemx -m
3307
3308 Sets the modification time of extracted files to the extraction time,
3309 rather than the modification time stored in the archive.
3310 @xref{Writing}.
3311
3312 @item --uncompress
3313
3314 (See @samp{--compress}.) @FIXME-pxref{}
3315
3316 @item --ungzip
3317
3318 (See @samp{--gzip}.) @FIXME-pxref{}
3319
3320 @item --unlink-first
3321 @itemx -U
3322
3323 Directs @command{tar} to remove the corresponding file from the file
3324 system before extracting it from the archive. @xref{Writing}.
3325
3326 @item --use-compress-program=@var{prog}
3327
3328 Instructs @command{tar} to access the archive through @var{prog}, which is
3329 presumed to be a compression program of some sort. @FIXME-xref{}
3330
3331 @item --utc
3332
3333 Display file modification dates in @acronym{UTC}. This option implies
3334 @samp{--verbose}.
3335
3336 @item --verbose
3337 @itemx -v
3338
3339 Specifies that @command{tar} should be more verbose about the operations its
3340 performing. This option can be specified multiple times for some
3341 operations to increase the amount of information displayed. @FIXME-xref{}
3342
3343 @item --verify
3344 @itemx -W
3345
3346 Verifies that the archive was correctly written when creating an
3347 archive. @FIXME-xref{}
3348
3349 @item --version
3350
3351 @command{tar} will print an informational message about what version
3352 it is and a copyright message, some credits, and then exit.
3353 @FIXME-xref{}
3354
3355 @item --volno-file=@var{file}
3356
3357 Used in conjunction with @samp{--multi-volume}. @command{tar} will keep track
3358 of which volume of a multi-volume archive its working in @var{file}.
3359 @FIXME-xref{}
3360
3361 @item --wildcards
3362 Use wildcards when excluding files.
3363 @FIXME-xref{}
3364
3365 @item --wildcards-match-slash
3366 Wildcards match @samp{/} when excluding files.
3367 @FIXME-xref{}
3368 @end table
3369
3370 @node Short Option Summary
3371 @subsection Short Options Cross Reference
3372
3373 Here is an alphabetized list of all of the short option forms, matching
3374 them with the equivalent long option.
3375
3376 @table @kbd
3377
3378 @item -A
3379
3380 @samp{--concatenate}
3381
3382 @item -B
3383
3384 @samp{--read-full-records}
3385
3386 @item -C
3387
3388 @samp{--directory}
3389
3390 @item -F
3391
3392 @samp{--info-script}
3393
3394 @item -G
3395
3396 @samp{--incremental}
3397
3398 @item -K
3399
3400 @samp{--starting-file}
3401
3402 @item -L
3403
3404 @samp{--tape-length}
3405
3406 @item -M
3407
3408 @samp{--multi-volume}
3409
3410 @item -N
3411
3412 @samp{--newer}
3413
3414 @item -O
3415
3416 @samp{--to-stdout}
3417
3418 @item -P
3419
3420 @samp{--absolute-names}
3421
3422 @item -R
3423
3424 @samp{--block-number}
3425
3426 @item -S
3427
3428 @samp{--sparse}
3429
3430 @item -T
3431
3432 @samp{--files-from}
3433
3434 @item -U
3435
3436 @samp{--unlink-first}
3437
3438 @item -V
3439
3440 @samp{--label}
3441
3442 @item -W
3443
3444 @samp{--verify}
3445
3446 @item -X
3447
3448 @samp{--exclude-from}
3449
3450 @item -Z
3451
3452 @samp{--compress}
3453
3454 @item -b
3455
3456 @samp{--blocking-factor}
3457
3458 @item -c
3459
3460 @samp{--create}
3461
3462 @item -d
3463
3464 @samp{--compare}
3465
3466 @item -f
3467
3468 @samp{--file}
3469
3470 @item -g
3471
3472 @samp{--listed-incremental}
3473
3474 @item -h
3475
3476 @samp{--dereference}
3477
3478 @item -i
3479
3480 @samp{--ignore-zeros}
3481
3482 @item -j
3483
3484 @samp{--bzip2}
3485
3486 @item -k
3487
3488 @samp{--keep-old-files}
3489
3490 @item -l
3491
3492 @samp{--one-file-system}. Use of this short option is deprecated. It
3493 is retained for compatibility with the earlier versions of GNU
3494 @command{tar}, and will be changed in future releases.
3495
3496 @xref{Current status}, for more information.
3497
3498 @item -m
3499
3500 @samp{--touch}
3501
3502 @item -o
3503
3504 When creating --- @samp{--no-same-owner}, when extracting ---
3505 @samp{--portability}.
3506
3507 The later usage is deprecated. It is retained for compatibility with
3508 the earlier versions of @GNUTAR{}. In the future releases
3509 @option{-o} will be equivalent to @samp{--no-same-owner} only.
3510
3511 @item -p
3512
3513 @samp{--preserve-permissions}
3514
3515 @item -r
3516
3517 @samp{--append}
3518
3519 @item -s
3520
3521 @samp{--same-order}
3522
3523 @item -t
3524
3525 @samp{--list}
3526
3527 @item -u
3528
3529 @samp{--update}
3530
3531 @item -v
3532
3533 @samp{--verbose}
3534
3535 @item -w
3536
3537 @samp{--interactive}
3538
3539 @item -x
3540
3541 @samp{--extract}
3542
3543 @item -z
3544
3545 @samp{--gzip}
3546
3547 @end table
3548
3549 @node help
3550 @section @GNUTAR{} documentation
3551
3552 Being careful, the first thing is really checking that you are using
3553 @GNUTAR{}, indeed. The @value{op-version} option
3554 will generate a message giving confirmation that you are using
3555 @GNUTAR{}, with the precise version of @GNUTAR{}
3556 you are using. @command{tar} identifies itself and
3557 prints the version number to the standard output, then immediately
3558 exits successfully, without doing anything else, ignoring all other
3559 options. For example, @w{@samp{tar --version}} might return:
3560
3561 @smallexample
3562 tar (@acronym{GNU} tar) @value{VERSION}
3563 @end smallexample
3564
3565 @noindent
3566 The first occurrence of @samp{tar} in the result above is the program
3567 name in the package (for example, @command{rmt} is another program),
3568 while the second occurrence of @samp{tar} is the name of the package
3569 itself, containing possibly many programs. The package is currently
3570 named @samp{tar}, after the name of the main program it
3571 contains@footnote{There are plans to merge the @command{cpio} and
3572 @command{tar} packages into a single one which would be called
3573 @code{paxutils}. So, who knows if, one of this days, the
3574 @value{op-version} would not yield @w{@samp{tar (@acronym{GNU}
3575 paxutils) 3.2}}}.
3576
3577 Another thing you might want to do is checking the spelling or meaning
3578 of some particular @command{tar} option, without resorting to this
3579 manual, for once you have carefully read it. @GNUTAR{}
3580 has a short help feature, triggerable through the
3581 @value{op-help} option. By using this option, @command{tar} will
3582 print a usage message listing all available options on standard
3583 output, then exit successfully, without doing anything else and
3584 ignoring all other options. Even if this is only a brief summary, it
3585 may be several screens long. So, if you are not using some kind of
3586 scrollable window, you might prefer to use something like:
3587
3588 @smallexample
3589 $ @kbd{tar --help | less}
3590 @end smallexample
3591
3592 @noindent
3593 presuming, here, that you like using @command{less} for a pager. Other
3594 popular pagers are @command{more} and @command{pg}. If you know about some
3595 @var{keyword} which interests you and do not want to read all the
3596 @value{op-help} output, another common idiom is doing:
3597
3598 @smallexample
3599 tar --help | grep @var{keyword}
3600 @end smallexample
3601
3602 @noindent
3603 for getting only the pertinent lines.
3604
3605 The perceptive reader would have noticed some contradiction in the
3606 previous paragraphs. It is written that both @value{op-version} and
3607 @value{op-help} print something, and have all other options ignored. In
3608 fact, they cannot ignore each other, and one of them has to win. We do
3609 not specify which is stronger, here; experiment if you really wonder!
3610
3611 The short help output is quite succinct, and you might have to get
3612 back to the full documentation for precise points. If you are reading
3613 this paragraph, you already have the @command{tar} manual in some
3614 form. This manual is available in printed form, as a kind of small
3615 book. It may printed out of the @GNUTAR{}
3616 distribution, provided you have @TeX{} already installed somewhere,
3617 and a laser printer around. Just configure the distribution, execute
3618 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3619 usual way (contact your local guru to know how). If @GNUTAR{}
3620 has been conveniently installed at your place, this
3621 manual is also available in interactive, hypertextual form as an Info
3622 file. Just call @w{@samp{info tar}} or, if you do not have the
3623 @command{info} program handy, use the Info reader provided within
3624 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3625
3626 There is currently no @code{man} page for @GNUTAR{}.
3627 If you observe such a @code{man} page on the system you are running,
3628 either it does not long to @GNUTAR{}, or it has not
3629 been produced by @acronym{GNU}. Currently, @GNUTAR{}
3630 documentation is provided in Texinfo format only, if we
3631 except, of course, the short result of @kbd{tar --help}.
3632
3633 @node verbose
3634 @section Checking @command{tar} progress
3635
3636 @cindex Progress information
3637 @cindex Status information
3638 @cindex Information on progress and status of operations
3639 @cindex Verbose operation
3640 @cindex Block number where error occurred
3641 @cindex Error message, block number of
3642 @cindex Version of the @command{tar} program
3643
3644 @cindex Getting more information during the operation
3645 @cindex Information during operation
3646 @cindex Feedback from @command{tar}
3647
3648 Typically, @command{tar} performs most operations without reporting any
3649 information to the user except error messages. When using @command{tar}
3650 with many options, particularly ones with complicated or
3651 difficult-to-predict behavior, it is possible to make serious mistakes.
3652 @command{tar} provides several options that make observing @command{tar}
3653 easier. These options cause @command{tar} to print information as it
3654 progresses in its job, and you might want to use them just for being
3655 more careful about what is going on, or merely for entertaining
3656 yourself. If you have encountered a problem when operating on an
3657 archive, however, you may need more information than just an error
3658 message in order to solve the problem. The following options can be
3659 helpful diagnostic tools.
3660
3661 Normally, the @value{op-list} command to list an archive prints just
3662 the file names (one per line) and the other commands are silent.
3663 When used with most operations, the @value{op-verbose} option causes
3664 @command{tar} to print the name of each file or archive member as it
3665 is processed. This and the other options which make @command{tar} print
3666 status information can be useful in monitoring @command{tar}.
3667
3668 With @value{op-create} or @value{op-extract}, @value{op-verbose} used once
3669 just prints the names of the files or members as they are processed.
3670 Using it twice causes @command{tar} to print a longer listing (reminiscent
3671 of @samp{ls -l}) for each member. Since @value{op-list} already prints
3672 the names of the members, @value{op-verbose} used once with @value{op-list}
3673 causes @command{tar} to print an @samp{ls -l} type listing of the files
3674 in the archive. The following examples both extract members with
3675 long list output:
3676
3677 @smallexample
3678 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3679 $ @kbd{tar xvvf archive.tar}
3680 @end smallexample
3681
3682 Verbose output appears on the standard output except when an archive is
3683 being written to the standard output, as with @samp{tar --create
3684 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3685 installer let standard output be the default archive). In that case
3686 @command{tar} writes verbose output to the standard error stream.
3687
3688 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3689 verbose output to @var{file} rather than to standard output or standard
3690 error.
3691
3692 The @value{op-totals} option---which is only meaningful when used with
3693 @value{op-create}---causes @command{tar} to print the total
3694 amount written to the archive, after it has been fully created.
3695
3696 The @value{op-checkpoint} option prints an occasional message
3697 as @command{tar} reads or writes the archive. In fact, it prints
3698 a message each 10 records read or written. It is designed for
3699 those who don't need the more detailed (and voluminous) output of
3700 @value{op-block-number}, but do want visual confirmation that @command{tar}
3701 is actually making forward progress.
3702
3703 @FIXME{There is some confusion here. It seems that -R once wrote a
3704 message at @samp{every} record read or written.}
3705
3706 The @value{op-show-omitted-dirs} option, when reading an archive---with
3707 @value{op-list} or @value{op-extract}, for example---causes a message
3708 to be printed for each directory in the archive which is skipped.
3709 This happens regardless of the reason for skipping: the directory might
3710 not have been named on the command line (implicitly or explicitly),
3711 it might be excluded by the use of the @value{op-exclude} option, or
3712 some other reason.
3713
3714 If @value{op-block-number} is used, @command{tar} prints, along with
3715 every message it would normally produce, the block number within the
3716 archive where the message was triggered. Also, supplementary messages
3717 are triggered when reading blocks full of NULs, or when hitting end of
3718 file on the archive. As of now, if the archive if properly terminated
3719 with a NUL block, the reading of the file may stop before end of file
3720 is met, so the position of end of file will not usually show when
3721 @value{op-block-number} is used. Note that @GNUTAR{}
3722 drains the archive before exiting when reading the
3723 archive from a pipe.
3724
3725 This option is especially useful when reading damaged archives, since
3726 it helps pinpoint the damaged sections. It can also be used with
3727 @value{op-list} when listing a file-system backup tape, allowing you to
3728 choose among several backup tapes when retrieving a file later, in
3729 favor of the tape where the file appears earliest (closest to the
3730 front of the tape). @FIXME-xref{when the node name is set and the
3731 backup section written.}
3732
3733 @node interactive
3734 @section Asking for Confirmation During Operations
3735 @cindex Interactive operation
3736
3737 Typically, @command{tar} carries out a command without stopping for
3738 further instructions. In some situations however, you may want to
3739 exclude some files and archive members from the operation (for instance
3740 if disk or storage space is tight). You can do this by excluding
3741 certain files automatically (@pxref{Choosing}), or by performing
3742 an operation interactively, using the @value{op-interactive} option.
3743 @command{tar} also accepts @samp{--confirmation} for this option.
3744
3745 When the @value{op-interactive} option is specified, before
3746 reading, writing, or deleting files, @command{tar} first prints a message
3747 for each such file, telling what operation it intends to take, then asks
3748 for confirmation on the terminal. The actions which require
3749 confirmation include adding a file to the archive, extracting a file
3750 from the archive, deleting a file from the archive, and deleting a file
3751 from disk. To confirm the action, you must type a line of input
3752 beginning with @samp{y}. If your input line begins with anything other
3753 than @samp{y}, @command{tar} skips that file.
3754
3755 If @command{tar} is reading the archive from the standard input,
3756 @command{tar} opens the file @file{/dev/tty} to support the interactive
3757 communications.
3758
3759 Verbose output is normally sent to standard output, separate from
3760 other error messages. However, if the archive is produced directly
3761 on standard output, then verbose output is mixed with errors on
3762 @code{stderr}. Producing the archive on standard output may be used
3763 as a way to avoid using disk space, when the archive is soon to be
3764 consumed by another process reading it, say. Some people felt the need
3765 of producing an archive on stdout, still willing to segregate between
3766 verbose output and error output. A possible approach would be using a
3767 named pipe to receive the archive, and having the consumer process to
3768 read from that named pipe. This has the advantage of letting standard
3769 output free to receive verbose output, all separate from errors.
3770
3771 @node operations
3772 @chapter @GNUTAR{} Operations
3773
3774 @menu
3775 * Basic tar::
3776 * Advanced tar::
3777 * create options::
3778 * extract options::
3779 * backup::
3780 * Applications::
3781 * looking ahead::
3782 @end menu
3783
3784 @node Basic tar
3785 @section Basic @GNUTAR{} Operations
3786
3787 The basic @command{tar} operations, @value{op-create}, @value{op-list} and
3788 @value{op-extract}, are currently presented and described in the tutorial
3789 chapter of this manual. This section provides some complementary notes
3790 for these operations.
3791
3792 @table @asis
3793 @item @value{op-create}
3794
3795 Creating an empty archive would have some kind of elegance. One can
3796 initialize an empty archive and later use @value{op-append} for adding
3797 all members. Some applications would not welcome making an exception
3798 in the way of adding the first archive member. On the other hand,
3799 many people reported that it is dangerously too easy for @command{tar}
3800 to destroy a magnetic tape with an empty archive@footnote{This is well
3801 described in @cite{Unix-haters Handbook}, by Simson Garfinkel, Daniel
3802 Weise & Steven Strassmann, IDG Books, ISBN 1-56884-203-1.}. The two most
3803 common errors are:
3804
3805 @enumerate
3806 @item
3807 Mistakingly using @code{create} instead of @code{extract}, when the
3808 intent was to extract the full contents of an archive. This error
3809 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3810 the QWERTY keyboard. Instead of being unpacked, the archive then
3811 gets wholly destroyed. When users speak about @dfn{exploding} an
3812 archive, they usually mean something else :-).
3813
3814 @item
3815 Forgetting the argument to @code{file}, when the intent was to create
3816 an archive with a single file in it. This error is likely because a
3817 tired user can easily add the @kbd{f} key to the cluster of option
3818 letters, by the mere force of habit, without realizing the full
3819 consequence of doing so. The usual consequence is that the single
3820 file, which was meant to be saved, is rather destroyed.
3821 @end enumerate
3822
3823 So, recognizing the likelihood and the catastrophical nature of these
3824 errors, @GNUTAR{} now takes some distance from elegance, and
3825 cowardly refuses to create an archive when @value{op-create} option is
3826 given, there are no arguments besides options, and @value{op-files-from}
3827 option is @emph{not} used. To get around the cautiousness of @GNUTAR{}
3828 and nevertheless create an archive with nothing in it,
3829 one may still use, as the value for the @value{op-files-from} option,
3830 a file with no names in it, as shown in the following commands:
3831
3832 @smallexample
3833 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3834 @kbd{tar cfT empty-archive.tar /dev/null}
3835 @end smallexample
3836
3837 @item @value{op-extract}
3838
3839 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3840
3841 @item @value{op-list}
3842
3843 @GNUTAR{} now shows dates as @samp{1996-08-30},
3844 while it used to show them as @samp{Aug 30 1996}. (One can revert to
3845 the old behavior by defining @code{USE_OLD_CTIME} in @file{src/list.c}
3846 before reinstalling.) But preferably, people should get used to ISO
3847 8601 dates. Local American dates should be made available again with
3848 full date localization support, once ready. In the meantime, programs
3849 not being localizable for dates should prefer international dates,
3850 that's really the way to go.
3851
3852 Look up @url{http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html} if you
3853 are curious, it contains a detailed explanation of the ISO 8601 standard.
3854
3855 @end table
3856
3857 @node Advanced tar
3858 @section Advanced @GNUTAR{} Operations
3859
3860 Now that you have learned the basics of using @GNUTAR{}, you may want
3861 to learn about further ways in which @command{tar} can help you.
3862
3863 This chapter presents five, more advanced operations which you probably
3864 won't use on a daily basis, but which serve more specialized functions.
3865 We also explain the different styles of options and why you might want
3866 to use one or another, or a combination of them in your @command{tar}
3867 commands. Additionally, this chapter includes options which allow you to
3868 define the output from @command{tar} more carefully, and provide help and
3869 error correction in special circumstances.
3870
3871 @FIXME{check this after the chapter is actually revised to make sure
3872 it still introduces the info in the chapter correctly : ).}
3873
3874 @menu
3875 * Operations::
3876 * append::
3877 * update::
3878 * concatenate::
3879 * delete::
3880 * compare::
3881 @end menu
3882
3883 @node Operations
3884 @subsection The Five Advanced @command{tar} Operations
3885 @UNREVISED
3886
3887 In the last chapter, you learned about the first three operations to
3888 @command{tar}. This chapter presents the remaining five operations to
3889 @command{tar}: @samp{--append}, @samp{--update}, @samp{--concatenate},
3890 @samp{--delete}, and @samp{--compare}.
3891
3892 You are not likely to use these operations as frequently as those
3893 covered in the last chapter; however, since they perform specialized
3894 functions, they are quite useful when you do need to use them. We
3895 will give examples using the same directory and files that you created
3896 in the last chapter. As you may recall, the directory is called
3897 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3898 @samp{rock}, and the two archive files you created are
3899 @samp{collection.tar} and @samp{music.tar}.
3900
3901 We will also use the archive files @samp{afiles.tar} and
3902 @samp{bfiles.tar}. @samp{afiles.tar} contains the members @samp{apple},
3903 @samp{angst}, and @samp{aspic}. @samp{bfiles.tar} contains the members
3904 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3905
3906 Unless we state otherwise, all practicing you do and examples you follow
3907 in this chapter will take place in the @file{practice} directory that
3908 you created in the previous chapter; see @ref{prepare for examples}.
3909 (Below in this section, we will remind you of the state of the examples
3910 where the last chapter left them.)
3911
3912 The five operations that we will cover in this chapter are:
3913
3914 @table @kbd
3915 @item --append
3916 @itemx -r
3917 Add new entries to an archive that already exists.
3918 @item --update
3919 @itemx -r
3920 Add more recent copies of archive members to the end of an archive, if
3921 they exist.
3922 @item --concatenate
3923 @itemx --catenate
3924 @itemx -A
3925 Add one or more pre-existing archives to the end of another archive.
3926 @item --delete
3927 Delete items from an archive (does not work on tapes).
3928 @item --compare
3929 @itemx --diff
3930 @itemx -d
3931 Compare archive members to their counterparts in the file system.
3932 @end table
3933
3934 @node append
3935 @subsection How to Add Files to Existing Archives: @code{--append}
3936 @UNREVISED
3937
3938 If you want to add files to an existing archive, you don't need to
3939 create a new archive; you can use @value{op-append}. The archive must
3940 already exist in order to use @samp{--append}. (A related operation
3941 is the @samp{--update} operation; you can use this to add newer
3942 versions of archive members to an existing archive. To learn how to
3943 do this with @samp{--update}, @pxref{update}.)
3944
3945 If you use @value{op-append} to add a file that has the same name as an
3946 archive member to an archive containing that archive member, then the
3947 old member is not deleted. What does happen, however, is somewhat
3948 complex. @command{tar} @emph{allows} you to have infinite number of files
3949 with the same name. Some operations treat these same-named members no
3950 differently than any other set of archive members: for example, if you
3951 view an archive with @value{op-list}, you will see all of those members
3952 listed, with their modification times, owners, etc.
3953
3954 Other operations don't deal with these members as perfectly as you might
3955 prefer; if you were to use @value{op-extract} to extract the archive,
3956 only the most recently added copy of a member with the same name as four
3957 other members would end up in the working directory. This is because
3958 @samp{--extract} extracts an archive in the order the members appeared
3959 in the archive; the most recently archived members will be extracted
3960 last. Additionally, an extracted member will @emph{replace} a file of
3961 the same name which existed in the directory already, and @command{tar}
3962 will not prompt you about this@footnote{Unless you give it
3963 @option{--keep-old-files} option, or the disk copy is newer than the
3964 the one in the archive and you invoke @command{tar} with
3965 @option{--keep-newer-files} option}. Thus, only the most recently archived
3966 member will end up being extracted, as it will replace the one
3967 extracted before it, and so on.
3968
3969 There exists a special option that allows you to get around this
3970 behavior and extract (or list) only a particular copy of the file.
3971 This is @option{--occurrence} option. If you run @command{tar} with
3972 this option, it will extract only the first copy of the file. You
3973 may also give this option an argument specifying the number of
3974 copy to be extracted. Thus, for example if the archive
3975 @file{archive.tar} contained three copies of file @file{myfile}, then
3976 the command
3977
3978 @smallexample
3979 tar --extract --file archive.tar --occurrence=2 myfile
3980 @end smallexample
3981
3982 @noindent
3983 would extract only the second copy. @xref{Option Summary,---occurrence}, for the description of @value{op-occurrence} option.
3984
3985 @FIXME{ hag -- you might want to incorporate some of the above into the
3986 MMwtSN node; not sure. i didn't know how to make it simpler...
3987
3988 There are a few ways to get around this. (maybe xref Multiple Members
3989 with the Same Name.}
3990
3991 @cindex Members, replacing with other members
3992 @cindex Replacing members with other members
3993 If you want to replace an archive member, use @value{op-delete} to
3994 delete the member you want to remove from the archive, , and then use
3995 @samp{--append} to add the member you want to be in the archive. Note
3996 that you can not change the order of the archive; the most recently
3997 added member will still appear last. In this sense, you cannot truly
3998 ``replace'' one member with another. (Replacing one member with another
3999 will not work on certain types of media, such as tapes; see @ref{delete}
4000 and @ref{Media}, for more information.)
4001
4002 @menu
4003 * appending files:: Appending Files to an Archive
4004 * multiple::
4005 @end menu
4006
4007 @node appending files
4008 @subsubsection Appending Files to an Archive
4009 @UNREVISED
4010 @cindex Adding files to an Archive
4011 @cindex Appending files to an Archive
4012 @cindex Archives, Appending files to
4013
4014 The simplest way to add a file to an already existing archive is the
4015 @value{op-append} operation, which writes specified files into the
4016 archive whether or not they are already among the archived files.
4017 When you use @samp{--append}, you @emph{must} specify file name
4018 arguments, as there is no default. If you specify a file that already
4019 exists in the archive, another copy of the file will be added to the
4020 end of the archive. As with other operations, the member names of the
4021 newly added files will be exactly the same as their names given on the
4022 command line. The @value{op-verbose} option will print out the names
4023 of the files as they are written into the archive.
4024
4025 @samp{--append} cannot be performed on some tape drives, unfortunately,
4026 due to deficiencies in the formats those tape drives use. The archive
4027 must be a valid @command{tar} archive, or else the results of using this
4028 operation will be unpredictable. @xref{Media}.
4029
4030 To demonstrate using @samp{--append} to add a file to an archive,
4031 create a file called @file{rock} in the @file{practice} directory.
4032 Make sure you are in the @file{practice} directory. Then, run the
4033 following @command{tar} command to add @file{rock} to
4034 @file{collection.tar}:
4035
4036 @smallexample
4037 $ @kbd{tar --append --file=collection.tar rock}
4038 @end smallexample
4039
4040 @noindent
4041 If you now use the @value{op-list} operation, you will see that
4042 @file{rock} has been added to the archive:
4043
4044 @smallexample
4045 $ @kbd{tar --list --file=collection.tar}
4046 -rw-rw-rw- me user 28 1996-10-18 16:31 jazz
4047 -rw-rw-rw- me user 21 1996-09-23 16:44 blues
4048 -rw-rw-rw- me user 20 1996-09-23 16:44 folk
4049 -rw-rw-rw- me user 20 1996-09-23 16:44 rock
4050 @end smallexample
4051
4052 @FIXME{in theory, dan will (soon) try to turn this node into what it's
4053 title claims it will become...}
4054
4055 @node multiple
4056 @subsubsection Multiple Files with the Same Name
4057
4058 You can use @value{op-append} to add copies of files which have been
4059 updated since the archive was created. (However, we do not recommend
4060 doing this since there is another @command{tar} option called
4061 @samp{--update}; @pxref{update} for more information. We describe this
4062 use of @samp{--append} here for the sake of completeness.) @FIXME{is
4063 this really a good idea, to give this whole description for something
4064 which i believe is basically a Stupid way of doing something? certain
4065 aspects of it show ways in which tar is more broken than i'd personally
4066 like to admit to, specifically the last sentence. On the other hand, i
4067 don't think it's a good idea to be saying that we explicitly don't
4068 recommend using something, but i can't see any better way to deal with
4069 the situation.}When you extract the archive, the older version will be
4070 effectively lost. This works because files are extracted from an
4071 archive in the order in which they were archived. Thus, when the
4072 archive is extracted, a file archived later in time will replace a
4073 file of the same name which was archived earlier, even though the older
4074 version of the file will remain in the archive unless you delete all
4075 versions of the file.
4076
4077 Supposing you change the file @file{blues} and then append the changed
4078 version to @file{collection.tar}. As you saw above, the original
4079 @file{blues} is in the archive @file{collection.tar}. If you change the
4080 file and append the new version of the file to the archive, there will
4081 be two copies in the archive. When you extract the archive, the older
4082 version of the file will be extracted first, and then replaced by the
4083 newer version when it is extracted.
4084
4085 You can append the new, changed copy of the file @file{blues} to the
4086 archive in this way:
4087
4088 @smallexample
4089 $ @kbd{tar --append --verbose --file=collection.tar blues}
4090 blues
4091 @end smallexample
4092
4093 @noindent
4094 Because you specified the @samp{--verbose} option, @command{tar} has
4095 printed the name of the file being appended as it was acted on. Now
4096 list the contents of the archive:
4097
4098 @smallexample
4099 $ @kbd{tar --list --verbose --file=collection.tar}
4100 -rw-rw-rw- me user 28 1996-10-18 16:31 jazz
4101 -rw-rw-rw- me user 21 1996-09-23 16:44 blues
4102 -rw-rw-rw- me user 20 1996-09-23 16:44 folk
4103 -rw-rw-rw- me user 20 1996-09-23 16:44 rock
4104 -rw-rw-rw- me user 58 1996-10-24 18:30 blues
4105 @end smallexample
4106
4107 @noindent
4108 The newest version of @file{blues} is now at the end of the archive
4109 (note the different creation dates and file sizes). If you extract
4110 the archive, the older version of the file @file{blues} will be
4111 replaced by the newer version. You can confirm this by extracting
4112 the archive and running @samp{ls} on the directory.
4113
4114 If you wish to extract the first occurrence of the file @file{blues}
4115 from the archive, use @value{op-occurrence} option, as shown in
4116 the following example:
4117
4118 @smallexample
4119 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4120 -rw-rw-rw- me user 21 1996-09-23 16:44 blues
4121 @end smallexample
4122
4123 @xref{Writing}, for more information on @value{op-extract} and
4124 @xref{Option Summary, --occurrence}, for the description of
4125 @value{op-occurrence} option.
4126
4127 @node update
4128 @subsection Updating an Archive
4129 @UNREVISED
4130 @cindex Updating an archive
4131
4132 In the previous section, you learned how to use @value{op-append} to add
4133 a file to an existing archive. A related operation is
4134 @value{op-update}. The @samp{--update} operation updates a @command{tar}
4135 archive by comparing the date of the specified archive members against
4136 the date of the file with the same name. If the file has been modified
4137 more recently than the archive member, then the newer version of the
4138 file is added to the archive (as with @value{op-append}).
4139
4140 Unfortunately, you cannot use @samp{--update} with magnetic tape drives.
4141 The operation will fail.
4142
4143 @FIXME{other examples of media on which --update will fail? need to ask
4144 charles and/or mib/thomas/dave shevett..}
4145
4146 Both @samp{--update} and @samp{--append} work by adding to the end
4147 of the archive. When you extract a file from the archive, only the
4148 version stored last will wind up in the file system, unless you use
4149 the @value{op-backup} option. @FIXME-ref{Multiple Members with the
4150 Same Name}
4151
4152 @menu
4153 * how to update::
4154 @end menu
4155
4156 @node how to update
4157 @subsubsection How to Update an Archive Using @code{--update}
4158
4159 You must use file name arguments with the @value{op-update} operation.
4160 If you don't specify any files, @command{tar} won't act on any files and
4161 won't tell you that it didn't do anything (which may end up confusing
4162 you).
4163
4164 @FIXME{note: the above parenthetical added because in fact, this
4165 behavior just confused the author. :-) }
4166
4167 To see the @samp{--update} option at work, create a new file,
4168 @file{classical}, in your practice directory, and some extra text to the
4169 file @file{blues}, using any text editor. Then invoke @command{tar} with
4170 the @samp{update} operation and the @value{op-verbose} option specified,
4171 using the names of all the files in the practice directory as file name
4172 arguments:
4173
4174 @smallexample
4175 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4176 blues
4177 classical
4178 $
4179 @end smallexample
4180
4181 @noindent
4182 Because we have specified verbose mode, @command{tar} prints out the names
4183 of the files it is working on, which in this case are the names of the
4184 files that needed to be updated. If you run @samp{tar --list} and look
4185 at the archive, you will see @file{blues} and @file{classical} at its
4186 end. There will be a total of two versions of the member @samp{blues};
4187 the one at the end will be newer and larger, since you added text before
4188 updating it.
4189
4190 (The reason @command{tar} does not overwrite the older file when updating
4191 it is because writing to the middle of a section of tape is a difficult
4192 process. Tapes are not designed to go backward. @xref{Media}, for more
4193 information about tapes.
4194
4195 @value{op-update} is not suitable for performing backups for two
4196 reasons: it does not change directory content entries, and it
4197 lengthens the archive every time it is used. The @GNUTAR{}
4198 options intended specifically for backups are more
4199 efficient. If you need to run backups, please consult @ref{Backups}.
4200
4201 @node concatenate
4202 @subsection Combining Archives with @code{--concatenate}
4203
4204 @cindex Adding archives to an archive
4205 @cindex Concatenating Archives
4206 Sometimes it may be convenient to add a second archive onto the end of
4207 an archive rather than adding individual files to the archive. To add
4208 one or more archives to the end of another archive, you should use the
4209 @value{op-concatenate} operation.
4210
4211 To use @samp{--concatenate}, name the archives to be concatenated on the
4212 command line. (Nothing happens if you don't list any.) The members,
4213 and their member names, will be copied verbatim from those archives. If
4214 this causes multiple members to have the same name, it does not delete
4215 any members; all the members with the same name coexist. @FIXME-ref{For
4216 information on how this affects reading the archive, Multiple
4217 Members with the Same Name.}
4218
4219 To demonstrate how @samp{--concatenate} works, create two small archives
4220 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4221 files from @file{practice}:
4222
4223 @smallexample
4224 $ @kbd{tar -cvf bluesrock.tar blues rock}
4225 blues
4226 classical
4227 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4228 folk
4229 jazz
4230 @end smallexample
4231
4232 @noindent
4233 If you like, You can run @samp{tar --list} to make sure the archives
4234 contain what they are supposed to:
4235
4236 @smallexample
4237 $ @kbd{tar -tvf bluesrock.tar}
4238 -rw-rw-rw- melissa user 105 1997-01-21 19:42 blues
4239 -rw-rw-rw- melissa user 33 1997-01-20 15:34 rock
4240 $ @kbd{tar -tvf folkjazz.tar}
4241 -rw-rw-rw- melissa user 20 1996-09-23 16:44 folk
4242 -rw-rw-rw- melissa user 65 1997-01-30 14:15 jazz
4243 @end smallexample
4244
4245 We can concatenate these two archives with @command{tar}:
4246
4247 @smallexample
4248 $ @kbd{cd ..}
4249 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4250 @end smallexample
4251
4252 If you now list the contents of the @file{bluesclass.tar}, you will see
4253 that now it also contains the archive members of @file{jazzfolk.tar}:
4254
4255 @smallexample
4256 $ @kbd{tar --list --file=bluesrock.tar}
4257 blues
4258 rock
4259 jazz
4260 folk
4261 @end smallexample
4262
4263 When you use @samp{--concatenate}, the source and target archives must
4264 already exist and must have been created using compatible format
4265 parameters. @FIXME-pxref{Matching Format Parameters}The new,
4266 concatenated archive will be called by the same name as the first
4267 archive listed on the command line. @FIXME{is there a way to specify a
4268 new name?}
4269
4270 Like @value{op-append}, this operation cannot be performed on some
4271 tape drives, due to deficiencies in the formats those tape drives use.
4272
4273 @cindex @code{concatenate} vs @command{cat}
4274 @cindex @command{cat} vs @code{concatenate}
4275 It may seem more intuitive to you to want or try to use @command{cat} to
4276 concatenate two archives instead of using the @samp{--concatenate}
4277 operation; after all, @command{cat} is the utility for combining files.
4278
4279 However, @command{tar} archives incorporate an end-of-file marker which
4280 must be removed if the concatenated archives are to be read properly as
4281 one archive. @samp{--concatenate} removes the end-of-archive marker
4282 from the target archive before each new archive is appended. If you use
4283 @command{cat} to combine the archives, the result will not be a valid
4284 @command{tar} format archive. If you need to retrieve files from an
4285 archive that was added to using the @command{cat} utility, use the
4286 @value{op-ignore-zeros} option. @xref{Ignore Zeros}, for further
4287 information on dealing with archives improperly combined using the
4288 @command{cat} shell utility.
4289
4290 @FIXME{this shouldn't go here. where should it go?} You must specify
4291 the source archives using @value{op-file} (@value{pxref-file}). If you
4292 do not specify the target archive, @command{tar} uses the value of the
4293 environment variable @env{TAPE}, or, if this has not been set, the
4294 default archive name.
4295
4296 @node delete
4297 @subsection Removing Archive Members Using @samp{--delete}
4298 @UNREVISED
4299 @cindex Deleting files from an archive
4300 @cindex Removing files from an archive
4301
4302 You can remove members from an archive by using the @value{op-delete}
4303 option. Specify the name of the archive with @value{op-file} and then
4304 specify the names of the members to be deleted; if you list no member
4305 names, nothing will be deleted. The @value{op-verbose} option will
4306 cause @command{tar} to print the names of the members as they are deleted.
4307 As with @value{op-extract}, you must give the exact member names when
4308 using @samp{tar --delete}. @samp{--delete} will remove all versions of
4309 the named file from the archive. The @samp{--delete} operation can run
4310 very slowly.
4311
4312 Unlike other operations, @samp{--delete} has no short form.
4313
4314 @cindex Tapes, using @code{--delete} and
4315 @cindex Deleting from tape archives
4316 This operation will rewrite the archive. You can only use
4317 @samp{--delete} on an archive if the archive device allows you to
4318 write to any point on the media, such as a disk; because of this, it
4319 does not work on magnetic tapes. Do not try to delete an archive member
4320 from a magnetic tape; the action will not succeed, and you will be
4321 likely to scramble the archive and damage your tape. There is no safe
4322 way (except by completely re-writing the archive) to delete files from
4323 most kinds of magnetic tape. @xref{Media}.
4324
4325 To delete all versions of the file @file{blues} from the archive
4326 @file{collection.tar} in the @file{practice} directory, make sure you
4327 are in that directory, and then,
4328
4329 @smallexample
4330 $ @kbd{tar --list --file=collection.tar}
4331 blues
4332 folk
4333 jazz
4334 rock
4335 practice/blues
4336 practice/folk
4337 practice/jazz
4338 practice/rock
4339 practice/blues
4340 $ @kbd{tar --delete --file=collection.tar blues}
4341 $ @kbd{tar --list --file=collection.tar}
4342 folk
4343 jazz
4344 rock
4345 $
4346 @end smallexample
4347
4348 @FIXME{I changed the order of these nodes around and haven't had a chance
4349 to fix the above example's results, yet. I have to play with this and
4350 follow it and see what it actually does!}
4351
4352 The @value{op-delete} option has been reported to work properly when
4353 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4354
4355 @node compare
4356 @subsection Comparing Archive Members with the File System
4357 @cindex Verifying the currency of an archive
4358 @UNREVISED
4359
4360 The @samp{--compare} (@samp{-d}), or @samp{--diff} operation compares
4361 specified archive members against files with the same names, and then
4362 reports differences in file size, mode, owner, modification date and
4363 contents. You should @emph{only} specify archive member names, not file
4364 names. If you do not name any members, then @command{tar} will compare the
4365 entire archive. If a file is represented in the archive but does not
4366 exist in the file system, @command{tar} reports a difference.
4367
4368 You have to specify the record size of the archive when modifying an
4369 archive with a non-default record size.
4370
4371 @command{tar} ignores files in the file system that do not have
4372 corresponding members in the archive.
4373
4374 The following example compares the archive members @file{rock},
4375 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4376 files of the same name in the file system. (Note that there is no file,
4377 @file{funk}; @command{tar} will report an error message.)
4378
4379 @smallexample
4380 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4381 rock
4382 blues
4383 tar: funk not found in archive
4384 @end smallexample
4385
4386 @noindent
4387 @FIXME{what does this actually depend on? i'm making a guess,
4388 here.}Depending on the system where you are running @command{tar} and the
4389 version you are running, @command{tar} may have a different error message,
4390 such as:
4391
4392 @smallexample
4393 funk: does not exist
4394 @end smallexample
4395
4396 @FIXME-xref{somewhere, for more information about format parameters.
4397 Melissa says: such as "format variations"? But why? Clearly I don't
4398 get it yet; I'll deal when I get to that section.}
4399
4400 The spirit behind the @value{op-compare} option is to check whether the
4401 archive represents the current state of files on disk, more than validating
4402 the integrity of the archive media. For this later goal, @xref{verify}.
4403
4404 @node create options
4405 @section Options Used by @code{--create}
4406
4407 The previous chapter described the basics of how to use
4408 @value{op-create} to create an archive from a set of files.
4409 @xref{create}. This section described advanced options to be used with
4410 @samp{--create}.
4411
4412 @menu
4413 * Ignore Failed Read::
4414 @end menu
4415
4416 @node Ignore Failed Read
4417 @subsection Ignore Fail Read
4418
4419 @table @kbd
4420 @item --ignore-failed-read
4421 Do not exit with nonzero on unreadable files or directories.
4422 @end table
4423
4424 @node extract options
4425 @section Options Used by @code{--extract}
4426 @UNREVISED
4427
4428 @FIXME{i need to get dan to go over these options with me and see if
4429 there's a better way of organizing them.}
4430
4431 The previous chapter showed how to use @value{op-extract} to extract
4432 an archive into the filesystem. Various options cause @command{tar} to
4433 extract more information than just file contents, such as the owner,
4434 the permissions, the modification date, and so forth. This section
4435 presents options to be used with @samp{--extract} when certain special
4436 considerations arise. You may review the information presented in
4437 @ref{extract} for more basic information about the
4438 @samp{--extract} operation.
4439
4440 @menu
4441 * Reading:: Options to Help Read Archives
4442 * Writing:: Changing How @command{tar} Writes Files
4443 * Scarce:: Coping with Scarce Resources
4444 @end menu
4445
4446 @node Reading
4447 @subsection Options to Help Read Archives
4448 @cindex Options when reading archives
4449 @cindex Reading incomplete records
4450 @cindex Records, incomplete
4451 @cindex End-of-archive entries, ignoring
4452 @cindex Ignoring end-of-archive entries
4453 @cindex Large lists of file names on small machines
4454 @cindex Small memory
4455 @cindex Running out of space
4456 @UNREVISED
4457
4458 Normally, @command{tar} will request data in full record increments from
4459 an archive storage device. If the device cannot return a full record,
4460 @command{tar} will report an error. However, some devices do not always
4461 return full records, or do not require the last record of an archive to
4462 be padded out to the next record boundary. To keep reading until you
4463 obtain a full record, or to accept an incomplete record if it contains
4464 an end-of-archive marker, specify the @value{op-read-full-records} option
4465 in conjunction with the @value{op-extract} or @value{op-list} operations.
4466 @value{xref-read-full-records}.
4467
4468 The @value{op-read-full-records} option is turned on by default when
4469 @command{tar} reads an archive from standard input, or from a remote
4470 machine. This is because on BSD Unix systems, attempting to read a
4471 pipe returns however much happens to be in the pipe, even if it is
4472 less than was requested. If this option were not enabled, @command{tar}
4473 would fail as soon as it read an incomplete record from the pipe.
4474
4475 If you're not sure of the blocking factor of an archive, you can
4476 read the archive by specifying @value{op-read-full-records} and
4477 @value{op-blocking-factor}, using a blocking factor larger than what the
4478 archive uses. This lets you avoid having to determine the blocking factor
4479 of an archive. @value{xref-blocking-factor}.
4480
4481 @menu
4482 * read full records::
4483 * Ignore Zeros::
4484 @end menu
4485
4486 @node read full records
4487 @unnumberedsubsubsec Reading Full Records
4488
4489 @FIXME{need sentence or so of intro here}
4490
4491 @table @kbd
4492 @item --read-full-records
4493 @item -B
4494 Use in conjunction with @value{op-extract} to read an archive which
4495 contains incomplete records, or one which has a blocking factor less
4496 than the one specified.
4497 @end table
4498
4499 @node Ignore Zeros
4500 @unnumberedsubsubsec Ignoring Blocks of Zeros
4501
4502 Normally, @command{tar} stops reading when it encounters a block of zeros
4503 between file entries (which usually indicates the end of the archive).
4504 @value{op-ignore-zeros} allows @command{tar} to completely read an archive
4505 which contains a block of zeros before the end (i.e.@: a damaged
4506 archive, or one which was created by concatenating several archives
4507 together).
4508
4509 The @value{op-ignore-zeros} option is turned off by default because many
4510 versions of @command{tar} write garbage after the end-of-archive entry,
4511 since that part of the media is never supposed to be read. @GNUTAR{}
4512 does not write after the end of an archive, but seeks to
4513 maintain compatiblity among archiving utilities.
4514
4515 @table @kbd
4516 @item --ignore-zeros
4517 @itemx -i
4518 To ignore blocks of zeros (ie.@: end-of-archive entries) which may be
4519 encountered while reading an archive. Use in conjunction with
4520 @value{op-extract} or @value{op-list}.
4521 @end table
4522
4523 @node Writing
4524 @subsection Changing How @command{tar} Writes Files
4525 @cindex Overwriting old files, prevention
4526 @cindex Protecting old files
4527 @cindex Modification times of extracted files
4528 @cindex Permissions of extracted files
4529 @cindex Modes of extracted files
4530 @cindex Writing extracted files to standard output
4531 @cindex Standard output, writing extracted files to
4532 @UNREVISED
4533
4534 @FIXME{need to mention the brand new option, --backup}
4535
4536 @menu
4537 * Dealing with Old Files::
4538 * Overwrite Old Files::
4539 * Keep Old Files::
4540 * Keep Newer Files::
4541 * Unlink First::
4542 * Recursive Unlink::
4543 * Modification Times::
4544 * Setting Access Permissions::
4545 * Writing to Standard Output::
4546 * remove files::
4547 @end menu
4548
4549 @node Dealing with Old Files
4550 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4551
4552 When extracting files, if @command{tar} discovers that the extracted
4553 file already exists, it normally replaces the file by removing it before
4554 extracting it, to prevent confusion in the presence of hard or symbolic
4555 links. (If the existing file is a symbolic link, it is removed, not
4556 followed.) However, if a directory cannot be removed because it is
4557 nonempty, @command{tar} normally overwrites its metadata (ownership,
4558 permission, etc.). The @option{--overwrite-dir} option enables this
4559 default behavior. To be more cautious and preserve the metadata of
4560 such a directory, use the @option{--no-overwrite-dir} option.
4561
4562 To be even more cautious and prevent existing files from being replaced, use
4563 the @value{op-keep-old-files} option. It causes @command{tar} to refuse
4564 to replace or update a file that already exists, i.e., a file with the
4565 same name as an archive member prevents extraction of that archive
4566 member. Instead, it reports an error.
4567
4568 To be more aggressive about altering existing files, use the
4569 @value{op-overwrite} option. It causes @command{tar} to overwrite
4570 existing files and to follow existing symbolic links when extracting.
4571
4572 Some people argue that @GNUTAR{} should not hesitate
4573 to overwrite files with other files when extracting. When extracting
4574 a @command{tar} archive, they expect to see a faithful copy of the
4575 state of the filesystem when the archive was created. It is debatable
4576 that this would always be a proper behavior. For example, suppose one
4577 has an archive in which @file{usr/local} is a link to
4578 @file{usr/local2}. Since then, maybe the site removed the link and
4579 renamed the whole hierarchy from @file{/usr/local2} to
4580 @file{/usr/local}. Such things happen all the time. I guess it would
4581 not be welcome at all that @GNUTAR{} removes the
4582 whole hierarchy just to make room for the link to be reinstated
4583 (unless it @emph{also} simultaneously restores the full
4584 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4585 able to remove a whole hierarchy to reestablish a symbolic link, for
4586 example, but @emph{only if} @value{op-recursive-unlink} is specified
4587 to allow this behavior. In any case, single files are silently
4588 removed.
4589
4590 Finally, the @value{op-unlink-first} option can improve performance in
4591 some cases by causing @command{tar} to remove files unconditionally
4592 before extracting them.
4593
4594 @node Overwrite Old Files
4595 @unnumberedsubsubsec Overwrite Old Files
4596
4597 @table @kbd
4598 @item --overwrite
4599 Overwrite existing files and directory metadata when extracting files
4600 from an archive.
4601
4602 This
4603 causes @command{tar} to write extracted files into the file system without
4604 regard to the files already on the system; i.e., files with the same
4605 names as archive members are overwritten when the archive is extracted.
4606 It also causes @command{tar} to extract the ownership, permissions,
4607 and time stamps onto any preexisting files or directories.
4608 If the name of a corresponding file name is a symbolic link, the file
4609 pointed to by the symbolic link will be overwritten instead of the
4610 symbolic link itself (if this is possible). Moreover, special devices,
4611 empty directories and even symbolic links are automatically removed if
4612 they are in the way of extraction.
4613
4614 Be careful when using the @value{op-overwrite} option, particularly when
4615 combined with the @value{op-absolute-names} option, as this combination
4616 can change the contents, ownership or permissions of any file on your
4617 system. Also, many systems do not take kindly to overwriting files that
4618 are currently being executed.
4619
4620 @item --overwrite-dir
4621 Overwrite the metadata of directories when extracting files from an
4622 archive, but remove other files before extracting.
4623 @end table
4624
4625 @node Keep Old Files
4626 @unnumberedsubsubsec Keep Old Files
4627
4628 @table @kbd
4629 @item --keep-old-files
4630 @itemx -k
4631 Do not replace existing files from archive. The
4632 @value{op-keep-old-files} option prevents @command{tar} from replacing
4633 existing files with files with the same name from the archive.
4634 The @value{op-keep-old-files} option is meaningless with @value{op-list}.
4635 Prevents @command{tar} from replacing files in the file system during
4636 extraction.
4637 @end table
4638
4639 @node Keep Newer Files
4640 @unnumberedsubsubsec Keep Newer Files
4641
4642 @table @kbd
4643 @item --keep-newer-files
4644 Do not replace existing files that are newer than their archive
4645 copies. This option is meaningless with @value{op-list}.
4646 @end table
4647
4648 @node Unlink First
4649 @unnumberedsubsubsec Unlink First
4650
4651 @table @kbd
4652 @item --unlink-first
4653 @itemx -U
4654 Remove files before extracting over them.
4655 This can make @command{tar} run a bit faster if you know in advance
4656 that the extracted files all need to be removed. Normally this option
4657 slows @command{tar} down slightly, so it is disabled by default.
4658 @end table
4659
4660 @node Recursive Unlink
4661 @unnumberedsubsubsec Recursive Unlink
4662
4663 @table @kbd
4664 @item --recursive-unlink
4665 When this option is specified, try removing files and directory hierarchies
4666 before extracting over them. @emph{This is a dangerous option!}
4667 @end table
4668
4669 If you specify the @value{op-recursive-unlink} option,
4670 @command{tar} removes @emph{anything} that keeps you from extracting a file
4671 as far as current permissions will allow it. This could include removal
4672 of the contents of a full directory hierarchy.
4673
4674 @node Modification Times
4675 @unnumberedsubsubsec Setting Modification Times
4676
4677 Normally, @command{tar} sets the modification times of extracted files to
4678 the modification times recorded for the files in the archive, but
4679 limits the permissions of extracted files by the current @code{umask}
4680 setting.
4681
4682 To set the modification times of extracted files to the time when
4683 the files were extracted, use the @value{op-touch} option in
4684 conjunction with @value{op-extract}.
4685
4686 @table @kbd
4687 @item --touch
4688 @itemx -m
4689 Sets the modification time of extracted archive members to the time
4690 they were extracted, not the time recorded for them in the archive.
4691 Use in conjunction with @value{op-extract}.
4692 @end table
4693
4694 @node Setting Access Permissions
4695 @unnumberedsubsubsec Setting Access Permissions
4696
4697 To set the modes (access permissions) of extracted files to those
4698 recorded for those files in the archive, use @samp{--same-permissions}
4699 in conjunction with the @value{op-extract} operation. @FIXME{Should be
4700 aliased to ignore-umask.}
4701
4702 @table @kbd
4703 @item --preserve-permission
4704 @itemx --same-permission
4705 @itemx --ignore-umask
4706 @itemx -p
4707 Set modes of extracted archive members to those recorded in the
4708 archive, instead of current umask settings. Use in conjunction with
4709 @value{op-extract}.
4710 @end table
4711
4712 @FIXME{Following paragraph needs to be rewritten: why doesn't this cat
4713 files together, why is this useful. is it really useful with
4714 more than one file?}
4715
4716 @node Writing to Standard Output
4717 @unnumberedsubsubsec Writing to Standard Output
4718
4719 To write the extracted files to the standard output, instead of
4720 creating the files on the file system, use @value{op-to-stdout} in
4721 conjunction with @value{op-extract}. This option is useful if you are
4722 extracting files to send them through a pipe, and do not need to
4723 preserve them in the file system. If you extract multiple members,
4724 they appear on standard output concatenated, in the order they are
4725 found in the archive.
4726
4727 @table @kbd
4728 @item --to-stdout
4729 @itemx -O
4730 Writes files to the standard output. Used in conjunction with
4731 @value{op-extract}. Extract files to standard output. When this option
4732 is used, instead of creating the files specified, @command{tar} writes
4733 the contents of the files extracted to its standard output. This may
4734 be useful if you are only extracting the files in order to send them
4735 through a pipe. This option is meaningless with @value{op-list}.
4736 @end table
4737
4738 This can be useful, for example, if you have a tar archive containing
4739 a big file and don't want to store the file on disk before processing
4740 it. You can use a command like this:
4741
4742 @smallexample
4743 tar -xOzf foo.tgz bigfile | process
4744 @end smallexample
4745
4746 or even like this if you want to process the concatenation of the files:
4747
4748 @smallexample
4749 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4750 @end smallexample
4751
4752 @node remove files
4753 @unnumberedsubsubsec Removing Files
4754
4755 @FIXME{the various macros in the front of the manual think that this
4756 option goes in this section. i have no idea; i only know it's nowhere
4757 else in the book...}
4758
4759 @table @kbd
4760 @item --remove-files
4761 Remove files after adding them to the archive.
4762 @end table
4763
4764 @node Scarce
4765 @subsection Coping with Scarce Resources
4766 @cindex Middle of the archive, starting in the
4767 @cindex Running out of space during extraction
4768 @cindex Disk space, running out of
4769 @cindex Space on the disk, recovering from lack of
4770 @UNREVISED
4771
4772 @menu
4773 * Starting File::
4774 * Same Order::
4775 @end menu
4776
4777 @node Starting File
4778 @unnumberedsubsubsec Starting File
4779
4780 @table @kbd
4781 @item --starting-file=@var{name}
4782 @itemx -K @var{name}
4783 Starts an operation in the middle of an archive. Use in conjunction
4784 with @value{op-extract} or @value{op-list}.
4785 @end table
4786
4787 If a previous attempt to extract files failed due to lack of disk
4788 space, you can use @value{op-starting-file} to start extracting only
4789 after member @var{name} of the archive. This assumes, of course, that
4790 there is now free space, or that you are now extracting into a
4791 different file system. (You could also choose to suspend @command{tar},
4792 remove unnecessary files from the file system, and then restart the
4793 same @command{tar} operation. In this case, @value{op-starting-file} is
4794 not necessary. @value{xref-incremental}, @value{xref-interactive},
4795 and @value{ref-exclude}.)
4796
4797 @node Same Order
4798 @unnumberedsubsubsec Same Order
4799
4800 @table @kbd
4801 @item --same-order
4802 @itemx --preserve-order
4803 @itemx -s
4804 To process large lists of file names on machines with small amounts of
4805 memory. Use in conjunction with @value{op-compare},
4806 @value{op-list}
4807 or @value{op-extract}.
4808 @end table
4809
4810 @FIXME{we don't need/want --preserve to exist any more (from melissa:
4811 ie, don't want that *version* of the option to exist, or don't want
4812 the option to exist in either version?}
4813
4814 @FIXME{i think this explanation is lacking.}
4815
4816 The @value{op-same-order} option tells @command{tar} that the list of file
4817 names to be listed or extracted is sorted in the same order as the
4818 files in the archive. This allows a large list of names to be used,
4819 even on a small machine that would not otherwise be able to hold all
4820 the names in memory at the same time. Such a sorted list can easily be
4821 created by running @samp{tar -t} on the archive and editing its output.
4822
4823 This option is probably never needed on modern computer systems.
4824
4825 @node backup
4826 @section Backup options
4827
4828 @cindex backup options
4829
4830 @GNUTAR{} offers options for making backups of files
4831 before writing new versions. These options control the details of
4832 these backups. They may apply to the archive itself before it is
4833 created or rewritten, as well as individual extracted members. Other
4834 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
4835 and @command{mv}, for example) offer similar options.
4836
4837 Backup options may prove unexpectedly useful when extracting archives
4838 containing many members having identical name, or when extracting archives
4839 on systems having file name limitations, making different members appear
4840 has having similar names through the side-effect of name truncation.
4841 (This is true only if we have a good scheme for truncated backup names,
4842 which I'm not sure at all: I suspect work is needed in this area.)
4843 When any existing file is backed up before being overwritten by extraction,
4844 then clashing files are automatically be renamed to be unique, and the
4845 true name is kept for only the last file of a series of clashing files.
4846 By using verbose mode, users may track exactly what happens.
4847
4848 At the detail level, some decisions are still experimental, and may
4849 change in the future, we are waiting comments from our users. So, please
4850 do not learn to depend blindly on the details of the backup features.
4851 For example, currently, directories themselves are never renamed through
4852 using these options, so, extracting a file over a directory still has
4853 good chances to fail. Also, backup options apply to created archives,
4854 not only to extracted members. For created archives, backups will not
4855 be attempted when the archive is a block or character device, or when it
4856 refers to a remote file.
4857
4858 For the sake of simplicity and efficiency, backups are made by renaming old
4859 files prior to creation or extraction, and not by copying. The original
4860 name is restored if the file creation fails. If a failure occurs after a
4861 partial extraction of a file, both the backup and the partially extracted
4862 file are kept.
4863
4864 @table @samp
4865
4866 @item --backup[=@var{method}]
4867 @opindex --backup
4868 @vindex VERSION_CONTROL
4869 @cindex backups
4870 Back up files that are about to be overwritten or removed.
4871 Without this option, the original versions are destroyed.
4872
4873 Use @var{method} to determine the type of backups made.
4874 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
4875 environment variable. And if @env{VERSION_CONTROL} is not set,
4876 use the @samp{existing} method.
4877
4878 @vindex version-control @r{Emacs variable}
4879 This option corresponds to the Emacs variable @samp{version-control};
4880 the same values for @var{method} are accepted as in Emacs. This option
4881 also allows more descriptive names. The valid @var{method}s are:
4882
4883 @table @samp
4884 @item t
4885 @itemx numbered
4886 @opindex numbered @r{backup method}
4887 Always make numbered backups.
4888
4889 @item nil
4890 @itemx existing
4891 @opindex existing @r{backup method}
4892 Make numbered backups of files that already have them, simple backups
4893 of the others.
4894
4895 @item never
4896 @itemx simple
4897 @opindex simple @r{backup method}
4898 Always make simple backups.
4899
4900 @end table
4901
4902 @item --suffix=@var{suffix}
4903 @opindex --suffix
4904 @cindex backup suffix
4905 @vindex SIMPLE_BACKUP_SUFFIX
4906 Append @var{suffix} to each backup file made with @samp{--backup}. If this
4907 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
4908 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
4909 set, the default is @samp{~}, just as in Emacs.
4910
4911 @end table
4912
4913 Some people express the desire to @emph{always} use the @value{op-backup}
4914 option, by defining some kind of alias or script. This is not as easy
4915 as one may think, due to the fact that old style options should appear first
4916 and consume arguments a bit unpredictably for an alias or script. But,
4917 if you are ready to give up using old style options, you may resort to
4918 using something like (a Bourne shell function here):
4919
4920 @smallexample
4921 tar () @{ /usr/local/bin/tar --backup $*; @}
4922 @end smallexample
4923
4924 @node Applications
4925 @section Notable @command{tar} Usages
4926 @UNREVISED
4927
4928 @FIXME{Using Unix file linking capability to recreate directory
4929 structures---linking files into one subdirectory and then
4930 @command{tar}ring that directory.}
4931
4932 @FIXME{Nice hairy example using absolute-names, newer, etc.}
4933
4934 @findex uuencode
4935 You can easily use archive files to transport a group of files from
4936 one system to another: put all relevant files into an archive on one
4937 computer system, transfer the archive to another system, and extract
4938 the contents there. The basic transfer medium might be magnetic tape,
4939 Internet FTP, or even electronic mail (though you must encode the
4940 archive with @command{uuencode} in order to transport it properly by
4941 mail). Both machines do not have to use the same operating system, as
4942 long as they both support the @command{tar} program.
4943
4944 For example, here is how you might copy a directory's contents from
4945 one disk to another, while preserving the dates, modes, owners and
4946 link-structure of all the files therein. In this case, the transfer
4947 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
4948
4949 @smallexample
4950 $ @kbd{cd sourcedir; tar -cf - . | (cd targetdir; tar -xf -)}
4951 @end smallexample
4952
4953 @noindent
4954 The command also works using short option forms:
4955
4956 @smallexample
4957 $ @w{@kbd{cd sourcedir; tar --create --file=- . | (cd targetdir; tar --extract --file=-)}}
4958 @end smallexample
4959
4960 @noindent
4961 This is one of the easiest methods to transfer a @command{tar} archive.
4962
4963 @node looking ahead
4964 @section Looking Ahead: The Rest of this Manual
4965
4966 You have now seen how to use all eight of the operations available to
4967 @command{tar}, and a number of the possible options. The next chapter
4968 explains how to choose and change file and archive names, how to use
4969 files to store names of other files which you can then call as
4970 arguments to @command{tar} (this can help you save time if you expect to
4971 archive the same list of files a number of times), and so forth.
4972 @FIXME{in case it's not obvious, i'm making this up in some sense
4973 based on my limited memory of what the next chapter *really* does. i
4974 just wanted to flesh out this final section a little bit so i'd
4975 remember to stick it in here. :-)}
4976
4977 If there are too many files to conveniently list on the command line,
4978 you can list the names in a file, and @command{tar} will read that file.
4979 @value{xref-files-from}.
4980
4981 There are various ways of causing @command{tar} to skip over some files,
4982 and not archive them. @xref{Choosing}.
4983
4984 @node Backups
4985 @chapter Performing Backups and Restoring Files
4986 @UNREVISED
4987
4988 @GNUTAR{} is distributed along with the scripts
4989 which the Free Software Foundation uses for performing backups. There
4990 is no corresponding scripts available yet for doing restoration of
4991 files. Even if there is a good chance those scripts may be satisfying
4992 to you, they are not the only scripts or methods available for doing
4993 backups and restore. You may well create your own, or use more
4994 sophisticated packages dedicated to that purpose.
4995
4996 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
4997 Automatic Network Disk Archiver), a backup system developed by James
4998 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
4999 This is free software, and it is available at these places:
5000
5001 @smallexample
5002 http://www.cs.umd.edu/projects/amanda/amanda.html
5003 ftp://ftp.cs.umd.edu/pub/amanda
5004 @end smallexample
5005
5006 @ifclear PUBLISH
5007
5008 Here is a possible plan for a future documentation about the backuping
5009 scripts which are provided within the @GNUTAR{}
5010 distribution.
5011
5012 @smallexample
5013 .* dumps
5014 . + what are dumps
5015
5016 . + different levels of dumps
5017 . - full dump = dump everything
5018 . - level 1, level 2 dumps etc, -
5019 A level n dump dumps everything changed since the last level
5020 n-1 dump (?)
5021
5022 . + how to use scripts for dumps (ie, the concept)
5023 . - scripts to run after editing backup specs (details)
5024
5025 . + Backup Specs, what is it.
5026 . - how to customize
5027 . - actual text of script [/sp/dump/backup-specs]
5028
5029 . + Problems
5030 . - rsh doesn't work
5031 . - rtape isn't installed
5032 . - (others?)
5033
5034 . + the --incremental option of tar
5035
5036 . + tapes
5037 . - write protection
5038 . - types of media
5039 . : different sizes and types, useful for different things
5040 . - files and tape marks
5041 one tape mark between files, two at end.
5042 . - positioning the tape
5043 MT writes two at end of write,
5044 backspaces over one when writing again.
5045 @end smallexample
5046
5047 @end ifclear
5048
5049 This chapter documents both the provided shell scripts and @command{tar}
5050 options which are more specific to usage as a backup tool.
5051
5052 To @dfn{back up} a file system means to create archives that contain
5053 all the files in that file system. Those archives can then be used to
5054 restore any or all of those files (for instance if a disk crashes or a
5055 file is accidentally deleted). File system @dfn{backups} are also
5056 called @dfn{dumps}.
5057
5058 @menu
5059 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5060 * Inc Dumps:: Using @command{tar} to Perform Incremental Dumps
5061 * incremental and listed-incremental:: The Incremental Options
5062 * Backup Levels:: Levels of Backups
5063 * Backup Parameters:: Setting Parameters for Backups and Restoration
5064 * Scripted Backups:: Using the Backup Scripts
5065 * Scripted Restoration:: Using the Restore Script
5066 @end menu
5067
5068 @node Full Dumps
5069 @section Using @command{tar} to Perform Full Dumps
5070 @UNREVISED
5071
5072 @cindex full dumps
5073 @cindex dumps, full
5074
5075 @cindex corrupted archives
5076 Full dumps should only be made when no other people or programs
5077 are modifying files in the filesystem. If files are modified while
5078 @command{tar} is making the backup, they may not be stored properly in
5079 the archive, in which case you won't be able to restore them if you
5080 have to. (Files not being modified are written with no trouble, and do
5081 not corrupt the entire archive.)
5082
5083 You will want to use the @value{op-label} option to give the archive a
5084 volume label, so you can tell what this archive is even if the label
5085 falls off the tape, or anything like that.
5086
5087 Unless the filesystem you are dumping is guaranteed to fit on
5088 one volume, you will need to use the @value{op-multi-volume} option.
5089 Make sure you have enough tapes on hand to complete the backup.
5090
5091 If you want to dump each filesystem separately you will need to use
5092 the @value{op-one-file-system} option to prevent @command{tar} from crossing
5093 filesystem boundaries when storing (sub)directories.
5094
5095 The @value{op-incremental} option is not needed, since this is a complete
5096 copy of everything in the filesystem, and a full restore from this
5097 backup would only be done onto a completely empty disk.
5098
5099 Unless you are in a hurry, and trust the @command{tar} program (and your
5100 tapes), it is a good idea to use the @value{op-verify} option, to make
5101 sure your files really made it onto the dump properly. This will
5102 also detect cases where the file was modified while (or just after)
5103 it was being archived. Not all media (notably cartridge tapes) are
5104 capable of being verified, unfortunately.
5105
5106 @value{op-listed-incremental} take a file name argument always. If the
5107 file doesn't exist, run a level zero dump, creating the file. If the
5108 file exists, uses that file to see what has changed.
5109
5110 @value{op-incremental} @FIXME{look it up}
5111
5112 @value{op-incremental} handle old @acronym{GNU}-format incremental backup.
5113
5114 This option should only be used when creating an incremental backup of
5115 a filesystem. When the @value{op-incremental} option is used, @command{tar}
5116 writes, at the beginning of the archive, an entry for each of the
5117 directories that will be operated on. The entry for a directory
5118 includes a list of all the files in the directory at the time the
5119 dump was done, and a flag for each file indicating whether the file
5120 is going to be put in the archive. This information is used when
5121 doing a complete incremental restore.
5122
5123 Note that this option causes @command{tar} to create a non-standard
5124 archive that may not be readable by non-@acronym{GNU} versions of the
5125 @command{tar} program.
5126
5127 The @value{op-incremental} option means the archive is an incremental
5128 backup. Its meaning depends on the command that it modifies.
5129
5130 If the @value{op-incremental} option is used with @value{op-list},
5131 @command{tar} will list, for each directory in the archive, the list
5132 of files in that directory at the time the archive was created. This
5133 information is put out in a format that is not easy for humans to
5134 read, but which is unambiguous for a program: each file name is
5135 preceded by either a @samp{Y} if the file is present in the archive,
5136 an @samp{N} if the file is not included in the archive, or a @samp{D}
5137 if the file is a directory (and is included in the archive). Each
5138 file name is terminated by a null character. The last file is
5139 followed by an additional null and a newline to indicate the end of
5140 the data.
5141
5142 If the @value{op-incremental} option is used with @value{op-extract}, then
5143 when the entry for a directory is found, all files that currently
5144 exist in that directory but are not listed in the archive @emph{are
5145 deleted from the directory}.
5146
5147 This behavior is convenient when you are restoring a damaged file
5148 system from a succession of incremental backups: it restores the
5149 entire state of the file system to that which obtained when the backup
5150 was made. If you don't use @value{op-incremental}, the file system will
5151 probably fill up with files that shouldn't exist any more.
5152
5153 @value{op-listed-incremental} handle new @acronym{GNU}-format
5154 incremental backup. This option handles new @acronym{GNU}-format
5155 incremental backup. It has much the same effect as
5156 @value{op-incremental}, but also the time when the dump is done and
5157 the list of directories dumped is written to the given
5158 @var{file}. When restoring, only files newer than the saved time are
5159 restored, and the directory list is used to speed up operations.
5160
5161 @value{op-listed-incremental} acts like @value{op-incremental}, but when
5162 used in conjunction with @value{op-create} will also cause @command{tar} to
5163 use the file @var{file}, which contains information about the state
5164 of the filesystem at the time of the last backup, to decide which
5165 files to include in the archive being created. That file will then
5166 be updated by @command{tar}. If the file @var{file} does not exist when
5167 this option is specified, @command{tar} will create it, and include all
5168 appropriate files in the archive.
5169
5170 The file, which is archive independent, contains the date it was last
5171 modified and a list of devices, inode numbers and directory names.
5172 @command{tar} will archive files with newer mod dates or inode change
5173 times, and directories with an unchanged inode number and device but
5174 a changed directory name. The file is updated after the files to
5175 be archived are determined, but before the new archive is actually
5176 created.
5177
5178 @node Inc Dumps
5179 @section Using @command{tar} to Perform Incremental Dumps
5180 @UNREVISED
5181
5182 @cindex incremental dumps
5183 @cindex dumps, incremental
5184
5185 Performing incremental dumps is similar to performing full dumps,
5186 although a few more options will usually be needed.
5187
5188 A standard scheme is to do a @emph{monthly} (full) dump once a month,
5189 a @emph{weekly} dump once a week of everything since the last monthly
5190 and a @emph{daily} every day of everything since the last (weekly or
5191 monthly) dump.
5192
5193 Here is a sample script to dump the directory hierarchies @samp{/usr}
5194 and @samp{/var}.
5195
5196 @smallexample
5197 #! /bin/sh
5198 tar --create \
5199 --blocking-factor=126 \
5200 --file=/dev/rmt/0 \
5201 --label="`hostname` /usr /var `date +%Y-%m-%d`" \
5202 --listed-incremental=/var/log/usr-var.snar \
5203 --verbose \
5204 /usr /var
5205 @end smallexample
5206
5207 This script uses the file @file{/var/log/usr-var.snar} as a snapshot to
5208 store information about the previous tar dump.
5209
5210 The blocking factor 126 is an attempt to make the tape drive stream.
5211 Some tape devices cannot handle 64 kB blocks or larger, and require the
5212 block size to be a multiple of 1 kB; for these devices, 126 is the
5213 largest blocking factor that can be used.
5214
5215 @node incremental and listed-incremental
5216 @section The Incremental Options
5217 @UNREVISED
5218
5219 @value{op-incremental} is used in conjunction with @value{op-create},
5220 @value{op-extract} or @value{op-list} when backing up and restoring file
5221 systems. An archive cannot be extracted or listed with the
5222 @value{op-incremental} option specified unless it was created with the
5223 option specified. This option should only be used by a script, not by
5224 the user, and is usually disregarded in favor of
5225 @value{op-listed-incremental}, which is described below.
5226
5227 @value{op-incremental} in conjunction with @value{op-create} causes
5228 @command{tar} to write, at the beginning of the archive, an entry for
5229 each of the directories that will be archived. The entry for a
5230 directory includes a list of all the files in the directory at the
5231 time the archive was created and a flag for each file indicating
5232 whether or not the file is going to be put in the archive.
5233
5234 Note that this option causes @command{tar} to create a non-standard
5235 archive that may not be readable by non-@acronym{GNU} versions of the
5236 @command{tar} program.
5237
5238 @value{op-incremental} in conjunction with @value{op-extract} causes
5239 @command{tar} to read the lists of directory contents previously stored
5240 in the archive, @emph{delete} files in the file system that did not
5241 exist in their directories when the archive was created, and then
5242 extract the files in the archive.
5243
5244 This behavior is convenient when restoring a damaged file system from
5245 a succession of incremental backups: it restores the entire state of
5246 the file system to that which obtained when the backup was made. If
5247 @value{op-incremental} isn't specified, the file system will probably
5248 fill up with files that shouldn't exist any more.
5249
5250 @value{op-incremental} in conjunction with @value{op-list} causes
5251 @command{tar} to print, for each directory in the archive, the list of
5252 files in that directory at the time the archive was created. This
5253 information is put out in a format that is not easy for humans to
5254 read, but which is unambiguous for a program: each file name is
5255 preceded by either a @samp{Y} if the file is present in the archive,
5256 an @samp{N} if the file is not included in the archive, or a @samp{D}
5257 if the file is a directory (and is included in the archive). Each
5258 file name is terminated by a null character. The last file is followed
5259 by an additional null and a newline to indicate the end of the data.
5260
5261 @value{op-listed-incremental} acts like @value{op-incremental}, but when
5262 used in conjunction with @value{op-create} will also cause @command{tar}
5263 to use the file @var{snapshot-file}, which contains information about
5264 the state of the file system at the time of the last backup, to decide
5265 which files to include in the archive being created. That file will
5266 then be updated by @command{tar}. If the file @var{file} does not exist
5267 when this option is specified, @command{tar} will create it, and include
5268 all appropriate files in the archive.
5269
5270 The file @var{file}, which is archive independent, contains the date
5271 it was last modified and a list of devices, inode numbers and
5272 directory names. @command{tar} will archive files with newer mod dates
5273 or inode change times, and directories with an unchanged inode number
5274 and device but a changed directory name. The file is updated after
5275 the files to be archived are determined, but before the new archive is
5276 actually created.
5277
5278 Incremental dumps depend crucially on time stamps, so the results are
5279 unreliable if you modify a file's time stamps during dumping (e.g.@:
5280 with the @samp{--atime-preserve} option), or if you set the clock
5281 backwards.
5282
5283 Despite it should be obvious that a device has a non-volatile value, NFS
5284 devices have non-dependable values when an automounter gets in the picture.
5285 This led to a great deal of spurious redumping in incremental dumps,
5286 so it is somewhat useless to compare two NFS devices numbers over time.
5287 So @command{tar} now considers all NFS devices as being equal when it comes
5288 to comparing directories; this is fairly gross, but there does not seem
5289 to be a better way to go.
5290
5291 @command{tar} doesn't access @var{snapshot-file} when
5292 @value{op-create} or @value{op-list} are specified, but the
5293 @value{op-listed-incremental} option must still be given. A
5294 placeholder @var{snapshot-file} can be specified, e.g.,
5295 @file{/dev/null}.
5296
5297 @FIXME{this section needs to be written}
5298
5299 @node Backup Levels
5300 @section Levels of Backups
5301
5302 An archive containing all the files in the file system is called a
5303 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5304 creating a full dump every day. This strategy, however, would waste a
5305 substantial amount of archive media and user time, as unchanged files
5306 are daily re-archived.
5307
5308 It is more efficient to do a full dump only occasionally. To back up
5309 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5310 one} dump archives all the files that have changed since the last full
5311 dump.
5312
5313 A typical dump strategy would be to perform a full dump once a week,
5314 and a level one dump once a day. This means some versions of files
5315 will in fact be archived more than once, but this dump strategy makes
5316 it possible to restore a file system to within one day of accuracy by
5317 only extracting two archives---the last weekly (full) dump and the
5318 last daily (level one) dump. The only information lost would be in
5319 files changed or created since the last daily backup. (Doing dumps
5320 more than once a day is usually not worth the trouble).
5321
5322 @GNUTAR{} comes with scripts you can use to do full
5323 and level-one (actually, even level-two and so on) dumps. Using
5324 scripts (shell programs) to perform backups and restoration is a
5325 convenient and reliable alternative to typing out file name lists
5326 and @command{tar} commands by hand.
5327
5328 Before you use these scripts, you need to edit the file
5329 @file{backup-specs}, which specifies parameters used by the backup
5330 scripts and by the restore script. This file is usually located
5331 in @file{/etc/backup} directory. @FIXME-xref{Script Syntax} Once the
5332 backup parameters are set, you can perform backups or restoration by
5333 running the appropriate script.
5334
5335 The name of the backup script is @code{backup}. The name of the
5336 restore script is @code{restore}. The following sections describe
5337 their use in detail.
5338
5339 @emph{Please Note:} The backup and restoration scripts are
5340 designed to be used together. While it is possible to restore files by
5341 hand from an archive which was created using a backup script, and to create
5342 an archive by hand which could then be extracted using the restore script,
5343 it is easier to use the scripts. @value{xref-incremental}, and
5344 @value{xref-listed-incremental}, before making such an attempt.
5345
5346 @node Backup Parameters
5347 @section Setting Parameters for Backups and Restoration
5348
5349 The file @file{backup-specs} specifies backup parameters for the
5350 backup and restoration scripts provided with @command{tar}. You must
5351 edit @file{backup-specs} to fit your system configuration and schedule
5352 before using these scripts.
5353
5354 Syntactically, @file{backup-specs} is a shell script, containing
5355 mainly variable assignments. However, any valid shell construct
5356 is allowed in this file. Particularly, you may wish to define
5357 functions within that script (e.g. see @code{RESTORE_BEGIN} below).
5358 For more information about shell script syntax, please refer to
5359 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5360 g_02, the definition of the Shell Command Language}. See also
5361 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5362
5363 The shell variables controlling behavior of @code{backup} and
5364 @code{restore} are described in the following subsections.
5365
5366 @menu
5367 * General-Purpose Variables::
5368 * Magnetic Tape Control::
5369 * User Hooks::
5370 * backup-specs example:: An Example Text of @file{Backup-specs}
5371 @end menu
5372
5373 @node General-Purpose Variables
5374 @subsection General-Purpose Variables
5375
5376 @defvr {Backup variable} ADMINISTRATOR
5377 The user name of the backup administrator. @code{Backup} scripts
5378 sends a backup report to this address.
5379 @end defvr
5380
5381 @defvr {Backup variable} BACKUP_HOUR
5382 The hour at which the backups are done. This can be a number from 0
5383 to 23, or the time specification in form @var{hours}:@var{minutes},
5384 or the string @samp{now}.
5385
5386 This variable is used by @code{backup}. Its value may be overridden
5387 using @option{--time} option (@pxref{Scripted Backups}).
5388 @end defvr
5389
5390 @defvr {Backup variable} TAPE_FILE
5391 The device @command{tar} writes the archive to. This device should be
5392 attached to the host on which the dump scripts are run.
5393 @end defvr
5394
5395 @defvr {Backup variable} BLOCKING
5396
5397 The blocking factor @command{tar} will use when writing the dump archive.
5398 @value{xref-blocking-factor}.
5399 @end defvr
5400
5401 @defvr {Backup variable} BACKUP_DIRS
5402
5403 A list of file systems to be dumped (for @code{backup}), or restored
5404 (for @code{restore}). You can include any directory
5405 name in the list --- subdirectories on that file system will be
5406 included, regardless of how they may look to other networked machines.
5407 Subdirectories on other file systems will be ignored.
5408
5409 The host name specifies which host to run @command{tar} on, and should
5410 normally be the host that actually contains the file system. However,
5411 the host machine must have @GNUTAR{} installed, and
5412 must be able to access the directory containing the backup scripts and
5413 their support files using the same file name that is used on the
5414 machine where the scripts are run (ie. what @command{pwd} will print
5415 when in that directory on that machine). If the host that contains
5416 the file system does not have this capability, you can specify another
5417 host as long as it can access the file system through NFS.
5418
5419 If the list of file systems is very long you may wish to put it
5420 in a separate file. This file is usually named
5421 @file{/etc/backup/dirs}, but this name may be overridden in
5422 @file{backup-specs} using @code{DIRLIST} variable.
5423 @end defvr
5424
5425 @defvr {Backup variable} DIRLIST
5426
5427 A path to the file containing the list of the filesystems to backup
5428 or restore. By default it is @file{/etc/backup/dirs}.
5429 @end defvr
5430
5431 @defvr {Backup variable} BACKUP_FILES
5432
5433 A list of individual files to be dumped (for @code{backup}), or restored
5434 (for @code{restore}). These should be accessible from the machine on
5435 which the backup script is run.
5436
5437 If the list of file systems is very long you may wish to store it
5438 in a separate file. This file is usually named
5439 @file{/etc/backup/files}, but this name may be overridden in
5440 @file{backup-specs} using @code{FILELIST} variable.
5441 @end defvr
5442
5443 @defvr {Backup variable} FILELIST
5444
5445 A path to the file containing the list of the individual files to backup
5446 or restore. By default it is @file{/etc/backup/files}.
5447 @end defvr
5448
5449 @defvr {Backup variable} RSH
5450
5451 Path to @code{rsh} binary or its equivalent. You may wish to
5452 set it to @code{ssh}, to improve security. In this case you will have
5453 to use public key authentication.
5454 @end defvr
5455
5456 @defvr {Backup variable} RSH_COMMAND
5457
5458 Path to rsh binary on remote mashines. This will be passed via
5459 @option{--rsh-command} option to the remote invocation of @GNUTAR{}.
5460 @end defvr
5461
5462 @defvr {Backup variable} VOLNO_FILE
5463
5464 Name of temporary file to hold volume numbers. This needs to be accessible
5465 by all the machines which have filesystems to be dumped.
5466 @end defvr
5467
5468 @defvr {Backup variable} XLIST
5469
5470 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5471 located on the remote machine and containing the list of files to
5472 be excluded from the backup. Exclude file lists are searched in
5473 /etc/tar-backup directory. A common use for exclude file lists
5474 is to exclude files containing security-sensitive information
5475 (e.g. @file{/etc/shadow} from backups).
5476
5477 This variable affects only @code{backup}.
5478 @end defvr
5479
5480 @defvr {Backup variable} SLEEP_TIME
5481
5482 Time to sleep between dumps of any two successive filesystems
5483
5484 This variable affects only @code{backup}.
5485 @end defvr
5486
5487 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5488
5489 Script to be run when it's time to insert a new tape in for the next
5490 volume. Administrators may want to tailor this script for their site.
5491 If this variable isn't set, @GNUTAR{} will display its built-in prompt
5492 @FIXME-xref{describe it somewhere!}, and will expect confirmation from
5493 the console.
5494 @end defvr
5495
5496 @defvr {Backup variable} SLEEP_MESSAGE
5497
5498 Message to display on the terminal while waiting for dump time. Usually
5499 this will just be some literal text.
5500 @end defvr
5501
5502 @defvr {Backup variable} TAR
5503
5504 Pathname of the @GNUTAR{} executable. If this is not set, backup
5505 scripts will search @command{tar} in the current shell path.
5506 @end defvr
5507
5508 @node Magnetic Tape Control
5509 @subsection Magnetic Tape Control
5510
5511 Backup scripts access tape device using special @dfn{hook functions}.
5512 These functions take a single argument -- the name of the tape
5513 device. Their names are kept in the following variables:
5514
5515 @defvr {Backup variable} MT_BEGIN
5516 The name of @dfn{begin} function. This function is called before
5517 accessing the drive. By default it retensions the tape:
5518
5519 @smallexample
5520 MT_BEGIN=mt_begin
5521
5522 mt_begin() @{
5523 mt -f "$1" retension
5524 @}
5525 @end smallexample
5526 @end defvr
5527
5528 @defvr {Backup variable} MT_REWIND
5529 The name of @dfn{rewind} function. The default definition is as
5530 follows:
5531
5532 @smallexample
5533 MT_REWIND=mt_rewind
5534
5535 mt_rewind() @{
5536 mt -f "$1" rewind
5537 @}
5538 @end smallexample
5539
5540 @end defvr
5541
5542 @defvr {Backup variable} MT_OFFLINE
5543 The name of the function switching the tape off line. By default
5544 it is defined as follows:
5545
5546 @smallexample
5547 MT_OFFLINE=mt_offline
5548
5549 mt_offline() @{
5550 mt -f "$1" offl
5551 @}
5552 @end smallexample
5553 @end defvr
5554
5555 @defvr {Backup variable} MT_STATUS
5556 The name of the function used to obtain the status of the archive device,
5557 including error count. Default definition:
5558
5559 @smallexample
5560 MT_STATUS=mt_status
5561
5562 mt_status() @{
5563 mt -f "$1" status
5564 @}
5565 @end smallexample
5566 @end defvr
5567
5568 @node User Hooks
5569 @subsection User Hooks
5570
5571 @dfn{User hooks} are shell functions executed before and after
5572 each @command{tar} invocation. Thus, there are @dfn{backup
5573 hooks}, which are executed before and after dumping each file
5574 system, and @dfn{restore hooks}, executed before and
5575 after restoring a file system. Each user hook is a shell function
5576 taking four arguments:
5577
5578 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5579 Its arguments are:
5580
5581 @table @var
5582 @item level
5583 Current backup or restore level.
5584
5585 @item host
5586 Name or IP address of the host machine being dumped or restored.
5587
5588 @item fs
5589 Full path name to the filesystem being dumped or restored.
5590
5591 @item fsname
5592 Filesystem name with directory separators replaced with colons. This
5593 is useful e.g. for creating unique files.
5594 @end table
5595 @end deffn
5596
5597 Following variables keep the names of user hook functions
5598
5599 @defvr {Backup variable} DUMP_BEGIN
5600 Dump begin function. It is executed before dumping the filesystem.
5601 @end defvr
5602
5603 @defvr {Backup variable} DUMP_END
5604 Executed after dumping the filesystem.
5605 @end defvr
5606
5607 @defvr {Backup variable} RESTORE_BEGIN
5608 Executed before restoring the filesystem.
5609 @end defvr
5610
5611 @defvr {Backup variable} RESTORE_END
5612 Executed after restoring the filesystem.
5613 @end defvr
5614
5615 @node backup-specs example
5616 @subsection An Example Text of @file{Backup-specs}
5617
5618 The following is an example of @file{backup-specs}:
5619
5620 @smallexample
5621 # site-specific parameters for file system backup.
5622
5623 ADMINISTRATOR=friedman
5624 BACKUP_HOUR=1
5625 TAPE_FILE=/dev/nrsmt0
5626
5627 # Use @code{ssh} instead of the less secure @code{rsh}
5628 RSH=/usr/bin/ssh
5629 RSH_COMMAND=/usr/bin/ssh
5630
5631 # Override MT_STATUS function:
5632 my_status() @{
5633 mts -t $TAPE_FILE
5634 @}
5635 MT_STATUS=my_status
5636
5637 # Disable MT_OFFLINE function
5638 MT_OFFLINE=:
5639
5640 BLOCKING=124
5641 BACKUP_DIRS="
5642 albert:/fs/fsf
5643 apple-gunkies:/gd
5644 albert:/fs/gd2
5645 albert:/fs/gp
5646 geech:/usr/jla
5647 churchy:/usr/roland
5648 albert:/
5649 albert:/usr
5650 apple-gunkies:/
5651 apple-gunkies:/usr
5652 gnu:/hack
5653 gnu:/u
5654 apple-gunkies:/com/mailer/gnu
5655 apple-gunkies:/com/archive/gnu"
5656
5657 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5658
5659 @end smallexample
5660
5661 @node Scripted Backups
5662 @section Using the Backup Scripts
5663
5664 The syntax for running a backup script is:
5665
5666 @smallexample
5667 backup --level=@var{level} --time=@var{time}
5668 @end smallexample
5669
5670 The @option{level} option requests the dump level. Thus, to produce
5671 a full dump, specify @code{--level=0} (this is the default, so
5672 @option{--level} may be omitted if its value is @code{0}).
5673 @footnote{For backward compatibility, the @code{backup} will also
5674 try to deduce the requested dump level from the name of the
5675 script itself. If the name consists of a string @samp{level-}
5676 followed by a single decimal digit, that digit is taken as
5677 the dump level number. Thus, you may create a link from @code{backup}
5678 to @code{level-1} and then run @code{level-1} whenever you need to
5679 create a level one dump.}
5680
5681 The @option{--time} option determines when should the backup be
5682 run. @var{Time} may take three forms:
5683
5684 @table @asis
5685 @item @var{hh}:@var{mm}
5686
5687 The dump must be run at @var{hh} hours @var{mm} minutes.
5688
5689 @item @var{hh}
5690
5691 The dump must be run at @var{hh} hours
5692
5693 @item now
5694
5695 The dump must be run immediately.
5696 @end table
5697
5698 You should start a script with a tape or disk mounted. Once you
5699 start a script, it prompts you for new tapes or disks as it
5700 needs them. Media volumes don't have to correspond to archive
5701 files --- a multi-volume archive can be started in the middle of a
5702 tape that already contains the end of another multi-volume archive.
5703 The @code{restore} script prompts for media by its archive volume,
5704 so to avoid an error message you should keep track of which tape
5705 (or disk) contains which volume of the archive (@pxref{Scripted
5706 Restoration}).
5707
5708 The backup scripts write two files on the file system. The first is a
5709 record file in @file{/etc/tar-backup/}, which is used by the scripts
5710 to store and retrieve information about which files were dumped. This
5711 file is not meant to be read by humans, and should not be deleted by
5712 them. @FIXME-xref{incremental and listed-incremental, for a more
5713 detailed explanation of this file.}
5714
5715 The second file is a log file containing the names of the file systems
5716 and files dumped, what time the backup was made, and any error
5717 messages that were generated, as well as how much space was left in
5718 the media volume after the last volume of the archive was written.
5719 You should check this log file after every backup. The file name is
5720 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5721 represents current date, and @var{n} represents current dump level number.
5722
5723 The script also prints the name of each system being dumped to the
5724 standard output.
5725
5726 Following is the full list of options accepted by @code{backup}
5727 script:
5728
5729 @table @option
5730 @item -l @var{level}
5731 @itemx --level=@var{level}
5732 Do backup level @var{level} (default 0).
5733
5734 @item -f
5735 @itemx --force
5736 Force backup even if today's log file already exists.
5737
5738 @item -v[@var{level}]
5739 @itemx --verbose[=@var{level}]
5740 Set verbosity level. The higher the level is, the more debugging
5741 information will be output during execution. Devault @var{level}
5742 is 100, which means the highest debugging level.
5743
5744 @item -t @var{start-time}
5745 @itemx --time=@var{start-time}
5746 Wait till @var{time}, then do backup.
5747
5748 @item -h
5749 @itemx --help
5750 Display short help message and exit.
5751
5752 @item -L
5753 @itemx --license
5754 Display program license and exit.
5755
5756 @item -V
5757 @itemx --version
5758 Display program version and exit.
5759 @end table
5760
5761
5762 @node Scripted Restoration
5763 @section Using the Restore Script
5764
5765 To restore files that were archived using a scripted backup, use the
5766 @code{restore} script. Its usage is quite straightforward. In the
5767 simplest form, invoke @code{restore --all}, it will
5768 then restore all the filesystems and files specified in
5769 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5770
5771 You may select the filesystems (and/or files) to restore by
5772 giving @code{restore} list of @dfn{patterns} in its command
5773 line. For example, running
5774
5775 @smallexample
5776 restore 'albert:*'
5777 @end smallexample
5778
5779 @noindent
5780 will restore all filesystems on the machine @samp{albert}. A more
5781 complicated example:
5782
5783 @smallexample
5784 restore 'albert:*' '*:/var'
5785 @end smallexample
5786
5787 @noindent
5788 This command will restore all filesystems on the machine @samp{albert}
5789 as well as @file{/var} filesystem on all machines.
5790
5791 By default @code{restore} will start restoring files from the lowest
5792 available dump level (usually zero) and will continue through
5793 all available dump levels. There may be situations where such a
5794 thorough restore is not necessary. For example, you may wish to
5795 restore only files from the recent level one backup. To do so,
5796 use @option{--level} option, as shown in the example below:
5797
5798 @smallexample
5799 restore --level=1
5800 @end smallexample
5801
5802 The full list of options accepted by @code{restore} follows:
5803
5804 @table @option
5805 @item -a
5806 @itemx --all
5807 Restore all filesystems and files specified in @file{backup-specs}
5808
5809 @item -l @var{level}
5810 @itemx --level=@var{level}
5811 Start restoring from the given backup level, instead of the default 0.
5812
5813 @item -v[@var{level}]
5814 @itemx --verbose[=@var{level}]
5815 Set verbosity level. The higher the level is, the more debugging
5816 information will be output during execution. Devault @var{level}
5817 is 100, which means the highest debugging level.
5818
5819 @item -h
5820 @itemx --help
5821 Display short help message and exit.
5822
5823 @item -L
5824 @itemx --license
5825 Display program license and exit.
5826
5827 @item -V
5828 @itemx --version
5829 Display program version and exit.
5830 @end table
5831
5832 You should start the restore script with the media containing the
5833 first volume of the archive mounted. The script will prompt for other
5834 volumes as they are needed. If the archive is on tape, you don't need
5835 to rewind the tape to to its beginning---if the tape head is
5836 positioned past the beginning of the archive, the script will rewind
5837 the tape as needed. @FIXME-xref{Media, for a discussion of tape
5838 positioning.}
5839
5840 @quotation
5841 @strong{Warning:} The script will delete files from the active file
5842 system if they were not in the file system when the archive was made.
5843 @end quotation
5844
5845 @value{xref-incremental}, and @value{ref-listed-incremental},
5846 for an explanation of how the script makes that determination.
5847
5848 @node Choosing
5849 @chapter Choosing Files and Names for @command{tar}
5850 @UNREVISED
5851
5852 @FIXME{Melissa (still) Doesn't Really Like This ``Intro'' Paragraph!!!}
5853
5854 Certain options to @command{tar} enable you to specify a name for your
5855 archive. Other options let you decide which files to include or exclude
5856 from the archive, based on when or whether files were modified, whether
5857 the file names do or don't match specified patterns, or whether files
5858 are in specified directories.
5859
5860 @menu
5861 * file:: Choosing the Archive's Name
5862 * Selecting Archive Members::
5863 * files:: Reading Names from a File
5864 * exclude:: Excluding Some Files
5865 * Wildcards::
5866 * after:: Operating Only on New Files
5867 * recurse:: Descending into Directories
5868 * one:: Crossing Filesystem Boundaries
5869 @end menu
5870
5871 @node file
5872 @section Choosing and Naming Archive Files
5873 @cindex Naming an archive
5874 @cindex Archive Name
5875 @cindex Directing output
5876 @cindex Choosing an archive file
5877 @cindex Where is the archive?
5878 @UNREVISED
5879
5880 @FIXME{should the title of this section actually be, "naming an
5881 archive"?}
5882
5883 By default, @command{tar} uses an archive file name that was compiled when
5884 it was built on the system; usually this name refers to some physical
5885 tape drive on the machine. However, the person who installed @command{tar}
5886 on the system may not set the default to a meaningful value as far as
5887 most users are concerned. As a result, you will usually want to tell
5888 @command{tar} where to find (or create) the archive. The @value{op-file}
5889 option allows you to either specify or name a file to use as the archive
5890 instead of the default archive file location.
5891
5892 @table @kbd
5893 @item --file=@var{archive-name}
5894 @itemx -f @var{archive-name}
5895 Name the archive to create or operate on. Use in conjunction with
5896 any operation.
5897 @end table
5898
5899 For example, in this @command{tar} command,
5900
5901 @smallexample
5902 $ @kbd{tar -cvf collection.tar blues folk jazz}
5903 @end smallexample
5904
5905 @noindent
5906 @file{collection.tar} is the name of the archive. It must directly
5907 follow the @samp{-f} option, since whatever directly follows @samp{-f}
5908 @emph{will} end up naming the archive. If you neglect to specify an
5909 archive name, you may end up overwriting a file in the working directory
5910 with the archive you create since @command{tar} will use this file's name
5911 for the archive name.
5912
5913 An archive can be saved as a file in the file system, sent through a
5914 pipe or over a network, or written to an I/O device such as a tape,
5915 floppy disk, or CD write drive.
5916
5917 @cindex Writing new archives
5918 @cindex Archive creation
5919 If you do not name the archive, @command{tar} uses the value of the
5920 environment variable @env{TAPE} as the file name for the archive. If
5921 that is not available, @command{tar} uses a default, compiled-in archive
5922 name, usually that for tape unit zero (ie. @file{/dev/tu00}).
5923 @command{tar} always needs an archive name.
5924
5925 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
5926 archive from standard input (when listing or extracting files), or
5927 writes it to standard output (when creating an archive). If you use
5928 @file{-} as an @var{archive-name} when modifying an archive,
5929 @command{tar} reads the original archive from its standard input and
5930 writes the entire new archive to its standard output.
5931
5932 @FIXME{might want a different example here; this is already used in
5933 "notable tar usages".}
5934
5935 @smallexample
5936 $ @kbd{cd sourcedir; tar -cf - . | (cd targetdir; tar -xf -)}
5937 @end smallexample
5938
5939 @FIXME{help!}
5940
5941 @cindex Standard input and output
5942 @cindex tar to standard input and output
5943 To specify an archive file on a device attached to a remote machine,
5944 use the following:
5945
5946 @smallexample
5947 @kbd{--file=@var{hostname}:/@var{dev}/@var{file name}}
5948 @end smallexample
5949
5950 @noindent
5951 @command{tar} will complete the remote connection, if possible, and
5952 prompt you for a username and password. If you use
5953 @samp{--file=@@@var{hostname}:/@var{dev}/@var{file name}}, @command{tar}
5954 will complete the remote connection, if possible, using your username
5955 as the username on the remote machine.
5956
5957 If the archive file name includes a colon (@samp{:}), then it is assumed
5958 to be a file on another machine. If the archive file is
5959 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
5960 host @var{host}. The remote host is accessed using the @command{rsh}
5961 program, with a username of @var{user}. If the username is omitted
5962 (along with the @samp{@@} sign), then your user name will be used.
5963 (This is the normal @command{rsh} behavior.) It is necessary for the
5964 remote machine, in addition to permitting your @command{rsh} access, to
5965 have the @file{rmt} program installed (This command is included in
5966 the @GNUTAR{} distribution and by default is installed under
5967 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
5968 installation prefix). If you need to use a file whose name includes a
5969 colon, then the remote tape drive behavior
5970 can be inhibited by using the @value{op-force-local} option.
5971
5972 @FIXME{i know we went over this yesterday, but bob (and now i do again,
5973 too) thinks it's out of the middle of nowhere. it doesn't seem to tie
5974 into what came before it well enough <<i moved it now, is it better
5975 here?>>. bob also comments that if Amanda isn't free software, we
5976 shouldn't mention it..}
5977
5978 When the archive is being created to @file{/dev/null}, @GNUTAR{}
5979 tries to minimize input and output operations. The
5980 Amanda backup system, when used with @GNUTAR{}, has
5981 an initial sizing pass which uses this feature.
5982
5983 @node Selecting Archive Members
5984 @section Selecting Archive Members
5985 @cindex Specifying files to act on
5986 @cindex Specifying archive members
5987
5988 @dfn{File Name arguments} specify which files in the file system
5989 @command{tar} operates on, when creating or adding to an archive, or which
5990 archive members @command{tar} operates on, when reading or deleting from
5991 an archive. @xref{Operations}.
5992
5993 To specify file names, you can include them as the last arguments on
5994 the command line, as follows:
5995 @smallexample
5996 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
5997 @end smallexample
5998
5999 If you specify a directory name as a file name argument, all the files
6000 in that directory are operated on by @command{tar}.
6001
6002 If you do not specify files when @command{tar} is invoked with
6003 @value{op-create}, @command{tar} operates on all the non-directory files in
6004 the working directory. If you specify either @value{op-list} or
6005 @value{op-extract}, @command{tar} operates on all the archive members in the
6006 archive. If you specify any operation other than one of these three,
6007 @command{tar} does nothing.
6008
6009 By default, @command{tar} takes file names from the command line. However,
6010 there are other ways to specify file or member names, or to modify the
6011 manner in which @command{tar} selects the files or members upon which to
6012 operate. @FIXME{add xref here}In general, these methods work both for
6013 specifying the names of files and archive members.
6014
6015 @node files
6016 @section Reading Names from a File
6017 @UNREVISED
6018
6019 @cindex Reading file names from a file
6020 @cindex Lists of file names
6021 @cindex File Name arguments, alternatives
6022 Instead of giving the names of files or archive members on the command
6023 line, you can put the names into a file, and then use the
6024 @value{op-files-from} option to @command{tar}. Give the name of the file
6025 which contains the list of files to include as the argument to
6026 @samp{--files-from}. In the list, the file names should be separated by
6027 newlines. You will frequently use this option when you have generated
6028 the list of files to archive with the @command{find} utility.
6029
6030 @table @kbd
6031 @item --files-from=@var{file name}
6032 @itemx -T @var{file name}
6033 Get names to extract or create from file @var{file name}.
6034 @end table
6035
6036 If you give a single dash as a file name for @samp{--files-from}, (i.e.,
6037 you specify either @samp{--files-from=-} or @samp{-T -}), then the file
6038 names are read from standard input.
6039
6040 Unless you are running @command{tar} with @samp{--create}, you can not use
6041 both @samp{--files-from=-} and @samp{--file=-} (@samp{-f -}) in the same
6042 command.
6043
6044 @FIXME{add bob's example, from his message on 2-10-97}
6045
6046 The following example shows how to use @command{find} to generate a list of
6047 files smaller than 400K in length and put that list into a file
6048 called @file{small-files}. You can then use the @samp{-T} option to
6049 @command{tar} to specify the files from that file, @file{small-files}, to
6050 create the archive @file{little.tgz}. (The @samp{-z} option to
6051 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6052 more information.)
6053
6054 @smallexample
6055 $ @kbd{find . -size -400 -print > small-files}
6056 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6057 @end smallexample
6058
6059 @noindent
6060 @FIXME{say more here to conclude the example/section?}
6061
6062 @menu
6063 * nul::
6064 @end menu
6065
6066 @node nul
6067 @subsection @kbd{NUL} Terminated File Names
6068
6069 @cindex File names, terminated by @kbd{NUL}
6070 @cindex @kbd{NUL} terminated file names
6071 The @value{op-null} option causes @value{op-files-from} to read file
6072 names terminated by a @code{NUL} instead of a newline, so files whose
6073 names contain newlines can be archived using @samp{--files-from}.
6074
6075 @table @kbd
6076 @item --null
6077 Only consider @kbd{NUL} terminated file names, instead of files that
6078 terminate in a newline.
6079 @end table
6080
6081 The @samp{--null} option is just like the one in @acronym{GNU}
6082 @command{xargs} and @command{cpio}, and is useful with the
6083 @samp{-print0} predicate of @acronym{GNU} @command{find}. In
6084 @command{tar}, @samp{--null} also causes @value{op-directory} options
6085 to be treated as file names to archive, in case there are any files
6086 out there called @file{-C}.
6087
6088 This example shows how to use @command{find} to generate a list of files
6089 larger than 800K in length and put that list into a file called
6090 @file{long-files}. The @samp{-print0} option to @command{find} just just
6091 like @samp{-print}, except that it separates files with a @kbd{NUL}
6092 rather than with a newline. You can then run @command{tar} with both the
6093 @samp{--null} and @samp{-T} options to specify that @command{tar} get the
6094 files from that file, @file{long-files}, to create the archive
6095 @file{big.tgz}. The @samp{--null} option to @command{tar} will cause
6096 @command{tar} to recognize the @kbd{NUL} separator between files.
6097
6098 @smallexample
6099 $ @kbd{find . -size +800 -print0 > long-files}
6100 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6101 @end smallexample
6102
6103 @FIXME{say anything else here to conclude the section?}
6104
6105 @node exclude
6106 @section Excluding Some Files
6107 @cindex File names, excluding files by
6108 @cindex Excluding files by name and pattern
6109 @cindex Excluding files by file system
6110 @UNREVISED
6111
6112 To avoid operating on files whose names match a particular pattern,
6113 use the @value{op-exclude} or @value{op-exclude-from} options.
6114
6115 @table @kbd
6116 @item --exclude=@var{pattern}
6117 Causes @command{tar} to ignore files that match the @var{pattern}.
6118 @end table
6119
6120 @findex exclude
6121 The @value{op-exclude} option prevents any file or member whose name
6122 matches the shell wildcard (@var{pattern}) from being operated on.
6123 For example, to create an archive with all the contents of the directory
6124 @file{src} except for files whose names end in @file{.o}, use the
6125 command @samp{tar -cf src.tar --exclude='*.o' src}.
6126
6127 You may give multiple @samp{--exclude} options.
6128
6129 @table @kbd
6130 @item --exclude-from=@var{file}
6131 @itemx -X @var{file}
6132 Causes @command{tar} to ignore files that match the patterns listed in
6133 @var{file}.
6134 @end table
6135
6136 @findex exclude-from
6137 Use the @samp{--exclude-from=@var{file-of-patterns}} option to read a
6138 list of patterns, one per line, from @var{file}; @command{tar} will
6139 ignore files matching those patterns. Thus if @command{tar} is
6140 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6141 single line @file{*.o}, no files whose names end in @file{.o} will be
6142 added to the archive.
6143
6144 @FIXME{do the exclude options files need to have stuff separated by
6145 newlines the same as the files-from option does?}
6146
6147 @menu
6148 * controlling pattern-patching with exclude::
6149 * problems with exclude::
6150 @end menu
6151
6152 @node controlling pattern-patching with exclude
6153 @unnumberedsubsec Controlling Pattern-Matching with the @code{exclude} Options
6154
6155 Normally, a pattern matches a name if an initial subsequence of the
6156 name's components matches the pattern, where @samp{*}, @samp{?}, and
6157 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6158 and wildcards can match @samp{/}.
6159
6160 Other than optionally stripping leading @samp{/} from names
6161 (@pxref{absolute}), patterns and names are used as-is. For
6162 example, trailing @samp{/} is not trimmed from a user-specified name
6163 before deciding whether to exclude it.
6164
6165 However, this matching procedure can be altered by the options listed
6166 below. These options accumulate. For example:
6167
6168 @smallexample
6169 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6170 @end smallexample
6171
6172 ignores case when excluding @samp{makefile}, but not when excluding
6173 @samp{readme}.
6174
6175 @table @option
6176 @item --anchored
6177 @itemx --no-anchored
6178 If anchored, a pattern must match an initial subsequence
6179 of the name's components. Otherwise, the pattern can match any
6180 subsequence. Default is @option{--no-anchored}.
6181
6182 @item --ignore-case
6183 @itemx --no-ignore-case
6184 When ignoring case, upper-case patterns match lower-case names and vice versa.
6185 When not ignoring case (the default), matching is case-sensitive.
6186
6187 @item --wildcards
6188 @itemx --no-wildcards
6189 When using wildcards (the default), @samp{*}, @samp{?}, and @samp{[...]}
6190 are the usual shell wildcards, and @samp{\} escapes wildcards.
6191 Otherwise, none of these characters are special, and patterns must match
6192 names literally.
6193
6194 @item --wildcards-match-slash
6195 @itemx --no-wildcards-match-slash
6196 When wildcards match slash (the default), a wildcard like @samp{*} in
6197 the pattern can match a @samp{/} in the name. Otherwise, @samp{/} is
6198 matched only by @samp{/}.
6199
6200 @end table
6201
6202 The @option{--recursion} and @option{--no-recursion} options
6203 (@pxref{recurse}) also affect how exclude patterns are interpreted. If
6204 recursion is in effect, a pattern excludes a name if it matches any of
6205 the name's parent directories.
6206
6207 @node problems with exclude
6208 @unnumberedsubsec Problems with Using the @code{exclude} Options
6209
6210 Some users find @samp{exclude} options confusing. Here are some common
6211 pitfalls:
6212
6213 @itemize @bullet
6214 @item
6215 The main operating mode of @command{tar} does not act on a path name
6216 explicitly listed on the command line if one of its file name
6217 components is excluded. In the example above, if
6218 you create an archive and exclude files that end with @samp{*.o}, but
6219 explicitly name the file @samp{dir.o/foo} after all the options have been
6220 listed, @samp{dir.o/foo} will be excluded from the archive.
6221
6222 @item
6223 You can sometimes confuse the meanings of @value{op-exclude} and
6224 @value{op-exclude-from}. Be careful: use @value{op-exclude} when files
6225 to be excluded are given as a pattern on the command line. Use
6226 @samp{--exclude-from=@var{file-of-patterns}} to introduce the name of a
6227 file which contains a list of patterns, one per line; each of these
6228 patterns can exclude zero, one, or many files.
6229
6230 @item
6231 When you use @value{op-exclude}, be sure to quote the @var{pattern}
6232 parameter, so @GNUTAR{} sees wildcard characters
6233 like @samp{*}. If you do not do this, the shell might expand the
6234 @samp{*} itself using files at hand, so @command{tar} might receive a
6235 list of files instead of one pattern, or none at all, making the
6236 command somewhat illegal. This might not correspond to what you want.
6237
6238 For example, write:
6239
6240 @smallexample
6241 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6242 @end smallexample
6243
6244 @noindent
6245 rather than:
6246
6247 @smallexample
6248 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6249 @end smallexample
6250
6251 @item
6252 You must use use shell syntax, or globbing, rather than @code{regexp}
6253 syntax, when using exclude options in @command{tar}. If you try to use
6254 @code{regexp} syntax to describe files to be excluded, your command
6255 might fail.
6256
6257 @item
6258 In earlier versions of @command{tar}, what is now the
6259 @samp{--exclude-from=@var{file-of-patterns}} option was called
6260 @samp{--exclude=@var{pattern}} instead. Now,
6261 @samp{--exclude=@var{pattern}} applies to patterns listed on the command
6262 line and @samp{--exclude-from=@var{file-of-patterns}} applies to
6263 patterns listed in a file.
6264
6265 @end itemize
6266
6267 @node Wildcards
6268 @section Wildcards Patterns and Matching
6269
6270 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6271 @samp{*} or @samp{?} for example, are replaced and expanded into all
6272 existing files matching the given pattern. However, @command{tar} often
6273 uses wildcard patterns for matching (or globbing) archive members instead
6274 of actual files in the filesystem. Wildcard patterns are also used for
6275 verifying volume labels of @command{tar} archives. This section has the
6276 purpose of explaining wildcard syntax for @command{tar}.
6277
6278 @FIXME{the next few paragraphs need work.}
6279
6280 A @var{pattern} should be written according to shell syntax, using wildcard
6281 characters to effect globbing. Most characters in the pattern stand
6282 for themselves in the matched string, and case is significant: @samp{a}
6283 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6284 pattern matches any single character in the matched string. The character
6285 @samp{*} in the pattern matches zero, one, or more single characters in
6286 the matched string. The character @samp{\} says to take the following
6287 character of the pattern @emph{literally}; it is useful when one needs to
6288 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6289
6290 The character @samp{[}, up to the matching @samp{]}, introduces a character
6291 class. A @dfn{character class} is a list of acceptable characters
6292 for the next single character of the matched string. For example,
6293 @samp{[abcde]} would match any of the first five letters of the alphabet.
6294 Note that within a character class, all of the ``special characters''
6295 listed above other than @samp{\} lose their special meaning; for example,
6296 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6297 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6298 the characters @samp{-} and @samp{]} must either come @emph{first} or
6299 @emph{last} in a character class.)
6300
6301 @cindex Excluding characters from a character class
6302 @cindex Character class, excluding characters from
6303 If the first character of the class after the opening @samp{[}
6304 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6305 Rather than listing character to match, it lists those characters which
6306 are @emph{forbidden} as the next single character of the matched string.
6307
6308 Other characters of the class stand for themselves. The special
6309 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6310 letters, is meant to represent all characters between @var{a} and
6311 @var{e}, inclusive.
6312
6313 @FIXME{need to add a sentence or so here to make this clear for those
6314 who don't have dan around.}
6315
6316 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6317 special for wildcard matches. However, if a pattern completely matches
6318 a directory prefix of a matched string, then it matches the full matched
6319 string: excluding a directory also excludes all the files beneath it.
6320
6321 @node after
6322 @section Operating Only on New Files
6323 @cindex Excluding file by age
6324 @cindex Modification time, excluding files by
6325 @cindex Age, excluding files by
6326 @UNREVISED
6327
6328 The @value{op-after-date} option causes @command{tar} to only work on files
6329 whose modification or inode-changed times are newer than the @var{date}
6330 given. If @var{date} starts with @samp{/} or @samp{.}, it is taken to
6331 be a file name; the last-modified time of that file is used as the date.
6332 If you use this option when creating or appending to an archive,
6333 the archive will only include new files. If you use @samp{--after-date}
6334 when extracting an archive, @command{tar} will only extract files newer
6335 than the @var{date} you specify.
6336
6337 If you only want @command{tar} to make the date comparison based on
6338 modification of the actual contents of the file (rather than inode
6339 changes), then use the @value{op-newer-mtime} option.
6340
6341 You may use these options with any operation. Note that these options
6342 differ from the @value{op-update} operation in that they allow you to
6343 specify a particular date against which @command{tar} can compare when
6344 deciding whether or not to archive the files.
6345
6346 @table @kbd
6347 @item --after-date=@var{date}
6348 @itemx --newer=@var{date}
6349 @itemx -N @var{date}
6350 Only store files newer than @var{date}.
6351
6352 Acts on files only if their modification or inode-changed times are
6353 later than @var{date}. Use in conjunction with any operation.
6354
6355 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
6356 name; the last-modified time of that file is used as the date.
6357
6358 @item --newer-mtime=@var{date}
6359 Acts like @value{op-after-date}, but only looks at modification times.
6360 @end table
6361
6362 These options limit @command{tar} to only operating on files which have
6363 been modified after the date specified. A file is considered to have
6364 changed if the contents have been modified, or if the owner,
6365 permissions, and so forth, have been changed. (For more information on
6366 how to specify a date, see @ref{Date input formats}; remember that the
6367 entire date argument must be quoted if it contains any spaces.)
6368
6369 Gurus would say that @value{op-after-date} tests both the @code{mtime}
6370 (time the contents of the file were last modified) and @code{ctime}
6371 (time the file's status was last changed: owner, permissions, etc)
6372 fields, while @value{op-newer-mtime} tests only @code{mtime} field.
6373
6374 To be precise, @value{op-after-date} checks @emph{both} @code{mtime} and
6375 @code{ctime} and processes the file if either one is more recent than
6376 @var{date}, while @value{op-newer-mtime} only checks @code{mtime} and
6377 disregards @code{ctime}. Neither uses @code{atime} (the last time the
6378 contents of the file were looked at).
6379
6380 Date specifiers can have embedded spaces. Because of this, you may need
6381 to quote date arguments to keep the shell from parsing them as separate
6382 arguments.
6383
6384 @FIXME{Need example of --newer-mtime with quoted argument.}
6385
6386 @quotation
6387 @strong{Please Note:} @value{op-after-date} and @value{op-newer-mtime}
6388 should not be used for incremental backups. Some files (such as those
6389 in renamed directories) are not selected properly by these options.
6390 @xref{incremental and listed-incremental}.
6391 @end quotation
6392
6393 @noindent
6394 @FIXME{which tells -- need to fill this in!}
6395
6396 @node recurse
6397 @section Descending into Directories
6398 @cindex Avoiding recursion in directories
6399 @cindex Descending directories, avoiding
6400 @cindex Directories, avoiding recursion
6401 @cindex Recursion in directories, avoiding
6402 @UNREVISED
6403
6404 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
6405
6406 @FIXME{show dan bob's comments, from 2-10-97}
6407
6408 Usually, @command{tar} will recursively explore all directories (either
6409 those given on the command line or through the @value{op-files-from}
6410 option) for the various files they contain. However, you may not always
6411 want @command{tar} to act this way.
6412
6413 The @value{op-no-recursion} option inhibits @command{tar}'s recursive descent
6414 into specified directories. If you specify @samp{--no-recursion}, you can
6415 use the @command{find} utility for hunting through levels of directories to
6416 construct a list of file names which you could then pass to @command{tar}.
6417 @command{find} allows you to be more selective when choosing which files to
6418 archive; see @ref{files} for more information on using @command{find} with
6419 @command{tar}, or look.
6420
6421 @table @kbd
6422 @item --no-recursion
6423 Prevents @command{tar} from recursively descending directories.
6424
6425 @item --recursion
6426 Requires @command{tar} to recursively descend directories.
6427 This is the default.
6428 @end table
6429
6430 When you use @samp{--no-recursion}, @GNUTAR{} grabs
6431 directory entries themselves, but does not descend on them
6432 recursively. Many people use @command{find} for locating files they
6433 want to back up, and since @command{tar} @emph{usually} recursively
6434 descends on directories, they have to use the @samp{@w{! -d}} option
6435 to @command{find} @FIXME{needs more explanation or a cite to another
6436 info file}as they usually do not want all the files in a directory.
6437 They then use the @value{op-files-from} option to archive the files
6438 located via @command{find}.
6439
6440 The problem when restoring files archived in this manner is that the
6441 directories themselves are not in the archive; so the
6442 @value{op-same-permissions} option does not affect them---while users
6443 might really like it to. Specifying @value{op-no-recursion} is a way to
6444 tell @command{tar} to grab only the directory entries given to it, adding
6445 no new files on its own.
6446
6447 The @value{op-no-recursion} option also applies when extracting: it
6448 causes @command{tar} to extract only the matched directory entries, not
6449 the files under those directories.
6450
6451 The @value{op-no-recursion} option also affects how exclude patterns
6452 are interpreted (@pxref{controlling pattern-patching with exclude}).
6453
6454 The @option{--no-recursion} and @option{--recursion} options apply to
6455 later options and operands, and can be overridden by later occurrences
6456 of @option{--no-recursion} and @option{--recursion}. For example:
6457
6458 @smallexample
6459 $ @kbd{tar -cf jams.tar --norecursion grape --recursion grape/concord}
6460 @end smallexample
6461
6462 @noindent
6463 creates an archive with one entry for @file{grape}, and the recursive
6464 contents of @file{grape/concord}, but no entries under @file{grape}
6465 other than @file{grape/concord}.
6466
6467 @node one
6468 @section Crossing Filesystem Boundaries
6469 @cindex File system boundaries, not crossing
6470 @UNREVISED
6471
6472 @command{tar} will normally automatically cross file system boundaries in
6473 order to archive files which are part of a directory tree. You can
6474 change this behavior by running @command{tar} and specifying
6475 @value{op-one-file-system}. This option only affects files that are
6476 archived because they are in a directory that is being archived;
6477 @command{tar} will still archive files explicitly named on the command line
6478 or through @value{op-files-from}, regardless of where they reside.
6479
6480 @table @kbd
6481 @item --one-file-system
6482 @itemx -l
6483 Prevents @command{tar} from crossing file system boundaries when
6484 archiving. Use in conjunction with any write operation.
6485 @end table
6486
6487 The @samp{--one-file-system} option causes @command{tar} to modify its
6488 normal behavior in archiving the contents of directories. If a file in
6489 a directory is not on the same filesystem as the directory itself, then
6490 @command{tar} will not archive that file. If the file is a directory
6491 itself, @command{tar} will not archive anything beneath it; in other words,
6492 @command{tar} will not cross mount points.
6493
6494 It is reported that using this option, the mount point is is archived,
6495 but nothing under it.
6496
6497 This option is useful for making full or incremental archival backups of
6498 a file system. If this option is used in conjunction with
6499 @value{op-verbose}, files that are excluded are mentioned by name on the
6500 standard error.
6501
6502 @menu
6503 * directory:: Changing Directory
6504 * absolute:: Absolute File Names
6505 @end menu
6506
6507 @node directory
6508 @subsection Changing the Working Directory
6509
6510 @FIXME{need to read over this node now for continuity; i've switched
6511 things around some.}
6512
6513 @cindex Changing directory mid-stream
6514 @cindex Directory, changing mid-stream
6515 @cindex Working directory, specifying
6516 @UNREVISED
6517
6518 To change the working directory in the middle of a list of file names,
6519 either on the command line or in a file specified using
6520 @value{op-files-from}, use @value{op-directory}. This will change the
6521 working directory to the directory @var{directory} after that point in
6522 the list.
6523
6524 @table @kbd
6525 @item --directory=@var{directory}
6526 @itemx -C @var{directory}
6527 Changes the working directory in the middle of a command line.
6528 @end table
6529
6530 For example,
6531
6532 @smallexample
6533 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
6534 @end smallexample
6535
6536 @noindent
6537 will place the files @file{grape} and @file{prune} from the current
6538 directory into the archive @file{jams.tar}, followed by the file
6539 @file{cherry} from the directory @file{food}. This option is especially
6540 useful when you have several widely separated files that you want to
6541 store in the same archive.
6542
6543 Note that the file @file{cherry} is recorded in the archive under the
6544 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
6545 archive will contain three files that all appear to have come from the
6546 same directory; if the archive is extracted with plain @samp{tar
6547 --extract}, all three files will be written in the current directory.
6548
6549 Contrast this with the command,
6550
6551 @smallexample
6552 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
6553 @end smallexample
6554
6555 @noindent
6556 which records the third file in the archive under the name
6557 @file{red/cherry} so that, if the archive is extracted using
6558 @samp{tar --extract}, the third file will be written in a subdirectory
6559 named @file{orange-colored}.
6560
6561 You can use the @samp{--directory} option to make the archive
6562 independent of the original name of the directory holding the files.
6563 The following command places the files @file{/etc/passwd},
6564 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
6565 @file{foo.tar}:
6566
6567 @smallexample
6568 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
6569 @end smallexample
6570
6571 @noindent
6572 However, the names of the archive members will be exactly what they were
6573 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
6574 They will not appear to be related by file name to the original
6575 directories where those files were located.
6576
6577 Note that @samp{--directory} options are interpreted consecutively. If
6578 @samp{--directory} specifies a relative file name, it is interpreted
6579 relative to the then current directory, which might not be the same as
6580 the original current working directory of @command{tar}, due to a previous
6581 @samp{--directory} option.
6582
6583 @FIXME{dan: does this mean that you *can* use the short option form, but
6584 you can *not* use the long option form with --files-from? or is this
6585 totally screwed?}
6586
6587 When using @samp{--files-from} (@pxref{files}), you can put @samp{-C}
6588 options in the file list. Unfortunately, you cannot put
6589 @samp{--directory} options in the file list. (This interpretation can
6590 be disabled by using the @value{op-null} option.)
6591
6592 @node absolute
6593 @subsection Absolute File Names
6594 @UNREVISED
6595
6596 @table @kbd
6597 @item -P
6598 @itemx --absolute-names
6599 Do not strip leading slashes from file names, and permit file names
6600 containing a @file{..} file name component.
6601 @end table
6602
6603 By default, @GNUTAR{} drops a leading @samp{/} on
6604 input or output, and complains about file names containing a @file{..}
6605 component. This option turns off this behavior.
6606
6607 When @command{tar} extracts archive members from an archive, it strips any
6608 leading slashes (@samp{/}) from the member name. This causes absolute
6609 member names in the archive to be treated as relative file names. This
6610 allows you to have such members extracted wherever you want, instead of
6611 being restricted to extracting the member in the exact directory named
6612 in the archive. For example, if the archive member has the name
6613 @file{/etc/passwd}, @command{tar} will extract it as if the name were
6614 really @file{etc/passwd}.
6615
6616 File names containing @file{..} can cause problems when extracting, so
6617 @command{tar} normally warns you about such files when creating an
6618 archive, and rejects attempts to extracts such files.
6619
6620 Other @command{tar} programs do not do this. As a result, if you
6621 create an archive whose member names start with a slash, they will be
6622 difficult for other people with a non-@GNUTAR{}
6623 program to use. Therefore, @GNUTAR{} also strips
6624 leading slashes from member names when putting members into the
6625 archive. For example, if you ask @command{tar} to add the file
6626 @file{/bin/ls} to an archive, it will do so, but the member name will
6627 be @file{bin/ls}.
6628
6629 If you use the @value{op-absolute-names} option, @command{tar} will do
6630 none of these transformations.
6631
6632 To archive or extract files relative to the root directory, specify
6633 the @value{op-absolute-names} option.
6634
6635 Normally, @command{tar} acts on files relative to the working
6636 directory---ignoring superior directory names when archiving, and
6637 ignoring leading slashes when extracting.
6638
6639 When you specify @value{op-absolute-names}, @command{tar} stores file names
6640 including all superior directory names, and preserves leading slashes.
6641 If you only invoked @command{tar} from the root directory you would never
6642 need the @value{op-absolute-names} option, but using this option may be
6643 more convenient than switching to root.
6644
6645 @FIXME{Should be an example in the tutorial/wizardry section using this
6646 to transfer files between systems.}
6647
6648 @FIXME{Is write access an issue?}
6649
6650 @table @kbd
6651 @item --absolute-names
6652 Preserves full file names (including superior directory names) when
6653 archiving files. Preserves leading slash when extracting files.
6654
6655 @end table
6656
6657 @FIXME{this is still horrible; need to talk with dan on monday.}
6658
6659 @command{tar} prints out a message about removing the @samp{/} from
6660 file names. This message appears once per @GNUTAR{}
6661 invocation. It represents something which ought to be told; ignoring
6662 what it means can cause very serious surprises, later.
6663
6664 Some people, nevertheless, do not want to see this message. Wanting to
6665 play really dangerously, one may of course redirect @command{tar} standard
6666 error to the sink. For example, under @command{sh}:
6667
6668 @smallexample
6669 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
6670 @end smallexample
6671
6672 @noindent
6673 Another solution, both nicer and simpler, would be to change to
6674 the @file{/} directory first, and then avoid absolute notation.
6675 For example:
6676
6677 @smallexample
6678 $ @kbd{(cd / && tar -c -f archive.tar home)}
6679 $ @kbd{tar -c -f archive.tar -C / home}
6680 @end smallexample
6681
6682 @include getdate.texi
6683
6684 @node Formats
6685 @chapter Controlling the Archive Format
6686
6687 Due to historical reasons, there are several formats of tar archives.
6688 All of them are based on the same principles, but have some subtle
6689 differences that often make them incompatible with each other.
6690
6691 GNU tar is able to create and handle archives in a variety of formats.
6692 The most frequently used formats are (in alphabetical order):
6693
6694 @table @asis
6695 @item gnu
6696 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
6697 from an early @acronym{POSIX} standard, adding some improvements such as
6698 sparse file handling and incremental archives. Unfortunately these
6699 features were implemented in a way incompatible with other archive
6700 formats.
6701
6702 Archives in @samp{gnu} format are able to hold pathnames of unlimited
6703 length.
6704
6705 @item oldgnu
6706 Format used by @GNUTAR{} of versions prior to 1.12.
6707
6708 @item v7
6709 Archive format, compatible with the V7 implementation of tar. This
6710 format imposes a number of limitations. The most important of them
6711 are:
6712
6713 @enumerate
6714 @item The maximum length of a file name is limited to 99 characters.
6715 @item The maximum length of a symbolic link is limited to 99 characters.
6716 @item It is impossible to store special files (block and character
6717 devices, fifos etc.)
6718 @item Maximum value of user or group ID is limited to 2097151 (7777777
6719 octal)
6720 @item V7 archives do not contain symbolic ownership information (user
6721 and group name of the file owner).
6722 @end enumerate
6723
6724 This format has traditionally been used by Automake when producing
6725 Makefiles. This practice will change in the future, in the meantime,
6726 however this means that projects containing filenames more than 99
6727 characters long will not be able to use @GNUTAR{} @value{VERSION} and
6728 Automake prior to 1.9.
6729
6730 @item ustar
6731 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
6732 symbolic ownership information. It is also able to store
6733 special files. However, it imposes several restrictions as well:
6734
6735 @enumerate
6736 @item The maximum length of a file name is limited to 256 characters,
6737 provided that the filename can be split at directory separator in
6738 two parts, first of them being at most 155 bytes long. So, in most
6739 cases the maximum file name length will be shorter than 256
6740 characters.
6741 @item The maximum length of a symbolic link name is limited to
6742 100 characters.
6743 @item Maximum size of a file the archive is able to accomodate
6744 is 8GB
6745 @item Maximum value of UID/GID is 2097151.
6746 @item Maximum number of bits in device major and minor numbers is 21.
6747 @end enumerate
6748
6749 @item star
6750 Format used by J@"org Schilling @command{star}
6751 implementation. @GNUTAR{} is able to read @samp{star} archives but
6752 currently does not produce them.
6753
6754 @item posix
6755 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
6756 most flexible and feature-rich format. It does not impose any
6757 restrictions on file sizes or filename lengths. This format is quite
6758 recent, so not all tar implementations are able to handle it properly.
6759 However, this format is designed in such a way that any tar
6760 implementation able to read @samp{ustar} archives will be able to read
6761 most @samp{posix} archives as well, with the only exception that any
6762 additional information (such as long file names etc.) will in such
6763 case be extracted as plain text files along with the files it refers to.
6764
6765 This archive format will be the default format for future versions
6766 of @GNUTAR{}.
6767
6768 @end table
6769
6770 The following table summarizes the limitations of each of these
6771 formats:
6772
6773 @multitable @columnfractions .10 .20 .20 .20 .20
6774 @item Format @tab UID @tab File Size @tab Path Name @tab Devn
6775 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
6776 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
6777 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
6778 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
6779 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
6780 @end multitable
6781
6782 The default format for @GNUTAR{} is defined at compilation
6783 time. You may check it by running @command{tar --help}, and examining
6784 the last lines of its output. Usually, @GNUTAR{} is configured
6785 to create archives in @samp{gnu} format, however, future version will
6786 switch to @samp{posix}.
6787
6788 @menu
6789 * Portability:: Making @command{tar} Archives More Portable
6790 * Compression:: Using Less Space through Compression
6791 * Attributes:: Handling File Attributes
6792 * Standard:: The Standard Format
6793 * Extensions:: @acronym{GNU} Extensions to the Archive Format
6794 * cpio:: Comparison of @command{tar} and @command{cpio}
6795 @end menu
6796
6797 @node Portability
6798 @section Making @command{tar} Archives More Portable
6799
6800 Creating a @command{tar} archive on a particular system that is meant to be
6801 useful later on many other machines and with other versions of @command{tar}
6802 is more challenging than you might think. @command{tar} archive formats
6803 have been evolving since the first versions of Unix. Many such formats
6804 are around, and are not always compatible with each other. This section
6805 discusses a few problems, and gives some advice about making @command{tar}
6806 archives more portable.
6807
6808 One golden rule is simplicity. For example, limit your @command{tar}
6809 archives to contain only regular files and directories, avoiding
6810 other kind of special files. Do not attempt to save sparse files or
6811 contiguous files as such. Let's discuss a few more problems, in turn.
6812
6813 @menu
6814 * Portable Names:: Portable Names
6815 * dereference:: Symbolic Links
6816 * old:: Old V7 Archives
6817 * ustar:: Ustar Archives
6818 * gnu:: GNU and old GNU format archives.
6819 * posix:: @acronym{POSIX} archives
6820 * Checksumming:: Checksumming Problems
6821 * Large or Negative Values:: Large files, negative time stamps, etc.
6822 @end menu
6823
6824 @node Portable Names
6825 @subsection Portable Names
6826
6827 Use portable file and member names. A name is portable if it contains
6828 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
6829 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
6830 contain @samp{/-}. Avoid deep directory nesting. For portability to
6831 old Unix hosts, limit your file name components to 14 characters or
6832 less.
6833
6834 If you intend to have your @command{tar} archives to be read under
6835 MSDOS, you should not rely on case distinction for file names, and you
6836 might use the @acronym{GNU} @command{doschk} program for helping you
6837 further diagnosing illegal MSDOS names, which are even more limited
6838 than System V's.
6839
6840 @node dereference
6841 @subsection Symbolic Links
6842 @cindex File names, using symbolic links
6843 @cindex Symbolic link as file name
6844
6845 Normally, when @command{tar} archives a symbolic link, it writes a
6846 block to the archive naming the target of the link. In that way, the
6847 @command{tar} archive is a faithful record of the filesystem contents.
6848 @value{op-dereference} is used with @value{op-create}, and causes
6849 @command{tar} to archive the files symbolic links point to, instead of
6850 the links themselves. When this option is used, when @command{tar}
6851 encounters a symbolic link, it will archive the linked-to file,
6852 instead of simply recording the presence of a symbolic link.
6853
6854 The name under which the file is stored in the file system is not
6855 recorded in the archive. To record both the symbolic link name and
6856 the file name in the system, archive the file under both names. If
6857 all links were recorded automatically by @command{tar}, an extracted file
6858 might be linked to a file name that no longer exists in the file
6859 system.
6860
6861 If a linked-to file is encountered again by @command{tar} while creating
6862 the same archive, an entire second copy of it will be stored. (This
6863 @emph{might} be considered a bug.)
6864
6865 So, for portable archives, do not archive symbolic links as such,
6866 and use @value{op-dereference}: many systems do not support
6867 symbolic links, and moreover, your distribution might be unusable if
6868 it contains unresolved symbolic links.
6869
6870 @node old
6871 @subsection Old V7 Archives
6872 @cindex Format, old style
6873 @cindex Old style format
6874 @cindex Old style archives
6875
6876 Certain old versions of @command{tar} cannot handle additional
6877 information recorded by newer @command{tar} programs. To create an
6878 archive in V7 format (not ANSI), which can be read by these old
6879 versions, specify the @value{op-format-v7} option in
6880 conjunction with the @value{op-create} (@command{tar} also
6881 accepts @samp{--portability} or @samp{op-old-archive} for this
6882 option). When you specify it,
6883 @command{tar} leaves out information about directories, pipes, fifos,
6884 contiguous files, and device files, and specifies file ownership by
6885 group and user IDs instead of group and user names.
6886
6887 When updating an archive, do not use @value{op-format-v7}
6888 unless the archive was created using this option.
6889
6890 In most cases, a @emph{new} format archive can be read by an @emph{old}
6891 @command{tar} program without serious trouble, so this option should
6892 seldom be needed. On the other hand, most modern @command{tar}s are
6893 able to read old format archives, so it might be safer for you to
6894 always use @value{op-format-v7} for your distributions.
6895
6896 @node ustar
6897 @subsection Ustar Archive Format
6898
6899 Archive format defined by @acronym{POSIX}.1-1988 specification is called
6900 @code{ustar}. Although it is more flexible than the V7 format, it
6901 still has many restrictions (@xref{Formats,ustar}, for the detailed
6902 description of @code{ustar} format). Along with V7 format,
6903 @code{ustar} format is a good choice for archives intended to be read
6904 with other implementations of @command{tar}.
6905
6906 To create archive in @code{ustar} format, use @value{op-format-ustar}
6907 option in conjunction with the @value{op-create}.
6908
6909 @node gnu
6910 @subsection @acronym{GNU} and old @GNUTAR{} format
6911
6912 @GNUTAR{} was based on an early draft of the
6913 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
6914 @command{tar}, such as the support for file names longer than 100
6915 characters, use portions of the @command{tar} header record which were
6916 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
6917 @acronym{POSIX} have allocated the same parts of the header record for
6918 other purposes. As a result, @GNUTAR{} format is
6919 incompatible with the current @acronym{POSIX} specification, and with
6920 @command{tar} programs that follow it.
6921
6922 In the majority of cases, @command{tar} will be configured to create
6923 this format by default. This will change in the future releases, since
6924 we plan to make @samp{posix} format the default.
6925
6926 To force creation a @GNUTAR{} archive, use option
6927 @value{op-format-gnu}.
6928
6929 Some @command{tar} options are currently basing on @GNUTAR{}
6930 format, and can therefore be used only with @samp{gnu}
6931 or @samp{oldgnu} archive formats. The list of such options follows:
6932
6933 @itemize @bullet
6934 @item @value{op-label}, when used with @value{op-create}.
6935 @item @value{op-incremental}
6936 @item @value{op-multi-volume}
6937 @end itemize
6938
6939 These options will be re-implemented for the @samp{posix} archive
6940 format in the future.
6941
6942 @node posix
6943 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
6944
6945 The version @value{VERSION} of @GNUTAR{} is able
6946 to read and create archives conforming to @acronym{POSIX.1-2001} standard.
6947
6948 A @acronym{POSIX} conformant archive will be created if @command{tar}
6949 was given @value{op-format-posix} option.
6950 Notice, that currently @acronym{GNU} extensions are not
6951 allowed with this format. Following is the list of options that
6952 cannot be used with @value{op-format-posix}:
6953
6954 @itemize @bullet
6955 @item @value{op-label}, when used with @value{op-create}.
6956 @item @value{op-incremental}
6957 @item @value{op-multi-volume}
6958 @end itemize
6959
6960 This restriction will disappear in the future versions.
6961
6962 @node Checksumming
6963 @subsection Checksumming Problems
6964
6965 SunOS and HP-UX @command{tar} fail to accept archives created using
6966 @GNUTAR{} and containing non-ASCII file names, that
6967 is, file names having characters with the eight bit set, because they
6968 use signed checksums, while @GNUTAR{} uses unsigned
6969 checksums while creating archives, as per @acronym{POSIX} standards. On
6970 reading, @GNUTAR{} computes both checksums and
6971 accept any. It is somewhat worrying that a lot of people may go
6972 around doing backup of their files using faulty (or at least
6973 non-standard) software, not learning about it until it's time to
6974 restore their missing files with an incompatible file extractor, or
6975 vice versa.
6976
6977 @GNUTAR{} compute checksums both ways, and accept
6978 any on read, so @acronym{GNU} tar can read Sun tapes even with their
6979 wrong checksums. @GNUTAR{} produces the standard
6980 checksum, however, raising incompatibilities with Sun. That is to
6981 say, @GNUTAR{} has not been modified to
6982 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
6983 I've been told that more recent Sun @command{tar} now read standard
6984 archives, so maybe Sun did a similar patch, after all?
6985
6986 The story seems to be that when Sun first imported @command{tar}
6987 sources on their system, they recompiled it without realizing that
6988 the checksums were computed differently, because of a change in
6989 the default signing of @code{char}'s in their compiler. So they
6990 started computing checksums wrongly. When they later realized their
6991 mistake, they merely decided to stay compatible with it, and with
6992 themselves afterwards. Presumably, but I do not really know, HP-UX
6993 has chosen that their @command{tar} archives to be compatible with Sun's.
6994 The current standards do not favor Sun @command{tar} format. In any
6995 case, it now falls on the shoulders of SunOS and HP-UX users to get
6996 a @command{tar} able to read the good archives they receive.
6997
6998 @node Large or Negative Values
6999 @subsection Large or Negative Values
7000 @cindex large values
7001 @cindex future time stamps
7002 @cindex negative time stamps
7003
7004 @acronym{POSIX} @command{tar} format uses fixed-sized unsigned octal strings
7005 to represent numeric values. User and group IDs and device major and
7006 minor numbers have unsigned 21-bit representations, and file sizes and
7007 times have unsigned 33-bit representations. @GNUTAR{}
7008 generates @acronym{POSIX} representations when possible, but for values
7009 outside the @acronym{POSIX} range it generates two's-complement base-256
7010 strings: uids, gids, and device numbers have signed 57-bit
7011 representations, and file sizes and times have signed 89-bit
7012 representations. These representations are an extension to @acronym{POSIX}
7013 @command{tar} format, so they are not universally portable.
7014
7015 The most common portability problems with out-of-range numeric values
7016 are large files and future or negative time stamps.
7017
7018 Portable archives should avoid members of 8 GB or larger, as @acronym{POSIX}
7019 @command{tar} format cannot represent them.
7020
7021 Portable archives should avoid time stamps from the future. @acronym{POSIX}
7022 @command{tar} format can represent time stamps in the range 1970-01-01
7023 00:00:00 through 2242-03-16 12:56:31 @sc{utc}. However, many current
7024 hosts use a signed 32-bit @code{time_t}, or internal time stamp format,
7025 and cannot represent time stamps after 2038-01-19 03:14:07 @sc{utc}; so
7026 portable archives must avoid these time stamps for many years to come.
7027
7028 Portable archives should also avoid time stamps before 1970. These time
7029 stamps are a common @acronym{POSIX} extension but their @code{time_t}
7030 representations are negative. Many traditional @command{tar}
7031 implementations generate a two's complement representation for negative
7032 time stamps that assumes a signed 32-bit @code{time_t}; hence they
7033 generate archives that are not portable to hosts with differing
7034 @code{time_t} representations. @GNUTAR{} recognizes this
7035 situation when it is run on host with a signed 32-bit @code{time_t}, but
7036 it issues a warning, as these time stamps are nonstandard and unportable.
7037
7038 @node Compression
7039 @section Using Less Space through Compression
7040
7041 @menu
7042 * gzip:: Creating and Reading Compressed Archives
7043 * sparse:: Archiving Sparse Files
7044 @end menu
7045
7046 @node gzip
7047 @subsection Creating and Reading Compressed Archives
7048 @cindex Compressed archives
7049 @cindex Storing archives in compressed format
7050 @UNREVISED
7051
7052 @table @kbd
7053 @item -z
7054 @itemx --gzip
7055 @itemx --ungzip
7056 Filter the archive through @command{gzip}.
7057 @end table
7058
7059 @FIXME{ach; these two bits orig from "compare" (?). where to put?} Some
7060 format parameters must be taken into consideration when modifying an
7061 archive.@FIXME{???} Compressed archives cannot be modified.
7062
7063 You can use @samp{--gzip} and @samp{--gunzip} on physical devices
7064 (tape drives, etc.) and remote files as well as on normal files; data
7065 to or from such devices or remote files is reblocked by another copy
7066 of the @command{tar} program to enforce the specified (or default) record
7067 size. The default compression parameters are used; if you need to
7068 override them, avoid the @value{op-gzip} option and run @command{gzip}
7069 explicitly. (Or set the @env{GZIP} environment variable.)
7070
7071 The @value{op-gzip} option does not work with the @value{op-multi-volume}
7072 option, or with the @value{op-update}, @value{op-append},
7073 @value{op-concatenate}, or @value{op-delete} operations.
7074
7075 It is not exact to say that @GNUTAR{} is to work in concert
7076 with @command{gzip} in a way similar to @command{zip}, say. Surely, it is
7077 possible that @command{tar} and @command{gzip} be done with a single call,
7078 like in:
7079
7080 @smallexample
7081 $ @kbd{tar cfz archive.tar.gz subdir}
7082 @end smallexample
7083
7084 @noindent
7085 to save all of @samp{subdir} into a @code{gzip}'ed archive. Later you
7086 can do:
7087
7088 @smallexample
7089 $ @kbd{tar xfz archive.tar.gz}
7090 @end smallexample
7091
7092 @noindent
7093 to explode and unpack.
7094
7095 The difference is that the whole archive is compressed. With
7096 @command{zip}, archive members are archived individually. @command{tar}'s
7097 method yields better compression. On the other hand, one can view the
7098 contents of a @command{zip} archive without having to decompress it. As
7099 for the @command{tar} and @command{gzip} tandem, you need to decompress the
7100 archive to see its contents. However, this may be done without needing
7101 disk space, by using pipes internally:
7102
7103 @smallexample
7104 $ @kbd{tar tfz archive.tar.gz}
7105 @end smallexample
7106
7107 @cindex corrupted archives
7108 About corrupted compressed archives: @command{gzip}'ed files have no
7109 redundancy, for maximum compression. The adaptive nature of the
7110 compression scheme means that the compression tables are implicitly
7111 spread all over the archive. If you lose a few blocks, the dynamic
7112 construction of the compression tables becomes unsynchronized, and there
7113 is little chance that you could recover later in the archive.
7114
7115 There are pending suggestions for having a per-volume or per-file
7116 compression in @GNUTAR{}. This would allow for viewing the
7117 contents without decompression, and for resynchronizing decompression at
7118 every volume or file, in case of corrupted archives. Doing so, we might
7119 lose some compressibility. But this would have make recovering easier.
7120 So, there are pros and cons. We'll see!
7121
7122 @table @kbd
7123 @item -j
7124 @itemx --bzip2
7125 Filter the archive through @code{bzip2}. Otherwise like @value{op-gzip}.
7126
7127 @item -Z
7128 @itemx --compress
7129 @itemx --uncompress
7130 Filter the archive through @command{compress}. Otherwise like
7131 @value{op-gzip}.
7132
7133 @item --use-compress-program=@var{prog}
7134 Filter through @var{prog} (must accept @samp{-d}).
7135 @end table
7136
7137 @value{op-compress} stores an archive in compressed format. This
7138 option is useful in saving time over networks and space in pipes, and
7139 when storage space is at a premium. @value{op-compress} causes
7140 @command{tar} to compress when writing the archive, or to uncompress when
7141 reading the archive.
7142
7143 To perform compression and uncompression on the archive, @command{tar}
7144 runs the @command{compress} utility. @command{tar} uses the default
7145 compression parameters; if you need to override them, avoid the
7146 @value{op-compress} option and run the @command{compress} utility
7147 explicitly. It is useful to be able to call the @command{compress}
7148 utility from within @command{tar} because the @command{compress} utility by
7149 itself cannot access remote tape drives.
7150
7151 The @value{op-compress} option will not work in conjunction with the
7152 @value{op-multi-volume} option or the @value{op-append}, @value{op-update}
7153 and @value{op-delete} operations. @xref{Operations}, for
7154 more information on these operations.
7155
7156 If there is no compress utility available, @command{tar} will report an error.
7157 @strong{Please note} that the @command{compress} program may be covered by
7158 a patent, and therefore we recommend you stop using it.
7159
7160 @value{op-bzip2} acts like @value{op-compress}, except that it uses
7161 the @code{bzip2} utility.
7162
7163 @table @kbd
7164 @item --compress
7165 @itemx --uncompress
7166 @itemx -z
7167 @itemx -Z
7168 When this option is specified, @command{tar} will compress (when
7169 writing an archive), or uncompress (when reading an archive). Used in
7170 conjunction with the @value{op-create}, @value{op-extract},
7171 @value{op-list} and @value{op-compare} operations.
7172 @end table
7173
7174 You can have archives be compressed by using the @value{op-gzip} option.
7175 This will arrange for @command{tar} to use the @command{gzip} program to be
7176 used to compress or uncompress the archive wren writing or reading it.
7177
7178 To use the older, obsolete, @command{compress} program, use the
7179 @value{op-compress} option. The @acronym{GNU} Project recommends you not use
7180 @command{compress}, because there is a patent covering the algorithm it
7181 uses. You could be sued for patent infringement merely by running
7182 @command{compress}.
7183
7184 @FIXME{I have one question, or maybe it's a suggestion if there isn't a way
7185 to do it now. I would like to use @value{op-gzip}, but I'd also like
7186 the output to be fed through a program like @acronym{GNU}
7187 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
7188 to use :-)), basically adding ECC protection on top of compression.
7189 It seems as if this should be quite easy to do, but I can't work out
7190 exactly how to go about it. Of course, I can pipe the standard output
7191 of @command{tar} through @command{ecc}, but then I lose (though I
7192 haven't started using it yet, I confess) the ability to have
7193 @command{tar} use @command{rmt} for it's I/O (I think).
7194
7195 I think the most straightforward thing would be to let me specify a
7196 general set of filters outboard of compression (preferably ordered,
7197 so the order can be automatically reversed on input operations, and
7198 with the options they require specifiable), but beggars shouldn't be
7199 choosers and anything you decide on would be fine with me.
7200
7201 By the way, I like @command{ecc} but if (as the comments say) it can't
7202 deal with loss of block sync, I'm tempted to throw some time at adding
7203 that capability. Supposing I were to actually do such a thing and
7204 get it (apparently) working, do you accept contributed changes to
7205 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
7206
7207 Isn't that exactly the role of the @value{op-use-compress-prog} option?
7208 I never tried it myself, but I suspect you may want to write a
7209 @var{prog} script or program able to filter stdin to stdout to
7210 way you want. It should recognize the @samp{-d} option, for when
7211 extraction is needed rather than creation.
7212
7213 It has been reported that if one writes compressed data (through the
7214 @value{op-gzip} or @value{op-compress} options) to a DLT and tries to use
7215 the DLT compression mode, the data will actually get bigger and one will
7216 end up with less space on the tape.}
7217
7218 @node sparse
7219 @subsection Archiving Sparse Files
7220 @cindex Sparse Files
7221 @UNREVISED
7222
7223 @table @kbd
7224 @item -S
7225 @itemx --sparse
7226 Handle sparse files efficiently.
7227 @end table
7228
7229 This option causes all files to be put in the archive to be tested for
7230 sparseness, and handled specially if they are. The @value{op-sparse}
7231 option is useful when many @code{dbm} files, for example, are being
7232 backed up. Using this option dramatically decreases the amount of
7233 space needed to store such a file.
7234
7235 In later versions, this option may be removed, and the testing and
7236 treatment of sparse files may be done automatically with any special
7237 @acronym{GNU} options. For now, it is an option needing to be specified on
7238 the command line with the creation or updating of an archive.
7239
7240 Files in the filesystem occasionally have ``holes.'' A hole in a file
7241 is a section of the file's contents which was never written. The
7242 contents of a hole read as all zeros. On many operating systems,
7243 actual disk storage is not allocated for holes, but they are counted
7244 in the length of the file. If you archive such a file, @command{tar}
7245 could create an archive longer than the original. To have @command{tar}
7246 attempt to recognize the holes in a file, use @value{op-sparse}. When
7247 you use the @value{op-sparse} option, then, for any file using less
7248 disk space than would be expected from its length, @command{tar} searches
7249 the file for consecutive stretches of zeros. It then records in the
7250 archive for the file where the consecutive stretches of zeros are, and
7251 only archives the ``real contents'' of the file. On extraction (using
7252 @value{op-sparse} is not needed on extraction) any such files have
7253 holes created wherever the continuous stretches of zeros were found.
7254 Thus, if you use @value{op-sparse}, @command{tar} archives won't take
7255 more space than the original.
7256
7257 A file is sparse if it contains blocks of zeros whose existence is
7258 recorded, but that have no space allocated on disk. When you specify
7259 the @value{op-sparse} option in conjunction with the @value{op-create}
7260 operation, @command{tar} tests all files for sparseness while archiving.
7261 If @command{tar} finds a file to be sparse, it uses a sparse representation of
7262 the file in the archive. @value{xref-create}, for more information
7263 about creating archives.
7264
7265 @value{op-sparse} is useful when archiving files, such as dbm files,
7266 likely to contain many nulls. This option dramatically
7267 decreases the amount of space needed to store such an archive.
7268
7269 @quotation
7270 @strong{Please Note:} Always use @value{op-sparse} when performing file
7271 system backups, to avoid archiving the expanded forms of files stored
7272 sparsely in the system.
7273
7274 Even if your system has no sparse files currently, some may be
7275 created in the future. If you use @value{op-sparse} while making file
7276 system backups as a matter of course, you can be assured the archive
7277 will never take more space on the media than the files take on disk
7278 (otherwise, archiving a disk filled with sparse files might take
7279 hundreds of tapes). @FIXME-xref{incremental when node name is set.}
7280 @end quotation
7281
7282 @command{tar} ignores the @value{op-sparse} option when reading an archive.
7283
7284 @table @kbd
7285 @item --sparse
7286 @itemx -S
7287 Files stored sparsely in the file system are represented sparsely in
7288 the archive. Use in conjunction with write operations.
7289 @end table
7290
7291 However, users should be well aware that at archive creation time,
7292 @GNUTAR{} still has to read whole disk file to
7293 locate the @dfn{holes}, and so, even if sparse files use little space
7294 on disk and in the archive, they may sometimes require inordinate
7295 amount of time for reading and examining all-zero blocks of a file.
7296 Although it works, it's painfully slow for a large (sparse) file, even
7297 though the resulting tar archive may be small. (One user reports that
7298 dumping a @file{core} file of over 400 megabytes, but with only about
7299 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
7300 ELC, with full CPU utilization.)
7301
7302 This reading is required in all cases and is not related to the fact
7303 the @value{op-sparse} option is used or not, so by merely @emph{not}
7304 using the option, you are not saving time@footnote{Well! We should say
7305 the whole truth, here. When @value{op-sparse} is selected while creating
7306 an archive, the current @command{tar} algorithm requires sparse files to be
7307 read twice, not once. We hope to develop a new archive format for saving
7308 sparse files in which one pass will be sufficient.}.
7309
7310 Programs like @command{dump} do not have to read the entire file; by
7311 examining the file system directly, they can determine in advance
7312 exactly where the holes are and thus avoid reading through them. The
7313 only data it need read are the actual allocated data blocks.
7314 @GNUTAR{} uses a more portable and straightforward
7315 archiving approach, it would be fairly difficult that it does
7316 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
7317 1990-12-10:
7318
7319 @quotation
7320 What I did say is that you cannot tell the difference between a hole and an
7321 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
7322 best tells you how many holes there are; it doesn't tell you @emph{where}.
7323 Just as programs may, conceivably, care what @code{st_blocks} is (care
7324 to name one that does?), they may also care where the holes are (I have
7325 no examples of this one either, but it's equally imaginable).
7326
7327 I conclude from this that good archivers are not portable. One can
7328 arguably conclude that if you want a portable program, you can in good
7329 conscience restore files with as many holes as possible, since you can't
7330 get it right.
7331 @end quotation
7332
7333 @node Attributes
7334 @section Handling File Attributes
7335 @UNREVISED
7336
7337 When @command{tar} reads files, this causes them to have the access
7338 times updated. To have @command{tar} attempt to set the access times
7339 back to what they were before they were read, use the
7340 @value{op-atime-preserve} option.
7341
7342 Handling of file attributes
7343
7344 @table @kbd
7345 @item --atime-preserve
7346 Preserve access times on files that are read.
7347 This doesn't work for files that
7348 you don't own, unless you're root, and it doesn't interact with
7349 incremental dumps nicely (@pxref{Backups}), and it can set access or
7350 modification times incorrectly if other programs access the file while
7351 @command{tar} is running; but it is good enough for some purposes.
7352
7353 @item -m
7354 @itemx --touch
7355 Do not extract file modified time.
7356
7357 When this option is used, @command{tar} leaves the modification times
7358 of the files it extracts as the time when the files were extracted,
7359 instead of setting it to the time recorded in the archive.
7360
7361 This option is meaningless with @value{op-list}.
7362
7363 @item --same-owner
7364 Create extracted files with the same ownership they have in the
7365 archive.
7366
7367 This is the default behavior for the superuser,
7368 so this option is meaningful only for non-root users, when @command{tar}
7369 is executed on those systems able to give files away. This is
7370 considered as a security flaw by many people, at least because it
7371 makes quite difficult to correctly account users for the disk space
7372 they occupy. Also, the @code{suid} or @code{sgid} attributes of
7373 files are easily and silently lost when files are given away.
7374
7375 When writing an archive, @command{tar} writes the user id and user name
7376 separately. If it can't find a user name (because the user id is not
7377 in @file{/etc/passwd}), then it does not write one. When restoring,
7378 and doing a @code{chmod} like when you use @value{op-same-permissions},
7379 @FIXME{same-owner?}it tries to look the name (if one was written)
7380 up in @file{/etc/passwd}. If it fails, then it uses the user id
7381 stored in the archive instead.
7382
7383 @item --no-same-owner
7384 @itemx -o
7385 Do not attempt to restore ownership when extracting. This is the
7386 default behavior for ordinary users, so this option has an effect
7387 only for the superuser.
7388
7389 @item --numeric-owner
7390 The @value{op-numeric-owner} option allows (ANSI) archives to be written
7391 without user/group name information or such information to be ignored
7392 when extracting. It effectively disables the generation and/or use
7393 of user/group name information. This option forces extraction using
7394 the numeric ids from the archive, ignoring the names.
7395
7396 This is useful in certain circumstances, when restoring a backup from
7397 an emergency floppy with different passwd/group files for example.
7398 It is otherwise impossible to extract files with the right ownerships
7399 if the password file in use during the extraction does not match the
7400 one belonging to the filesystem(s) being extracted. This occurs,
7401 for example, if you are restoring your files after a major crash and
7402 had booted from an emergency floppy with no password file or put your
7403 disk into another machine to do the restore.
7404
7405 The numeric ids are @emph{always} saved into @command{tar} archives.
7406 The identifying names are added at create time when provided by the
7407 system, unless @value{op-old-archive} is used. Numeric ids could be
7408 used when moving archives between a collection of machines using
7409 a centralized management for attribution of numeric ids to users
7410 and groups. This is often made through using the NIS capabilities.
7411
7412 When making a @command{tar} file for distribution to other sites, it
7413 is sometimes cleaner to use a single owner for all files in the
7414 distribution, and nicer to specify the write permission bits of the
7415 files as stored in the archive independently of their actual value on
7416 the file system. The way to prepare a clean distribution is usually
7417 to have some Makefile rule creating a directory, copying all needed
7418 files in that directory, then setting ownership and permissions as
7419 wanted (there are a lot of possible schemes), and only then making a
7420 @command{tar} archive out of this directory, before cleaning
7421 everything out. Of course, we could add a lot of options to
7422 @GNUTAR{} for fine tuning permissions and ownership.
7423 This is not the good way, I think. @GNUTAR{} is
7424 already crowded with options and moreover, the approach just explained
7425 gives you a great deal of control already.
7426
7427 @item -p
7428 @itemx --same-permissions
7429 @itemx --preserve-permissions
7430 Extract all protection information.
7431
7432 This option causes @command{tar} to set the modes (access permissions) of
7433 extracted files exactly as recorded in the archive. If this option
7434 is not used, the current @code{umask} setting limits the permissions
7435 on extracted files.
7436
7437 This option is meaningless with @value{op-list}.
7438
7439 @item --preserve
7440 Same as both @value{op-same-permissions} and @value{op-same-order}.
7441
7442 The @value{op-preserve} option has no equivalent short option name.
7443 It is equivalent to @value{op-same-permissions} plus @value{op-same-order}.
7444
7445 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)}
7446
7447 @end table
7448
7449 @node Standard
7450 @section Basic Tar Format
7451 @UNREVISED
7452
7453 While an archive may contain many files, the archive itself is a
7454 single ordinary file. Like any other file, an archive file can be
7455 written to a storage device such as a tape or disk, sent through a
7456 pipe or over a network, saved on the active file system, or even
7457 stored in another archive. An archive file is not easy to read or
7458 manipulate without using the @command{tar} utility or Tar mode in
7459 @acronym{GNU} Emacs.
7460
7461 Physically, an archive consists of a series of file entries terminated
7462 by an end-of-archive entry, which consists of two 512 blocks of zero
7463 bytes. A file
7464 entry usually describes one of the files in the archive (an
7465 @dfn{archive member}), and consists of a file header and the contents
7466 of the file. File headers contain file names and statistics, checksum
7467 information which @command{tar} uses to detect file corruption, and
7468 information about file types.
7469
7470 Archives are permitted to have more than one member with the same
7471 member name. One way this situation can occur is if more than one
7472 version of a file has been stored in the archive. For information
7473 about adding new versions of a file to an archive, see @ref{update}.
7474 @FIXME-xref{To learn more about having more than one archive member with the
7475 same name, see -backup node, when it's written.}
7476
7477 In addition to entries describing archive members, an archive may
7478 contain entries which @command{tar} itself uses to store information.
7479 @value{xref-label}, for an example of such an archive entry.
7480
7481 A @command{tar} archive file contains a series of blocks. Each block
7482 contains @code{BLOCKSIZE} bytes. Although this format may be thought
7483 of as being on magnetic tape, other media are often used.
7484
7485 Each file archived is represented by a header block which describes
7486 the file, followed by zero or more blocks which give the contents
7487 of the file. At the end of the archive file there are two 512-byte blocks
7488 filled with binary zeros as an end-of-file marker. A reasonable system
7489 should write such end-of-file marker at the end of an archive, but
7490 must not assume that such a block exists when reading an archive. In
7491 particular @GNUTAR{} always issues a warning if it does not encounter it.
7492
7493 The blocks may be @dfn{blocked} for physical I/O operations.
7494 Each record of @var{n} blocks (where @var{n} is set by the
7495 @value{op-blocking-factor} option to @command{tar}) is written with a single
7496 @w{@samp{write ()}} operation. On magnetic tapes, the result of
7497 such a write is a single record. When writing an archive,
7498 the last record of blocks should be written at the full size, with
7499 blocks after the zero block containing all zeros. When reading
7500 an archive, a reasonable system should properly handle an archive
7501 whose last record is shorter than the rest, or which contains garbage
7502 records after a zero block.
7503
7504 The header block is defined in C as follows. In the @GNUTAR{}
7505 distribution, this is part of file @file{src/tar.h}:
7506
7507 @smallexample
7508 @include header.texi
7509 @end smallexample
7510
7511 All characters in header blocks are represented by using 8-bit
7512 characters in the local variant of ASCII. Each field within the
7513 structure is contiguous; that is, there is no padding used within
7514 the structure. Each character on the archive medium is stored
7515 contiguously.
7516
7517 Bytes representing the contents of files (after the header block
7518 of each file) are not translated in any way and are not constrained
7519 to represent characters in any character set. The @command{tar} format
7520 does not distinguish text files from binary files, and no translation
7521 of file contents is performed.
7522
7523 The @code{name}, @code{linkname}, @code{magic}, @code{uname}, and
7524 @code{gname} are null-terminated character strings. All other fields
7525 are zero-filled octal numbers in ASCII. Each numeric field of width
7526 @var{w} contains @var{w} minus 1 digits, and a null.
7527
7528 The @code{name} field is the file name of the file, with directory names
7529 (if any) preceding the file name, separated by slashes.
7530
7531 @FIXME{how big a name before field overflows?}
7532
7533 The @code{mode} field provides nine bits specifying file permissions
7534 and three bits to specify the Set UID, Set GID, and Save Text
7535 (@dfn{sticky}) modes. Values for these bits are defined above.
7536 When special permissions are required to create a file with a given
7537 mode, and the user restoring files from the archive does not hold such
7538 permissions, the mode bit(s) specifying those special permissions
7539 are ignored. Modes which are not supported by the operating system
7540 restoring files from the archive will be ignored. Unsupported modes
7541 should be faked up when creating or updating an archive; e.g.@: the
7542 group permission could be copied from the @emph{other} permission.
7543
7544 The @code{uid} and @code{gid} fields are the numeric user and group
7545 ID of the file owners, respectively. If the operating system does
7546 not support numeric user or group IDs, these fields should be ignored.
7547
7548 The @code{size} field is the size of the file in bytes; linked files
7549 are archived with this field specified as zero. @FIXME-xref{Modifiers, in
7550 particular the @value{op-incremental} option.}
7551
7552 The @code{mtime} field is the modification time of the file at the time
7553 it was archived. It is the ASCII representation of the octal value of
7554 the last time the file was modified, represented as an integer number of
7555 seconds since January 1, 1970, 00:00 Coordinated Universal Time.
7556
7557 The @code{chksum} field is the ASCII representation of the octal value
7558 of the simple sum of all bytes in the header block. Each 8-bit
7559 byte in the header is added to an unsigned integer, initialized to
7560 zero, the precision of which shall be no less than seventeen bits.
7561 When calculating the checksum, the @code{chksum} field is treated as
7562 if it were all blanks.
7563
7564 The @code{typeflag} field specifies the type of file archived. If a
7565 particular implementation does not recognize or permit the specified
7566 type, the file will be extracted as if it were a regular file. As this
7567 action occurs, @command{tar} issues a warning to the standard error.
7568
7569 The @code{atime} and @code{ctime} fields are used in making incremental
7570 backups; they store, respectively, the particular file's access time
7571 and last inode-change time.
7572
7573 The @code{offset} is used by the @value{op-multi-volume} option, when
7574 making a multi-volume archive. The offset is number of bytes into
7575 the file that we need to restart at to continue the file on the next
7576 tape, i.e., where we store the location that a continued file is
7577 continued at.
7578
7579 The following fields were added to deal with sparse files. A file
7580 is @dfn{sparse} if it takes in unallocated blocks which end up being
7581 represented as zeros, i.e., no useful data. A test to see if a file
7582 is sparse is to look at the number blocks allocated for it versus the
7583 number of characters in the file; if there are fewer blocks allocated
7584 for the file than would normally be allocated for a file of that
7585 size, then the file is sparse. This is the method @command{tar} uses to
7586 detect a sparse file, and once such a file is detected, it is treated
7587 differently from non-sparse files.
7588
7589 Sparse files are often @code{dbm} files, or other database-type files
7590 which have data at some points and emptiness in the greater part of
7591 the file. Such files can appear to be very large when an @samp{ls
7592 -l} is done on them, when in truth, there may be a very small amount
7593 of important data contained in the file. It is thus undesirable
7594 to have @command{tar} think that it must back up this entire file, as
7595 great quantities of room are wasted on empty blocks, which can lead
7596 to running out of room on a tape far earlier than is necessary.
7597 Thus, sparse files are dealt with so that these empty blocks are
7598 not written to the tape. Instead, what is written to the tape is a
7599 description, of sorts, of the sparse file: where the holes are, how
7600 big the holes are, and how much data is found at the end of the hole.
7601 This way, the file takes up potentially far less room on the tape,
7602 and when the file is extracted later on, it will look exactly the way
7603 it looked beforehand. The following is a description of the fields
7604 used to handle a sparse file:
7605
7606 The @code{sp} is an array of @code{struct sparse}. Each @code{struct
7607 sparse} contains two 12-character strings which represent an offset
7608 into the file and a number of bytes to be written at that offset.
7609 The offset is absolute, and not relative to the offset in preceding
7610 array element.
7611
7612 The header can hold four of these @code{struct sparse} at the moment;
7613 if more are needed, they are not stored in the header.
7614
7615 The @code{isextended} flag is set when an @code{extended_header}
7616 is needed to deal with a file. Note that this means that this flag
7617 can only be set when dealing with a sparse file, and it is only set
7618 in the event that the description of the file will not fit in the
7619 allotted room for sparse structures in the header. In other words,
7620 an extended_header is needed.
7621
7622 The @code{extended_header} structure is used for sparse files which
7623 need more sparse structures than can fit in the header. The header can
7624 fit 4 such structures; if more are needed, the flag @code{isextended}
7625 gets set and the next block is an @code{extended_header}.
7626
7627 Each @code{extended_header} structure contains an array of 21
7628 sparse structures, along with a similar @code{isextended} flag
7629 that the header had. There can be an indeterminate number of such
7630 @code{extended_header}s to describe a sparse file.
7631
7632 @table @asis
7633
7634 @item @code{REGTYPE}
7635 @itemx @code{AREGTYPE}
7636 These flags represent a regular file. In order to be compatible
7637 with older versions of @command{tar}, a @code{typeflag} value of
7638 @code{AREGTYPE} should be silently recognized as a regular file.
7639 New archives should be created using @code{REGTYPE}. Also, for
7640 backward compatibility, @command{tar} treats a regular file whose name
7641 ends with a slash as a directory.
7642
7643 @item @code{LNKTYPE}
7644 This flag represents a file linked to another file, of any type,
7645 previously archived. Such files are identified in Unix by each
7646 file having the same device and inode number. The linked-to name is
7647 specified in the @code{linkname} field with a trailing null.
7648
7649 @item @code{SYMTYPE}
7650 This represents a symbolic link to another file. The linked-to name
7651 is specified in the @code{linkname} field with a trailing null.
7652
7653 @item @code{CHRTYPE}
7654 @itemx @code{BLKTYPE}
7655 These represent character special files and block special files
7656 respectively. In this case the @code{devmajor} and @code{devminor}
7657 fields will contain the major and minor device numbers respectively.
7658 Operating systems may map the device specifications to their own
7659 local specification, or may ignore the entry.
7660
7661 @item @code{DIRTYPE}
7662 This flag specifies a directory or sub-directory. The directory
7663 name in the @code{name} field should end with a slash. On systems where
7664 disk allocation is performed on a directory basis, the @code{size} field
7665 will contain the maximum number of bytes (which may be rounded to
7666 the nearest disk block allocation unit) which the directory may
7667 hold. A @code{size} field of zero indicates no such limiting. Systems
7668 which do not support limiting in this manner should ignore the
7669 @code{size} field.
7670
7671 @item @code{FIFOTYPE}
7672 This specifies a FIFO special file. Note that the archiving of a
7673 FIFO file archives the existence of this file and not its contents.
7674
7675 @item @code{CONTTYPE}
7676 This specifies a contiguous file, which is the same as a normal
7677 file except that, in operating systems which support it, all its
7678 space is allocated contiguously on the disk. Operating systems
7679 which do not allow contiguous allocation should silently treat this
7680 type as a normal file.
7681
7682 @item @code{A} @dots{} @code{Z}
7683 These are reserved for custom implementations. Some of these are
7684 used in the @acronym{GNU} modified format, as described below.
7685
7686 @end table
7687
7688 Other values are reserved for specification in future revisions of
7689 the P1003 standard, and should not be used by any @command{tar} program.
7690
7691 The @code{magic} field indicates that this archive was output in
7692 the P1003 archive format. If this field contains @code{TMAGIC},
7693 the @code{uname} and @code{gname} fields will contain the ASCII
7694 representation of the owner and group of the file respectively.
7695 If found, the user and group IDs are used rather than the values in
7696 the @code{uid} and @code{gid} fields.
7697
7698 For references, see ISO/IEC 9945-1:1990 or IEEE Std 1003.1-1990, pages
7699 169-173 (section 10.1) for @cite{Archive/Interchange File Format}; and
7700 IEEE Std 1003.2-1992, pages 380-388 (section 4.48) and pages 936-940
7701 (section E.4.48) for @cite{pax - Portable archive interchange}.
7702
7703 @node Extensions
7704 @section @acronym{GNU} Extensions to the Archive Format
7705 @UNREVISED
7706
7707 The @acronym{GNU} format uses additional file types to describe new types of
7708 files in an archive. These are listed below.
7709
7710 @table @code
7711 @item GNUTYPE_DUMPDIR
7712 @itemx 'D'
7713 This represents a directory and a list of files created by the
7714 @value{op-incremental} option. The @code{size} field gives the total
7715 size of the associated list of files. Each file name is preceded by
7716 either a @samp{Y} (the file should be in this archive) or an @samp{N}.
7717 (The file is a directory, or is not stored in the archive.) Each file
7718 name is terminated by a null. There is an additional null after the
7719 last file name.
7720
7721 @item GNUTYPE_MULTIVOL
7722 @itemx 'M'
7723 This represents a file continued from another volume of a multi-volume
7724 archive created with the @value{op-multi-volume} option. The original
7725 type of the file is not given here. The @code{size} field gives the
7726 maximum size of this piece of the file (assuming the volume does
7727 not end before the file is written out). The @code{offset} field
7728 gives the offset from the beginning of the file where this part of
7729 the file begins. Thus @code{size} plus @code{offset} should equal
7730 the original size of the file.
7731
7732 @item GNUTYPE_SPARSE
7733 @itemx 'S'
7734 This flag indicates that we are dealing with a sparse file. Note
7735 that archiving a sparse file requires special operations to find
7736 holes in the file, which mark the positions of these holes, along
7737 with the number of bytes of data to be found after the hole.
7738
7739 @item GNUTYPE_VOLHDR
7740 @itemx 'V'
7741 This file type is used to mark the volume header that was given with
7742 the @value{op-label} option when the archive was created. The @code{name}
7743 field contains the @code{name} given after the @value{op-label} option.
7744 The @code{size} field is zero. Only the first file in each volume
7745 of an archive should have this type.
7746
7747 @end table
7748
7749 You may have trouble reading a @acronym{GNU} format archive on a
7750 non-@acronym{GNU} system if the options @value{op-incremental},
7751 @value{op-multi-volume}, @value{op-sparse}, or @value{op-label} were
7752 used when writing the archive. In general, if @command{tar} does not
7753 use the @acronym{GNU}-added fields of the header, other versions of
7754 @command{tar} should be able to read the archive. Otherwise, the
7755 @command{tar} program will give an error, the most likely one being a
7756 checksum error.
7757
7758 @node cpio
7759 @section Comparison of @command{tar} and @command{cpio}
7760 @UNREVISED
7761
7762 @FIXME{Reorganize the following material}
7763
7764 The @command{cpio} archive formats, like @command{tar}, do have maximum
7765 pathname lengths. The binary and old ASCII formats have a max path
7766 length of 256, and the new ASCII and CRC ASCII formats have a max
7767 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
7768 with arbitrary pathname lengths, but other @command{cpio} implementations
7769 may crash unexplainedly trying to read them.
7770
7771 @command{tar} handles symbolic links in the form in which it comes in BSD;
7772 @command{cpio} doesn't handle symbolic links in the form in which it comes
7773 in System V prior to SVR4, and some vendors may have added symlinks
7774 to their system without enhancing @command{cpio} to know about them.
7775 Others may have enhanced it in a way other than the way I did it
7776 at Sun, and which was adopted by AT&T (and which is, I think, also
7777 present in the @command{cpio} that Berkeley picked up from AT&T and put
7778 into a later BSD release---I think I gave them my changes).
7779
7780 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
7781 can handle @command{tar} format input, and write it on output, and it
7782 probably handles symbolic links. They may not have bothered doing
7783 anything to enhance @command{tar} as a result.)
7784
7785 @command{cpio} handles special files; traditional @command{tar} doesn't.
7786
7787 @command{tar} comes with V7, System III, System V, and BSD source;
7788 @command{cpio} comes only with System III, System V, and later BSD
7789 (4.3-tahoe and later).
7790
7791 @command{tar}'s way of handling multiple hard links to a file can handle
7792 file systems that support 32-bit inumbers (e.g., the BSD file system);
7793 @command{cpio}s way requires you to play some games (in its "binary"
7794 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
7795 they're 18 bits---it would have to play games with the "file system ID"
7796 field of the header to make sure that the file system ID/i-number pairs
7797 of different files were always different), and I don't know which
7798 @command{cpio}s, if any, play those games. Those that don't might get
7799 confused and think two files are the same file when they're not, and
7800 make hard links between them.
7801
7802 @command{tar}s way of handling multiple hard links to a file places only
7803 one copy of the link on the tape, but the name attached to that copy
7804 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
7805 way puts one copy for every link, but you can retrieve it using any
7806 of the names.
7807
7808 @quotation
7809 What type of check sum (if any) is used, and how is this calculated.
7810 @end quotation
7811
7812 See the attached manual pages for @command{tar} and @command{cpio} format.
7813 @command{tar} uses a checksum which is the sum of all the bytes in the
7814 @command{tar} header for a file; @command{cpio} uses no checksum.
7815
7816 @quotation
7817 If anyone knows why @command{cpio} was made when @command{tar} was present
7818 at the unix scene,
7819 @end quotation
7820
7821 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
7822 generally-available version of UNIX had @command{tar} at the time. I don't
7823 know whether any version that was generally available @emph{within AT&T}
7824 had @command{tar}, or, if so, whether the people within AT&T who did
7825 @command{cpio} knew about it.
7826
7827 On restore, if there is a corruption on a tape @command{tar} will stop at
7828 that point, while @command{cpio} will skip over it and try to restore the
7829 rest of the files.
7830
7831 The main difference is just in the command syntax and header format.
7832
7833 @command{tar} is a little more tape-oriented in that everything is blocked
7834 to start on a record boundary.
7835
7836 @quotation
7837 Is there any differences between the ability to recover crashed
7838 archives between the two of them. (Is there any chance of recovering
7839 crashed archives at all.)
7840 @end quotation
7841
7842 Theoretically it should be easier under @command{tar} since the blocking
7843 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
7844 However, modern @command{cpio}'s and variations have an option to just
7845 search for the next file header after an error with a reasonable chance
7846 of resyncing. However, lots of tape driver software won't allow you to
7847 continue past a media error which should be the only reason for getting
7848 out of sync unless a file changed sizes while you were writing the
7849 archive.
7850
7851 @quotation
7852 If anyone knows why @command{cpio} was made when @command{tar} was present
7853 at the unix scene, please tell me about this too.
7854 @end quotation
7855
7856 Probably because it is more media efficient (by not blocking everything
7857 and using only the space needed for the headers where @command{tar}
7858 always uses 512 bytes per file header) and it knows how to archive
7859 special files.
7860
7861 You might want to look at the freely available alternatives. The
7862 major ones are @command{afio}, @GNUTAR{}, and
7863 @command{pax}, each of which have their own extensions with some
7864 backwards compatibility.
7865
7866 Sparse files were @command{tar}red as sparse files (which you can
7867 easily test, because the resulting archive gets smaller, and
7868 @acronym{GNU} @command{cpio} can no longer read it).
7869
7870 @node Media
7871 @chapter Tapes and Other Archive Media
7872 @UNREVISED
7873
7874 A few special cases about tape handling warrant more detailed
7875 description. These special cases are discussed below.
7876
7877 Many complexities surround the use of @command{tar} on tape drives. Since
7878 the creation and manipulation of archives located on magnetic tape was
7879 the original purpose of @command{tar}, it contains many features making
7880 such manipulation easier.
7881
7882 Archives are usually written on dismountable media---tape cartridges,
7883 mag tapes, or floppy disks.
7884
7885 The amount of data a tape or disk holds depends not only on its size,
7886 but also on how it is formatted. A 2400 foot long reel of mag tape
7887 holds 40 megabytes of data when formatted at 1600 bits per inch. The
7888 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
7889
7890 Magnetic media are re-usable---once the archive on a tape is no longer
7891 needed, the archive can be erased and the tape or disk used over.
7892 Media quality does deteriorate with use, however. Most tapes or disks
7893 should be discarded when they begin to produce data errors. EXABYTE
7894 tape cartridges should be discarded when they generate an @dfn{error
7895 count} (number of non-usable bits) of more than 10k.
7896
7897 Magnetic media are written and erased using magnetic fields, and
7898 should be protected from such fields to avoid damage to stored data.
7899 Sticking a floppy disk to a filing cabinet using a magnet is probably
7900 not a good idea.
7901
7902 @menu
7903 * Device:: Device selection and switching
7904 * Remote Tape Server::
7905 * Common Problems and Solutions::
7906 * Blocking:: Blocking
7907 * Many:: Many archives on one tape
7908 * Using Multiple Tapes:: Using Multiple Tapes
7909 * label:: Including a Label in the Archive
7910 * verify::
7911 * Write Protection::
7912 @end menu
7913
7914 @node Device
7915 @section Device Selection and Switching
7916 @UNREVISED
7917
7918 @table @kbd
7919 @item -f [@var{hostname}:]@var{file}
7920 @itemx --file=[@var{hostname}:]@var{file}
7921 Use archive file or device @var{file} on @var{hostname}.
7922 @end table
7923
7924 This option is used to specify the file name of the archive @command{tar}
7925 works on.
7926
7927 If the file name is @samp{-}, @command{tar} reads the archive from standard
7928 input (when listing or extracting), or writes it to standard output
7929 (when creating). If the @samp{-} file name is given when updating an
7930 archive, @command{tar} will read the original archive from its standard
7931 input, and will write the entire new archive to its standard output.
7932
7933 If the file name contains a @samp{:}, it is interpreted as
7934 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
7935 sign (@kbd{@@}), it is treated as @samp{user@@hostname:file name}. In
7936 either case, @command{tar} will invoke the command @command{rsh} (or
7937 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
7938 machine. If you give an alternate login name, it will be given to the
7939 @command{rsh}.
7940 Naturally, the remote machine must have an executable
7941 @command{/usr/libexec/rmt}. This program is free software from the
7942 University of California, and a copy of the source code can be found
7943 with the sources for @command{tar}; it's compiled and installed by default.
7944 The exact path to this utility is determined when configuring the package.
7945 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
7946 your installation prefix. This location may also be overridden at
7947 runtime by using @value{op-rmt-command} option (@xref{Option Summary,
7948 ---rmt-command}, for detailed description of this option. @xref{Remote
7949 Tape Server}, for the description of @command{rmt} command).
7950
7951 If this option is not given, but the environment variable @env{TAPE}
7952 is set, its value is used; otherwise, old versions of @command{tar}
7953 used a default archive name (which was picked when @command{tar} was
7954 compiled). The default is normally set up to be the @dfn{first} tape
7955 drive or other transportable I/O medium on the system.
7956
7957 Starting with version 1.11.5, @GNUTAR{} uses
7958 standard input and standard output as the default device, and I will
7959 not try anymore supporting automatic device detection at installation
7960 time. This was failing really in too many cases, it was hopeless.
7961 This is now completely left to the installer to override standard
7962 input and standard output for default device, if this seems
7963 preferable. Further, I think @emph{most} actual usages of
7964 @command{tar} are done with pipes or disks, not really tapes,
7965 cartridges or diskettes.
7966
7967 Some users think that using standard input and output is running
7968 after trouble. This could lead to a nasty surprise on your screen if
7969 you forget to specify an output file name---especially if you are going
7970 through a network or terminal server capable of buffering large amounts
7971 of output. We had so many bug reports in that area of configuring
7972 default tapes automatically, and so many contradicting requests, that
7973 we finally consider the problem to be portably intractable. We could
7974 of course use something like @samp{/dev/tape} as a default, but this
7975 is @emph{also} running after various kind of trouble, going from hung
7976 processes to accidental destruction of real tapes. After having seen
7977 all this mess, using standard input and output as a default really
7978 sounds like the only clean choice left, and a very useful one too.
7979
7980 @GNUTAR{} reads and writes archive in records, I
7981 suspect this is the main reason why block devices are preferred over
7982 character devices. Most probably, block devices are more efficient
7983 too. The installer could also check for @samp{DEFTAPE} in
7984 @file{<sys/mtio.h>}.
7985
7986 @table @kbd
7987 @item --force-local
7988 Archive file is local even if it contains a colon.
7989
7990 @item --rsh-command=@var{command}
7991 Use remote @var{command} instead of @command{rsh}. This option exists
7992 so that people who use something other than the standard @command{rsh}
7993 (e.g., a Kerberized @command{rsh}) can access a remote device.
7994
7995 When this command is not used, the shell command found when
7996 the @command{tar} program was installed is used instead. This is
7997 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
7998 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
7999 The installer may have overridden this by defining the environment
8000 variable @env{RSH} @emph{at installation time}.
8001
8002 @item -[0-7][lmh]
8003 Specify drive and density.
8004
8005 @item -M
8006 @itemx --multi-volume
8007 Create/list/extract multi-volume archive.
8008
8009 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
8010 that may be larger than will fit on the medium used to hold it.
8011 @xref{Multi-Volume Archives}.
8012
8013 @item -L @var{num}
8014 @itemx --tape-length=@var{num}
8015 Change tape after writing @var{num} x 1024 bytes.
8016
8017 This option might be useful when your tape drivers do not properly
8018 detect end of physical tapes. By being slightly conservative on the
8019 maximum tape length, you might avoid the problem entirely.
8020
8021 @item -F @var{file}
8022 @itemx --info-script=@var{file}
8023 @itemx --new-volume-script=@var{file}
8024 Execute @file{file} at end of each tape. If @file{file} exits with
8025 nonzero status, exit. This implies @value{op-multi-volume}.
8026 @end table
8027
8028 @node Remote Tape Server
8029 @section The Remote Tape Server
8030
8031 @cindex remote tape drive
8032 @pindex rmt
8033 In order to access the tape drive on a remote machine, @command{tar}
8034 uses the remote tape server written at the University of California at
8035 Berkeley. The remote tape server must be installed as
8036 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
8037 want to use. @command{tar} calls @command{rmt} by running an
8038 @command{rsh} or @command{remsh} to the remote machine, optionally
8039 using a different login name if one is supplied.
8040
8041 A copy of the source for the remote tape server is provided. It is
8042 Copyright @copyright{} 1983 by the Regents of the University of
8043 California, but can be freely distributed. It is compiled and
8044 installed by default.
8045
8046 @cindex absolute file names
8047 Unless you use the @value{op-absolute-names} option, @GNUTAR{}
8048 will not allow you to create an archive that contains
8049 absolute file names (a file name beginning with @samp{/}.) If you try,
8050 @command{tar} will automatically remove the leading @samp{/} from the
8051 file names it stores in the archive. It will also type a warning
8052 message telling you what it is doing.
8053
8054 When reading an archive that was created with a different
8055 @command{tar} program, @GNUTAR{} automatically
8056 extracts entries in the archive which have absolute file names as if
8057 the file names were not absolute. This is an important feature. A
8058 visitor here once gave a @command{tar} tape to an operator to restore;
8059 the operator used Sun @command{tar} instead of @GNUTAR{},
8060 and the result was that it replaced large portions of
8061 our @file{/bin} and friends with versions from the tape; needless to
8062 say, we were unhappy about having to recover the file system from
8063 backup tapes.
8064
8065 For example, if the archive contained a file @file{/usr/bin/computoy},
8066 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
8067 relative to the current directory. If you want to extract the files in
8068 an archive to the same absolute names that they had when the archive
8069 was created, you should do a @samp{cd /} before extracting the files
8070 from the archive, or you should either use the @value{op-absolute-names}
8071 option, or use the command @samp{tar -C / @dots{}}.
8072
8073 @cindex Ultrix 3.1 and write failure
8074 Some versions of Unix (Ultrix 3.1 is known to have this problem),
8075 can claim that a short write near the end of a tape succeeded,
8076 when it actually failed. This will result in the -M option not
8077 working correctly. The best workaround at the moment is to use a
8078 significantly larger blocking factor than the default 20.
8079
8080 In order to update an archive, @command{tar} must be able to backspace the
8081 archive in order to reread or rewrite a record that was just read (or
8082 written). This is currently possible only on two kinds of files: normal
8083 disk files (or any other file that can be backspaced with @samp{lseek}),
8084 and industry-standard 9-track magnetic tape (or any other kind of tape
8085 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
8086
8087 This means that the @value{op-append}, @value{op-update},
8088 @value{op-concatenate}, and @value{op-delete} commands will not work on any
8089 other kind of file. Some media simply cannot be backspaced, which
8090 means these commands and options will never be able to work on them.
8091 These non-backspacing media include pipes and cartridge tape drives.
8092
8093 Some other media can be backspaced, and @command{tar} will work on them
8094 once @command{tar} is modified to do so.
8095
8096 Archives created with the @value{op-multi-volume}, @value{op-label}, and
8097 @value{op-incremental} options may not be readable by other version
8098 of @command{tar}. In particular, restoring a file that was split over
8099 a volume boundary will require some careful work with @command{dd}, if
8100 it can be done at all. Other versions of @command{tar} may also create
8101 an empty file whose name is that of the volume header. Some versions
8102 of @command{tar} may create normal files instead of directories archived
8103 with the @value{op-incremental} option.
8104
8105 @node Common Problems and Solutions
8106 @section Some Common Problems and their Solutions
8107
8108 @ifclear PUBLISH
8109
8110 @format
8111 errors from system:
8112 permission denied
8113 no such file or directory
8114 not owner
8115
8116 errors from @command{tar}:
8117 directory checksum error
8118 header format error
8119
8120 errors from media/system:
8121 i/o error
8122 device busy
8123 @end format
8124
8125 @end ifclear
8126
8127 @node Blocking
8128 @section Blocking
8129 @UNREVISED
8130
8131 @dfn{Block} and @dfn{record} terminology is rather confused, and it
8132 is also confusing to the expert reader. On the other hand, readers
8133 who are new to the field have a fresh mind, and they may safely skip
8134 the next two paragraphs, as the remainder of this manual uses those
8135 two terms in a quite consistent way.
8136
8137 John Gilmore, the writer of the public domain @command{tar} from which
8138 @GNUTAR{} was originally derived, wrote (June 1995):
8139
8140 @quotation
8141 The nomenclature of tape drives comes from IBM, where I believe
8142 they were invented for the IBM 650 or so. On IBM mainframes, what
8143 is recorded on tape are tape blocks. The logical organization of
8144 data is into records. There are various ways of putting records into
8145 blocks, including @code{F} (fixed sized records), @code{V} (variable
8146 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
8147 to a block), @code{VB} (variable size records, @var{n} to a block),
8148 @code{VSB} (variable spanned blocked: variable sized records that can
8149 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
8150 parameter specified this to the operating system.
8151
8152 The Unix man page on @command{tar} was totally confused about this.
8153 When I wrote @code{PD TAR}, I used the historically correct terminology
8154 (@command{tar} writes data records, which are grouped into blocks).
8155 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
8156 here), and now Fran@,{c}ois has migrated that terminology back
8157 into the source code too.
8158 @end quotation
8159
8160 The term @dfn{physical block} means the basic transfer chunk from or
8161 to a device, after which reading or writing may stop without anything
8162 being lost. In this manual, the term @dfn{block} usually refers to
8163 a disk physical block, @emph{assuming} that each disk block is 512
8164 bytes in length. It is true that some disk devices have different
8165 physical blocks, but @command{tar} ignore these differences in its own
8166 format, which is meant to be portable, so a @command{tar} block is always
8167 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
8168 The term @dfn{logical block} often represents the basic chunk of
8169 allocation of many disk blocks as a single entity, which the operating
8170 system treats somewhat atomically; this concept is only barely used
8171 in @GNUTAR{}.
8172
8173 The term @dfn{physical record} is another way to speak of a physical
8174 block, those two terms are somewhat interchangeable. In this manual,
8175 the term @dfn{record} usually refers to a tape physical block,
8176 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
8177 It is true that archives may be put on disk or used with pipes,
8178 but nevertheless, @command{tar} tries to read and write the archive one
8179 @dfn{record} at a time, whatever the medium in use. One record is made
8180 up of an integral number of blocks, and this operation of putting many
8181 disk blocks into a single tape block is called @dfn{reblocking}, or
8182 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
8183 the logical organization of many characters into something meaningful
8184 to the application. The term @dfn{unit record} describes a small set
8185 of characters which are transmitted whole to or by the application,
8186 and often refers to a line of text. Those two last terms are unrelated
8187 to what we call a @dfn{record} in @GNUTAR{}.
8188
8189 When writing to tapes, @command{tar} writes the contents of the archive
8190 in chunks known as @dfn{records}. To change the default blocking
8191 factor, use the @value{op-blocking-factor} option. Each record will
8192 then be composed of @var{512-size} blocks. (Each @command{tar} block is
8193 512 bytes. @xref{Standard}.) Each file written to the archive uses
8194 at least one full record. As a result, using a larger record size
8195 can result in more wasted space for small files. On the other hand, a
8196 larger record size can often be read and written much more efficiently.
8197
8198 Further complicating the problem is that some tape drives ignore the
8199 blocking entirely. For these, a larger record size can still improve
8200 performance (because the software layers above the tape drive still
8201 honor the blocking), but not as dramatically as on tape drives that
8202 honor blocking.
8203
8204 When reading an archive, @command{tar} can usually figure out the
8205 record size on itself. When this is the case, and a non-standard
8206 record size was used when the archive was created, @command{tar} will
8207 print a message about a non-standard blocking factor, and then operate
8208 normally. On some tape devices, however, @command{tar} cannot figure
8209 out the record size itself. On most of those, you can specify a
8210 blocking factor (with @value{op-blocking-factor}) larger than the
8211 actual blocking factor, and then use the @value{op-read-full-records}
8212 option. (If you specify a blocking factor with
8213 @value{op-blocking-factor} and don't use the
8214 @value{op-read-full-records} option, then @command{tar} will not
8215 attempt to figure out the recording size itself.) On some devices,
8216 you must always specify the record size exactly with
8217 @value{op-blocking-factor} when reading, because @command{tar} cannot
8218 figure it out. In any case, use @value{op-list} before doing any
8219 extractions to see whether @command{tar} is reading the archive
8220 correctly.
8221
8222 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
8223 putting them into records is to put a whole number of them (one or
8224 more) into each record. @command{tar} records are all the same size;
8225 at the end of the file there's a block containing all zeros, which
8226 is how you tell that the remainder of the last record(s) are garbage.
8227
8228 In a standard @command{tar} file (no options), the block size is 512
8229 and the record size is 10240, for a blocking factor of 20. What the
8230 @value{op-blocking-factor} option does is sets the blocking factor,
8231 changing the record size while leaving the block size at 512 bytes.
8232 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
8233 most tape drives these days prefer much bigger records in order to
8234 stream and not waste tape. When writing tapes for myself, some tend
8235 to use a factor of the order of 2048, say, giving a record size of
8236 around one megabyte.
8237
8238 If you use a blocking factor larger than 20, older @command{tar}
8239 programs might not be able to read the archive, so we recommend this
8240 as a limit to use in practice. @GNUTAR{}, however,
8241 will support arbitrarily large record sizes, limited only by the
8242 amount of virtual memory or the physical characteristics of the tape
8243 device.
8244
8245 @menu
8246 * Format Variations:: Format Variations
8247 * Blocking Factor:: The Blocking Factor of an Archive
8248 @end menu
8249
8250 @node Format Variations
8251 @subsection Format Variations
8252 @cindex Format Parameters
8253 @cindex Format Options
8254 @cindex Options, archive format specifying
8255 @cindex Options, format specifying
8256 @UNREVISED
8257
8258 Format parameters specify how an archive is written on the archive
8259 media. The best choice of format parameters will vary depending on
8260 the type and number of files being archived, and on the media used to
8261 store the archive.
8262
8263 To specify format parameters when accessing or creating an archive,
8264 you can use the options described in the following sections.
8265 If you do not specify any format parameters, @command{tar} uses
8266 default parameters. You cannot modify a compressed archive.
8267 If you create an archive with the @value{op-blocking-factor} option
8268 specified (@value{pxref-blocking-factor}), you must specify that
8269 blocking-factor when operating on the archive. @xref{Formats}, for other
8270 examples of format parameter considerations.
8271
8272 @node Blocking Factor
8273 @subsection The Blocking Factor of an Archive
8274 @cindex Blocking Factor
8275 @cindex Record Size
8276 @cindex Number of blocks per record
8277 @cindex Number of bytes per record
8278 @cindex Bytes per record
8279 @cindex Blocks per record
8280 @UNREVISED
8281
8282 The data in an archive is grouped into blocks, which are 512 bytes.
8283 Blocks are read and written in whole number multiples called
8284 @dfn{records}. The number of blocks in a record (ie. the size of a
8285 record in units of 512 bytes) is called the @dfn{blocking factor}.
8286 The @value{op-blocking-factor} option specifies the blocking factor of
8287 an archive. The default blocking factor is typically 20 (ie.@:
8288 10240 bytes), but can be specified at installation. To find out
8289 the blocking factor of an existing archive, use @samp{tar --list
8290 --file=@var{archive-name}}. This may not work on some devices.
8291
8292 Records are separated by gaps, which waste space on the archive media.
8293 If you are archiving on magnetic tape, using a larger blocking factor
8294 (and therefore larger records) provides faster throughput and allows you
8295 to fit more data on a tape (because there are fewer gaps). If you are
8296 archiving on cartridge, a very large blocking factor (say 126 or more)
8297 greatly increases performance. A smaller blocking factor, on the other
8298 hand, may be useful when archiving small files, to avoid archiving lots
8299 of nulls as @command{tar} fills out the archive to the end of the record.
8300 In general, the ideal record size depends on the size of the
8301 inter-record gaps on the tape you are using, and the average size of the
8302 files you are archiving. @xref{create}, for information on
8303 writing archives.
8304
8305 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
8306
8307 Archives with blocking factors larger than 20 cannot be read
8308 by very old versions of @command{tar}, or by some newer versions
8309 of @command{tar} running on old machines with small address spaces.
8310 With @GNUTAR{}, the blocking factor of an archive is limited
8311 only by the maximum record size of the device containing the archive,
8312 or by the amount of available virtual memory.
8313
8314 Also, on some systems, not using adequate blocking factors, as sometimes
8315 imposed by the device drivers, may yield unexpected diagnostics. For
8316 example, this has been reported:
8317
8318 @smallexample
8319 Cannot write to /dev/dlt: Invalid argument
8320 @end smallexample
8321
8322 @noindent
8323 In such cases, it sometimes happen that the @command{tar} bundled by
8324 the system is aware of block size idiosyncrasies, while @GNUTAR{}
8325 requires an explicit specification for the block size,
8326 which it cannot guess. This yields some people to consider
8327 @GNUTAR{} is misbehaving, because by comparison,
8328 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
8329 for example, might resolve the problem.
8330
8331 If you use a non-default blocking factor when you create an archive, you
8332 must specify the same blocking factor when you modify that archive. Some
8333 archive devices will also require you to specify the blocking factor when
8334 reading that archive, however this is not typically the case. Usually, you
8335 can use @value{op-list} without specifying a blocking factor---@command{tar}
8336 reports a non-default record size and then lists the archive members as
8337 it would normally. To extract files from an archive with a non-standard
8338 blocking factor (particularly if you're not sure what the blocking factor
8339 is), you can usually use the @value{op-read-full-records} option while
8340 specifying a blocking factor larger then the blocking factor of the archive
8341 (ie. @samp{tar --extract --read-full-records --blocking-factor=300}.
8342 @xref{list}, for more information on the @value{op-list}
8343 operation. @xref{Reading}, for a more detailed explanation of that option.
8344
8345 @table @kbd
8346 @item --blocking-factor=@var{number}
8347 @itemx -b @var{number}
8348 Specifies the blocking factor of an archive. Can be used with any
8349 operation, but is usually not necessary with @value{op-list}.
8350 @end table
8351
8352 Device blocking
8353
8354 @table @kbd
8355 @item -b @var{blocks}
8356 @itemx --blocking-factor=@var{blocks}
8357 Set record size to @math{@var{blocks} * 512} bytes.
8358
8359 This option is used to specify a @dfn{blocking factor} for the archive.
8360 When reading or writing the archive, @command{tar}, will do reads and writes
8361 of the archive in records of @math{@var{block}*512} bytes. This is true
8362 even when the archive is compressed. Some devices requires that all
8363 write operations be a multiple of a certain size, and so, @command{tar}
8364 pads the archive out to the next record boundary.
8365
8366 The default blocking factor is set when @command{tar} is compiled, and is
8367 typically 20. Blocking factors larger than 20 cannot be read by very
8368 old versions of @command{tar}, or by some newer versions of @command{tar}
8369 running on old machines with small address spaces.
8370
8371 With a magnetic tape, larger records give faster throughput and fit
8372 more data on a tape (because there are fewer inter-record gaps).
8373 If the archive is in a disk file or a pipe, you may want to specify
8374 a smaller blocking factor, since a large one will result in a large
8375 number of null bytes at the end of the archive.
8376
8377 When writing cartridge or other streaming tapes, a much larger
8378 blocking factor (say 126 or more) will greatly increase performance.
8379 However, you must specify the same blocking factor when reading or
8380 updating the archive.
8381
8382 Apparently, Exabyte drives have a physical block size of 8K bytes.
8383 If we choose our blocksize as a multiple of 8k bytes, then the problem
8384 seems to disappear. Id est, we are using block size of 112 right
8385 now, and we haven't had the problem since we switched@dots{}
8386
8387 With @GNUTAR{} the blocking factor is limited only
8388 by the maximum record size of the device containing the archive, or by
8389 the amount of available virtual memory.
8390
8391 However, deblocking or reblocking is virtually avoided in a special
8392 case which often occurs in practice, but which requires all the
8393 following conditions to be simultaneously true:
8394 @itemize @bullet
8395 @item
8396 the archive is subject to a compression option,
8397 @item
8398 the archive is not handled through standard input or output, nor
8399 redirected nor piped,
8400 @item
8401 the archive is directly handled to a local disk, instead of any special
8402 device,
8403 @item
8404 @value{op-blocking-factor} is not explicitly specified on the @command{tar}
8405 invocation.
8406 @end itemize
8407
8408 If the output goes directly to a local disk, and not through
8409 stdout, then the last write is not extended to a full record size.
8410 Otherwise, reblocking occurs. Here are a few other remarks on this
8411 topic:
8412
8413 @itemize @bullet
8414
8415 @item
8416 @command{gzip} will complain about trailing garbage if asked to
8417 uncompress a compressed archive on tape, there is an option to turn
8418 the message off, but it breaks the regularity of simply having to use
8419 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
8420 silently ignoring any number of trailing zeros. I'll ask Jean-loup
8421 Gailly, by sending a copy of this message to him.
8422
8423 @item
8424 @command{compress} does not show this problem, but as Jean-loup pointed
8425 out to Michael, @samp{compress -d} silently adds garbage after
8426 the result of decompression, which tar ignores because it already
8427 recognized its end-of-file indicator. So this bug may be safely
8428 ignored.
8429
8430 @item
8431 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
8432 but will still return an exit status of 2 which tar reports in turn.
8433 @command{tar} might ignore the exit status returned, but I hate doing
8434 that, as it weakens the protection @command{tar} offers users against
8435 other possible problems at decompression time. If @command{gzip} was
8436 silently skipping trailing zeros @emph{and} also avoiding setting the
8437 exit status in this innocuous case, that would solve this situation.
8438
8439 @item
8440 @command{tar} should become more solid at not stopping to read a pipe at
8441 the first null block encountered. This inelegantly breaks the pipe.
8442 @command{tar} should rather drain the pipe out before exiting itself.
8443 @end itemize
8444
8445 @item -i
8446 @itemx --ignore-zeros
8447 Ignore blocks of zeros in archive (means EOF).
8448
8449 The @value{op-ignore-zeros} option causes @command{tar} to ignore blocks
8450 of zeros in the archive. Normally a block of zeros indicates the
8451 end of the archive, but when reading a damaged archive, or one which
8452 was created by concatenating several archives together, this option
8453 allows @command{tar} to read the entire archive. This option is not on
8454 by default because many versions of @command{tar} write garbage after
8455 the zeroed blocks.
8456
8457 Note that this option causes @command{tar} to read to the end of the
8458 archive file, which may sometimes avoid problems when multiple files
8459 are stored on a single physical tape.
8460
8461 @item -B
8462 @itemx --read-full-records
8463 Reblock as we read (for reading 4.2BSD pipes).
8464
8465 If @value{op-read-full-records} is used, @command{tar} will not panic if an
8466 attempt to read a record from the archive does not return a full record.
8467 Instead, @command{tar} will keep reading until it has obtained a full
8468 record.
8469
8470 This option is turned on by default when @command{tar} is reading
8471 an archive from standard input, or from a remote machine. This is
8472 because on BSD Unix systems, a read of a pipe will return however
8473 much happens to be in the pipe, even if it is less than @command{tar}
8474 requested. If this option was not used, @command{tar} would fail as
8475 soon as it read an incomplete record from the pipe.
8476
8477 This option is also useful with the commands for updating an archive.
8478
8479 @end table
8480
8481 Tape blocking
8482
8483 @FIXME{Appropriate options should be moved here from elsewhere.}
8484
8485 @cindex blocking factor
8486 @cindex tape blocking
8487
8488 When handling various tapes or cartridges, you have to take care of
8489 selecting a proper blocking, that is, the number of disk blocks you
8490 put together as a single tape block on the tape, without intervening
8491 tape gaps. A @dfn{tape gap} is a small landing area on the tape
8492 with no information on it, used for decelerating the tape to a
8493 full stop, and for later regaining the reading or writing speed.
8494 When the tape driver starts reading a record, the record has to
8495 be read whole without stopping, as a tape gap is needed to stop the
8496 tape motion without loosing information.
8497
8498 @cindex Exabyte blocking
8499 @cindex DAT blocking
8500 Using higher blocking (putting more disk blocks per tape block) will use
8501 the tape more efficiently as there will be less tape gaps. But reading
8502 such tapes may be more difficult for the system, as more memory will be
8503 required to receive at once the whole record. Further, if there is a
8504 reading error on a huge record, this is less likely that the system will
8505 succeed in recovering the information. So, blocking should not be too
8506 low, nor it should be too high. @command{tar} uses by default a blocking of
8507 20 for historical reasons, and it does not really matter when reading or
8508 writing to disk. Current tape technology would easily accommodate higher
8509 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
8510 We were told that for some DLT drives, the blocking should be a multiple
8511 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
8512 Other manufacturers may use different recommendations for the same tapes.
8513 This might also depends of the buffering techniques used inside modern
8514 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
8515 Others request blocking to be some exponent of two.
8516
8517 So, there is no fixed rule for blocking. But blocking at read time
8518 should ideally be the same as blocking used at write time. At one place
8519 I know, with a wide variety of equipment, they found it best to use a
8520 blocking of 32 to guarantee that their tapes are fully interchangeable.
8521
8522 I was also told that, for recycled tapes, prior erasure (by the same
8523 drive unit that will be used to create the archives) sometimes lowers
8524 the error rates observed at rewriting time.
8525
8526 I might also use @samp{--number-blocks} instead of
8527 @samp{--block-number}, so @samp{--block} will then expand to
8528 @samp{--blocking-factor} unambiguously.
8529
8530 @node Many
8531 @section Many Archives on One Tape
8532
8533 @FIXME{Appropriate options should be moved here from elsewhere.}
8534
8535 @findex ntape @r{device}
8536 Most tape devices have two entries in the @file{/dev} directory, or
8537 entries that come in pairs, which differ only in the minor number for
8538 this device. Let's take for example @file{/dev/tape}, which often
8539 points to the only or usual tape device of a given system. There might
8540 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
8541 name is the @emph{rewinding} version of the device, while the name
8542 having @samp{nr} in it is the @emph{no rewinding} version of the same
8543 device.
8544
8545 A rewinding tape device will bring back the tape to its beginning point
8546 automatically when this device is opened or closed. Since @command{tar}
8547 opens the archive file before using it and closes it afterwards, this
8548 means that a simple:
8549
8550 @smallexample
8551 $ @kbd{tar cf /dev/tape @var{directory}}
8552 @end smallexample
8553
8554 @noindent
8555 will reposition the tape to its beginning both prior and after saving
8556 @var{directory} contents to it, thus erasing prior tape contents and
8557 making it so that any subsequent write operation will destroy what has
8558 just been saved.
8559
8560 @cindex tape positioning
8561 So, a rewinding device is normally meant to hold one and only one file.
8562 If you want to put more than one @command{tar} archive on a given tape, you
8563 will need to avoid using the rewinding version of the tape device. You
8564 will also have to pay special attention to tape positioning. Errors in
8565 positioning may overwrite the valuable data already on your tape. Many
8566 people, burnt by past experiences, will only use rewinding devices and
8567 limit themselves to one file per tape, precisely to avoid the risk of
8568 such errors. Be fully aware that writing at the wrong position on a
8569 tape loses all information past this point and most probably until the
8570 end of the tape, and this destroyed information @emph{cannot} be
8571 recovered.
8572
8573 To save @var{directory-1} as a first archive at the beginning of a
8574 tape, and leave that tape ready for a second archive, you should use:
8575
8576 @smallexample
8577 $ @kbd{mt -f /dev/nrtape rewind}
8578 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
8579 @end smallexample
8580
8581 @cindex tape marks
8582 @dfn{Tape marks} are special magnetic patterns written on the tape
8583 media, which are later recognizable by the reading hardware. These
8584 marks are used after each file, when there are many on a single tape.
8585 An empty file (that is to say, two tape marks in a row) signal the
8586 logical end of the tape, after which no file exist. Usually,
8587 non-rewinding tape device drivers will react to the close request issued
8588 by @command{tar} by first writing two tape marks after your archive, and by
8589 backspacing over one of these. So, if you remove the tape at that time
8590 from the tape drive, it is properly terminated. But if you write
8591 another file at the current position, the second tape mark will be
8592 erased by the new information, leaving only one tape mark between files.
8593
8594 So, you may now save @var{directory-2} as a second archive after the
8595 first on the same tape by issuing the command:
8596
8597 @smallexample
8598 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
8599 @end smallexample
8600
8601 @noindent
8602 and so on for all the archives you want to put on the same tape.
8603
8604 Another usual case is that you do not write all the archives the same
8605 day, and you need to remove and store the tape between two archive
8606 sessions. In general, you must remember how many files are already
8607 saved on your tape. Suppose your tape already has 16 files on it, and
8608 that you are ready to write the 17th. You have to take care of skipping
8609 the first 16 tape marks before saving @var{directory-17}, say, by using
8610 these commands:
8611
8612 @smallexample
8613 $ @kbd{mt -f /dev/nrtape rewind}
8614 $ @kbd{mt -f /dev/nrtape fsf 16}
8615 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
8616 @end smallexample
8617
8618 In all the previous examples, we put aside blocking considerations, but
8619 you should do the proper things for that as well. @xref{Blocking}.
8620
8621 @menu
8622 * Tape Positioning:: Tape Positions and Tape Marks
8623 * mt:: The @command{mt} Utility
8624 @end menu
8625
8626 @node Tape Positioning
8627 @subsection Tape Positions and Tape Marks
8628 @UNREVISED
8629
8630 Just as archives can store more than one file from the file system,
8631 tapes can store more than one archive file. To keep track of where
8632 archive files (or any other type of file stored on tape) begin and
8633 end, tape archive devices write magnetic @dfn{tape marks} on the
8634 archive media. Tape drives write one tape mark between files,
8635 two at the end of all the file entries.
8636
8637 If you think of data as a series of records "rrrr"'s, and tape marks as
8638 "*"'s, a tape might look like the following:
8639
8640 @smallexample
8641 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
8642 @end smallexample
8643
8644 Tape devices read and write tapes using a read/write @dfn{tape
8645 head}---a physical part of the device which can only access one
8646 point on the tape at a time. When you use @command{tar} to read or
8647 write archive data from a tape device, the device will begin reading
8648 or writing from wherever on the tape the tape head happens to be,
8649 regardless of which archive or what part of the archive the tape
8650 head is on. Before writing an archive, you should make sure that no
8651 data on the tape will be overwritten (unless it is no longer needed).
8652 Before reading an archive, you should make sure the tape head is at
8653 the beginning of the archive you want to read. (The @code{restore}
8654 script will find the archive automatically. @FIXME-xref{Scripted Restoration}@xref{mt}, for
8655 an explanation of the tape moving utility.
8656
8657 If you want to add new archive file entries to a tape, you should
8658 advance the tape to the end of the existing file entries, backspace
8659 over the last tape mark, and write the new archive file. If you were
8660 to add two archives to the example above, the tape might look like the
8661 following:
8662
8663 @smallexample
8664 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
8665 @end smallexample
8666
8667 @node mt
8668 @subsection The @command{mt} Utility
8669 @UNREVISED
8670
8671 @FIXME{Is it true that this only works on non-block devices?
8672 should explain the difference, (fixed or variable).}
8673 @value{xref-blocking-factor}.
8674
8675 You can use the @command{mt} utility to advance or rewind a tape past a
8676 specified number of archive files on the tape. This will allow you
8677 to move to the beginning of an archive before extracting or reading
8678 it, or to the end of all the archives before writing a new one.
8679 @FIXME{Why isn't there an "advance 'til you find two tape marks
8680 together"?}
8681
8682 The syntax of the @command{mt} command is:
8683
8684 @smallexample
8685 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
8686 @end smallexample
8687
8688 where @var{tapename} is the name of the tape device, @var{number} is
8689 the number of times an operation is performed (with a default of one),
8690 and @var{operation} is one of the following:
8691
8692 @FIXME{is there any use for record operations?}
8693
8694 @table @kbd
8695 @item eof
8696 @itemx weof
8697 Writes @var{number} tape marks at the current position on the tape.
8698
8699 @item fsf
8700 Moves tape position forward @var{number} files.
8701
8702 @item bsf
8703 Moves tape position back @var{number} files.
8704
8705 @item rewind
8706 Rewinds the tape. (Ignores @var{number}).
8707
8708 @item offline
8709 @itemx rewoff1
8710 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
8711
8712 @item status
8713 Prints status information about the tape unit.
8714
8715 @end table
8716
8717 @FIXME{Is there a better way to frob the spacing on the list?}
8718
8719 If you don't specify a @var{tapename}, @command{mt} uses the environment
8720 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} uses the device
8721 @file{/dev/rmt12}.
8722
8723 @command{mt} returns a 0 exit status when the operation(s) were
8724 successful, 1 if the command was unrecognized, and 2 if an operation
8725 failed.
8726
8727 @FIXME{New node on how to find an archive?}
8728
8729 If you use @value{op-extract} with the @value{op-label} option specified,
8730 @command{tar} will read an archive label (the tape head has to be positioned
8731 on it) and print an error if the archive label doesn't match the
8732 @var{archive-name} specified. @var{archive-name} can be any regular
8733 expression. If the labels match, @command{tar} extracts the archive.
8734 @value{xref-label}.
8735 @FIXME-xref{Matching Format Parameters}@FIXME{fix cross
8736 references}@samp{tar --list --label} will cause @command{tar} to print the
8737 label.
8738
8739 @FIXME{Program to list all the labels on a tape?}
8740
8741 @node Using Multiple Tapes
8742 @section Using Multiple Tapes
8743 @UNREVISED
8744
8745 Often you might want to write a large archive, one larger than will fit
8746 on the actual tape you are using. In such a case, you can run multiple
8747 @command{tar} commands, but this can be inconvenient, particularly if you
8748 are using options like @value{op-exclude} or dumping entire filesystems.
8749 Therefore, @command{tar} supports multiple tapes automatically.
8750
8751 Use @value{op-multi-volume} on the command line, and then @command{tar} will,
8752 when it reaches the end of the tape, prompt for another tape, and
8753 continue the archive. Each tape will have an independent archive, and
8754 can be read without needing the other. (As an exception to this, the
8755 file that @command{tar} was archiving when it ran out of tape will usually
8756 be split between the two archives; in this case you need to extract from
8757 the first archive, using @value{op-multi-volume}, and then put in the
8758 second tape when prompted, so @command{tar} can restore both halves of the
8759 file.)
8760
8761 @GNUTAR{} multi-volume archives do not use a truly
8762 portable format. You need @GNUTAR{} at both end to
8763 process them properly.
8764
8765 When prompting for a new tape, @command{tar} accepts any of the following
8766 responses:
8767
8768 @table @kbd
8769 @item ?
8770 Request @command{tar} to explain possible responses
8771 @item q
8772 Request @command{tar} to exit immediately.
8773 @item n @var{file name}
8774 Request @command{tar} to write the next volume on the file @var{file name}.
8775 @item !
8776 Request @command{tar} to run a subshell.
8777 @item y
8778 Request @command{tar} to begin writing the next volume.
8779 @end table
8780
8781 (You should only type @samp{y} after you have changed the tape;
8782 otherwise @command{tar} will write over the volume it just finished.)
8783
8784 If you want more elaborate behavior than this, give @command{tar} the
8785 @value{op-info-script} option. The file @var{script-name} is expected
8786 to be a program (or shell script) to be run instead of the normal
8787 prompting procedure. If the program fails, @command{tar} exits;
8788 otherwise, @command{tar} begins writing the next volume. The behavior
8789 of the
8790 @samp{n} response to the normal tape-change prompt is not available
8791 if you use @value{op-info-script}.
8792
8793 The method @command{tar} uses to detect end of tape is not perfect, and
8794 fails on some operating systems or on some devices. You can use the
8795 @value{op-tape-length} option if @command{tar} can't detect the end of the
8796 tape itself. This option selects @value{op-multi-volume} automatically.
8797 The @var{size} argument should then be the usable size of the tape.
8798 But for many devices, and floppy disks in particular, this option is
8799 never required for real, as far as we know.
8800
8801 The volume number used by @command{tar} in its tape-change prompt
8802 can be changed; if you give the @value{op-volno-file} option, then
8803 @var{file-of-number} should be an unexisting file to be created, or else,
8804 a file already containing a decimal number. That number will be used
8805 as the volume number of the first volume written. When @command{tar} is
8806 finished, it will rewrite the file with the now-current volume number.
8807 (This does not change the volume number written on a tape label, as
8808 per @value{ref-label}, it @emph{only} affects the number used in
8809 the prompt.)
8810
8811 If you want @command{tar} to cycle through a series of tape drives, then
8812 you can use the @samp{n} response to the tape-change prompt. This is
8813 error prone, however, and doesn't work at all with @value{op-info-script}.
8814 Therefore, if you give @command{tar} multiple @value{op-file} options, then
8815 the specified files will be used, in sequence, as the successive volumes
8816 of the archive. Only when the first one in the sequence needs to be
8817 used again will @command{tar} prompt for a tape change (or run the info
8818 script).
8819
8820 Multi-volume archives
8821
8822 With @value{op-multi-volume}, @command{tar} will not abort when it cannot
8823 read or write any more data. Instead, it will ask you to prepare a new
8824 volume. If the archive is on a magnetic tape, you should change tapes
8825 now; if the archive is on a floppy disk, you should change disks, etc.
8826
8827 Each volume of a multi-volume archive is an independent @command{tar}
8828 archive, complete in itself. For example, you can list or extract any
8829 volume alone; just don't specify @value{op-multi-volume}. However, if one
8830 file in the archive is split across volumes, the only way to extract
8831 it successfully is with a multi-volume extract command @samp{--extract
8832 --multi-volume} (@samp{-xM}) starting on or before the volume where
8833 the file begins.
8834
8835 For example, let's presume someone has two tape drives on a system
8836 named @file{/dev/tape0} and @file{/dev/tape1}. For having @GNUTAR{}
8837 to switch to the second drive when it needs to write the
8838 second tape, and then back to the first tape, etc., just do either of:
8839
8840 @smallexample
8841 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
8842 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
8843 @end smallexample
8844
8845 @menu
8846 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
8847 * Tape Files:: Tape Files
8848 @end menu
8849
8850 @node Multi-Volume Archives
8851 @subsection Archives Longer than One Tape or Disk
8852 @cindex Multi-volume archives
8853 @UNREVISED
8854
8855 To create an archive that is larger than will fit on a single unit of
8856 the media, use the @value{op-multi-volume} option in conjunction with
8857 the @value{op-create} option (@pxref{create}). A
8858 @dfn{multi-volume} archive can be manipulated like any other archive
8859 (provided the @value{op-multi-volume} option is specified), but is
8860 stored on more than one tape or disk.
8861
8862 When you specify @value{op-multi-volume}, @command{tar} does not report an
8863 error when it comes to the end of an archive volume (when reading), or
8864 the end of the media (when writing). Instead, it prompts you to load
8865 a new storage volume. If the archive is on a magnetic tape, you
8866 should change tapes when you see the prompt; if the archive is on a
8867 floppy disk, you should change disks; etc.
8868
8869 You can read each individual volume of a multi-volume archive as if it
8870 were an archive by itself. For example, to list the contents of one
8871 volume, use @value{op-list}, without @value{op-multi-volume} specified.
8872 To extract an archive member from one volume (assuming it is described
8873 that volume), use @value{op-extract}, again without
8874 @value{op-multi-volume}.
8875
8876 If an archive member is split across volumes (ie. its entry begins on
8877 one volume of the media and ends on another), you need to specify
8878 @value{op-multi-volume} to extract it successfully. In this case, you
8879 should load the volume where the archive member starts, and use
8880 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
8881 volumes as it needs them. @xref{extracting archives}, for more
8882 information about extracting archives.
8883
8884 @value{op-info-script} is like @value{op-multi-volume}, except that
8885 @command{tar} does not prompt you directly to change media volumes when
8886 a volume is full---instead, @command{tar} runs commands you have stored
8887 in @var{script-name}. For example, this option can be used to eject
8888 cassettes, or to broadcast messages such as @samp{Someone please come
8889 change my tape} when performing unattended backups. When @var{script-name}
8890 is done, @command{tar} will assume that the media has been changed.
8891
8892 Multi-volume archives can be modified like any other archive. To add
8893 files to a multi-volume archive, you need to only mount the last
8894 volume of the archive media (and new volumes, if needed). For all
8895 other operations, you need to use the entire archive.
8896
8897 If a multi-volume archive was labeled using @value{op-label}
8898 (@value{pxref-label}) when it was created, @command{tar} will not
8899 automatically label volumes which are added later. To label subsequent
8900 volumes, specify @value{op-label} again in conjunction with the
8901 @value{op-append}, @value{op-update} or @value{op-concatenate} operation.
8902
8903 @cindex Labeling multi-volume archives
8904 @FIXME{example}
8905
8906 @FIXME{There should be a sample program here, including an exit
8907 before end. Is the exit status even checked in tar? :-(}
8908
8909 @table @kbd
8910 @item --multi-volume
8911 @itemx -M
8912 Creates a multi-volume archive, when used in conjunction with
8913 @value{op-create}. To perform any other operation on a multi-volume
8914 archive, specify @value{op-multi-volume} in conjunction with that
8915 operation.
8916
8917 @item --info-script=@var{program-file}
8918 @itemx -F @var{program-file}
8919 Creates a multi-volume archive via a script. Used in conjunction with
8920 @value{op-create}.
8921 @end table
8922
8923 Beware that there is @emph{no} real standard about the proper way, for
8924 a @command{tar} archive, to span volume boundaries. If you have a
8925 multi-volume created by some vendor's @command{tar}, there is almost
8926 no chance you could read all the volumes with @GNUTAR{}.
8927 The converse is also true: you may not expect
8928 multi-volume archives created by @GNUTAR{} to be
8929 fully recovered by vendor's @command{tar}. Since there is little
8930 chance that, in mixed system configurations, some vendor's
8931 @command{tar} will work on another vendor's machine, and there is a
8932 great chance that @GNUTAR{} will work on most of
8933 them, your best bet is to install @GNUTAR{} on all
8934 machines between which you know exchange of files is possible.
8935
8936 @node Tape Files
8937 @subsection Tape Files
8938 @UNREVISED
8939
8940 To give the archive a name which will be recorded in it, use the
8941 @value{op-label} option. This will write a special block identifying
8942 @var{volume-label} as the name of the archive to the front of the archive
8943 which will be displayed when the archive is listed with @value{op-list}.
8944 If you are creating a multi-volume archive with
8945 @value{op-multi-volume}@FIXME-pxref{Using Multiple Tapes}, then the
8946 volume label will have
8947 @samp{Volume @var{nnn}} appended to the name you give, where @var{nnn} is
8948 the number of the volume of the archive. (If you use the @value{op-label}
8949 option when reading an archive, it checks to make sure the label on the
8950 tape matches the one you give. @value{xref-label}.
8951
8952 When @command{tar} writes an archive to tape, it creates a single
8953 tape file. If multiple archives are written to the same tape, one
8954 after the other, they each get written as separate tape files. When
8955 extracting, it is necessary to position the tape at the right place
8956 before running @command{tar}. To do this, use the @command{mt} command.
8957 For more information on the @command{mt} command and on the organization
8958 of tapes into a sequence of tape files, see @ref{mt}.
8959
8960 People seem to often do:
8961
8962 @smallexample
8963 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
8964 @end smallexample
8965
8966 or such, for pushing a common date in all volumes or an archive set.
8967
8968 @node label
8969 @section Including a Label in the Archive
8970 @cindex Labeling an archive
8971 @cindex Labels on the archive media
8972 @UNREVISED
8973
8974 @table @kbd
8975 @item -V @var{name}
8976 @itemx --label=@var{name}
8977 Create archive with volume name @var{name}.
8978 @end table
8979
8980 This option causes @command{tar} to write out a @dfn{volume header} at
8981 the beginning of the archive. If @value{op-multi-volume} is used, each
8982 volume of the archive will have a volume header of @samp{@var{name}
8983 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
8984 next, and so on.
8985
8986 @FIXME{Should the arg to --label be a quoted string?? No.}
8987
8988 To avoid problems caused by misplaced paper labels on the archive
8989 media, you can include a @dfn{label} entry---an archive member which
8990 contains the name of the archive---in the archive itself. Use the
8991 @value{op-label} option in conjunction with the @value{op-create} operation
8992 to include a label entry in the archive as it is being created.
8993
8994 If you create an archive using both @value{op-label} and
8995 @value{op-multi-volume}, each volume of the archive will have an
8996 archive label of the form @samp{@var{archive-label} Volume @var{n}},
8997 where @var{n} is 1 for the first volume, 2 for the next, and so on.
8998 @FIXME-xref{Multi-Volume Archives, for information on creating multiple
8999 volume archives.}
9000
9001 If you list or extract an archive using @value{op-label}, @command{tar} will
9002 print an error if the archive label doesn't match the @var{archive-label}
9003 specified, and will then not list nor extract the archive. In those cases,
9004 @var{archive-label} argument is interpreted as a globbing-style pattern
9005 which must match the actual magnetic volume label. @xref{exclude}, for
9006 a precise description of how match is attempted@footnote{Previous versions
9007 of @command{tar} used full regular expression matching, or before that, only
9008 exact string matching, instead of wildcard matchers. We decided for the
9009 sake of simplicity to use a uniform matching device through @command{tar}.}.
9010 If the switch @value{op-multi-volume} is being used, the volume label
9011 matcher will also suffix @var{archive-label} by @w{@samp{ Volume [1-9]*}}
9012 if the initial match fails, before giving up. Since the volume numbering
9013 is automatically added in labels at creation time, it sounded logical to
9014 equally help the user taking care of it when the archive is being read.
9015
9016 The @value{op-label} was once called @samp{--volume}, but is not available
9017 under that name anymore.
9018
9019 To find out an archive's label entry (or to find out if an archive has
9020 a label at all), use @samp{tar --list --verbose}. @command{tar} will
9021 print the label first, and then print archive member information, as
9022 in the example below:
9023
9024 @smallexample
9025 $ @kbd{tar --verbose --list --file=iamanarchive}
9026 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
9027 -rw-rw-rw- ringo user 40 1990-05-21 13:30 iamafilename
9028 @end smallexample
9029
9030 @table @kbd
9031 @item --label=@var{archive-label}
9032 @itemx -V @var{archive-label}
9033 Includes an @dfn{archive-label} at the beginning of the archive when
9034 the archive is being created, when used in conjunction with the
9035 @value{op-create} option. Checks to make sure the archive label
9036 matches the one specified (when used in conjunction with the
9037 @value{op-extract} option.
9038 @end table
9039
9040 To get a common information on all tapes of a series, use the
9041 @value{op-label} option. For having this information different in each
9042 series created through a single script used on a regular basis, just
9043 manage to get some date string as part of the label. For example:
9044
9045 @smallexample
9046 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
9047 $ @kbd{tar --create --file=/dev/tape --multi-volume \
9048 --volume="Daily backup for `date +%Y-%m-%d`"}
9049 @end smallexample
9050
9051 Also note that each label has its own date and time, which corresponds
9052 to when @GNUTAR{} initially attempted to write it,
9053 often soon after the operator launches @command{tar} or types the
9054 carriage return telling that the next tape is ready. Comparing date
9055 labels does give an idea of tape throughput only if the delays for
9056 rewinding tapes and the operator switching them were negligible, which
9057 is usually not the case.
9058
9059 @FIXME{was --volume}
9060
9061 @node verify
9062 @section Verifying Data as It is Stored
9063 @cindex Verifying a write operation
9064 @cindex Double-checking a write operation
9065
9066 @table @kbd
9067 @item -W
9068 @itemx --verify
9069 Attempt to verify the archive after writing.
9070 @end table
9071
9072 This option causes @command{tar} to verify the archive after writing it.
9073 Each volume is checked after it is written, and any discrepancies
9074 are recorded on the standard error output.
9075
9076 Verification requires that the archive be on a back-space-able medium.
9077 This means pipes, some cartridge tape drives, and some other devices
9078 cannot be verified.
9079
9080 You can insure the accuracy of an archive by comparing files in the
9081 system with archive members. @command{tar} can compare an archive to the
9082 file system as the archive is being written, to verify a write
9083 operation, or can compare a previously written archive, to insure that
9084 it is up to date.
9085
9086 To check for discrepancies in an archive immediately after it is
9087 written, use the @value{op-verify} option in conjunction with
9088 the @value{op-create} operation. When this option is
9089 specified, @command{tar} checks archive members against their counterparts
9090 in the file system, and reports discrepancies on the standard error.
9091
9092 To verify an archive, you must be able to read it from before the end
9093 of the last written entry. This option is useful for detecting data
9094 errors on some tapes. Archives written to pipes, some cartridge tape
9095 drives, and some other devices cannot be verified.
9096
9097 One can explicitly compare an already made archive with the file system
9098 by using the @value{op-compare} option, instead of using the more automatic
9099 @value{op-verify} option. @value{xref-compare}.
9100
9101 Note that these two options have a slightly different intent. The
9102 @value{op-compare} option how identical are the logical contents of some
9103 archive with what is on your disks, while the @value{op-verify} option is
9104 really for checking if the physical contents agree and if the recording
9105 media itself is of dependable quality. So, for the @value{op-verify}
9106 operation, @command{tar} tries to defeat all in-memory cache pertaining to
9107 the archive, while it lets the speed optimization undisturbed for the
9108 @value{op-compare} option. If you nevertheless use @value{op-compare} for
9109 media verification, you may have to defeat the in-memory cache yourself,
9110 maybe by opening and reclosing the door latch of your recording unit,
9111 forcing some doubt in your operating system about the fact this is really
9112 the same volume as the one just written or read.
9113
9114 The @value{op-verify} option would not be necessary if drivers were indeed
9115 able to detect dependably all write failures. This sometimes require many
9116 magnetic heads, some able to read after the writes occurred. One would
9117 not say that drivers unable to detect all cases are necessarily flawed,
9118 as long as programming is concerned.
9119
9120 The @value{op-verify} option will not work in conjunction with the
9121 @value{op-multi-volume} option or the @value{op-append},
9122 @value{op-update} and @value{op-delete} operations. @xref{Operations},
9123 for more information on these operations.
9124
9125 Also, since @command{tar} normally strips leading @samp{/} from file
9126 names (@pxref{absolute}), a command like @samp{tar --verify -cf
9127 /tmp/foo.tar /etc} will work as desired only if the working directory is
9128 @file{/}, as @command{tar} uses the archive's relative member names
9129 (e.g., @file{etc/motd}) when verifying the archive.
9130
9131 @node Write Protection
9132 @section Write Protection
9133
9134 Almost all tapes and diskettes, and in a few rare cases, even disks can
9135 be @dfn{write protected}, to protect data on them from being changed.
9136 Once an archive is written, you should write protect the media to prevent
9137 the archive from being accidentally overwritten or deleted. (This will
9138 protect the archive from being changed with a tape or floppy drive---it
9139 will not protect it from magnet fields or other physical hazards).
9140
9141 The write protection device itself is usually an integral part of the
9142 physical media, and can be a two position (write enabled/write
9143 disabled) switch, a notch which can be popped out or covered, a ring
9144 which can be removed from the center of a tape reel, or some other
9145 changeable feature.
9146
9147 @node Free Software Needs Free Documentation
9148 @appendix Free Software Needs Free Documentation
9149 @include freemanuals.texi
9150
9151 @node Copying This Manual
9152 @appendix Copying This Manual
9153
9154 @menu
9155 * GNU Free Documentation License:: License for copying this manual
9156 @end menu
9157
9158 @include fdl.texi
9159
9160 @node Index
9161 @appendix Index
9162
9163 @printindex cp
9164
9165 @summarycontents
9166 @contents
9167 @bye
9168
9169 @c Local variables:
9170 @c texinfo-column-for-description: 32
9171 @c End:
This page took 0.445823 seconds and 5 git commands to generate.