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