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