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