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