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