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