9 @c ======================================================================
10 @c This document has three levels of rendition: PUBLISH, DISTRIB or PROOF,
11 @c as decided by @set symbols. The PUBLISH rendition does not show
12 @c notes or marks asking for revision. Most users will prefer having more
13 @c information, even if this information is not fully revised for adequacy,
14 @c so DISTRIB is the default for tar distributions. The PROOF rendition
15 @c show all marks to the point of ugliness, but is nevertheless useful to
16 @c those working on the manual itself.
17 @c ======================================================================
28 @set RENDITION The book, version
32 @set RENDITION FTP release, version
36 @set RENDITION Proof reading version
39 @c ---------------------------------------------------------------------
40 @c The @FIXME's, @UNREVISED and @c comments are part Fran@,{c}ois's work
41 @c plan. These annotations are somewhat precious to him; he asks that I
42 @c do not alter them inconsiderately. Much work is needed for GNU tar
43 @c internals (the sources, the programs themselves). Revising the
44 @c adequacy of the manual while revising the sources, and cleaning them
45 @c both at the same time, seems to him like a good way to proceed.
46 @c ---------------------------------------------------------------------
48 @c Output marks for nodes needing revision, but not in PUBLISH rendition.
53 @emph{(This message will disappear, once this node revised.)}
58 @c Output various FIXME information only in PROOF rendition.
64 @strong{<FIXME>} \string\ @strong{</>}
69 @macro FIXME-ref{string}
72 @strong{<REF>} \string\ @strong{</>}
77 @macro FIXME-pxref{string}
80 @strong{<PXREF>} \string\ @strong{</>}
85 @macro FIXME-xref{string}
88 @strong{<XREF>} \string\ @strong{</>}
93 @c @macro option{entry}
95 @c @opindex{--\entry\}
99 @set op-absolute-names @kbd{--absolute-names} (@kbd{-P})
100 @set ref-absolute-names @ref{absolute}
101 @set xref-absolute-names @xref{absolute}
102 @set pxref-absolute-names @pxref{absolute}
104 @set op-after-date @kbd{--after-date=@var{date}} (@kbd{--newer=@var{date}}, @kbd{-N @var{date}})
105 @set ref-after-date @ref{after}
106 @set xref-after-date @xref{after}
107 @set pxref-after-date @pxref{after}
109 @set op-append @kbd{--append} (@kbd{-r})
110 @set ref-append @ref{add}
111 @set xref-append @xref{add}
112 @set pxref-append @pxref{add}
114 @set op-atime-preserve @kbd{--atime-preserve}
115 @set ref-atime-preserve @ref{Attributes}
116 @set xref-atime-preserve @xref{Attributes}
117 @set pxref-atime-preserve @pxref{Attributes}
119 @set op-backup @kbd{--backup}
120 @set ref-backup @ref{Backup options}
121 @set xref-backup @xref{Backup options}
122 @set pxref-backup @pxref{Backup options}
124 @set op-block-number @kbd{--block-number} (@kbd{-R})
125 @set ref-block-number @ref{verbose}
126 @set xref-block-number @xref{verbose}
127 @set pxref-block-number @pxref{verbose}
129 @set op-blocking-factor @kbd{--blocking-factor=@var{512-size}} (@kbd{-b @var{512-size}})
130 @set ref-blocking-factor @ref{Blocking Factor}
131 @set xref-blocking-factor @xref{Blocking Factor}
132 @set pxref-blocking-factor @pxref{Blocking Factor}
134 @set op-bzip2 @kbd{--bzip2} (@kbd{-I})
135 @set ref-bzip2 @ref{gzip}
136 @set xref-bzip2 @xref{gzip}
137 @set pxref-bzip2 @pxref{gzip}
139 @set op-checkpoint @kbd{--checkpoint}
140 @set ref-checkpoint @ref{verbose}
141 @set xref-checkpoint @xref{verbose}
142 @set pxref-checkpoint @pxref{verbose}
144 @set op-compare @kbd{--compare} (@kbd{--diff}, @kbd{-d})
145 @set ref-compare @ref{compare}
146 @set xref-compare @xref{compare}
147 @set pxref-compare @pxref{compare}
149 @set op-compress @kbd{--compress} (@kbd{--uncompress}, @kbd{-Z})
150 @set ref-compress @ref{gzip}
151 @set xref-compress @xref{gzip}
152 @set pxref-compress @pxref{gzip}
154 @set op-concatenate @kbd{--concatenate} (@kbd{--catenate}, @kbd{-A})
155 @set ref-concatenate @ref{concatenate}
156 @set xref-concatenate @xref{concatenate}
157 @set pxref-concatenate @pxref{concatenate}
159 @set op-create @kbd{--create} (@kbd{-c})
160 @set ref-create @ref{create}
161 @set xref-create @xref{create}
162 @set pxref-create @pxref{create}
164 @set op-delete @kbd{--delete}
165 @set ref-delete @ref{delete}
166 @set xref-delete @xref{delete}
167 @set pxref-delete @pxref{delete}
169 @set op-dereference @kbd{--dereference} (@kbd{-h})
170 @set ref-dereference @ref{dereference}
171 @set xref-dereference @xref{dereference}
172 @set pxref-dereference @pxref{dereference}
174 @set op-directory @kbd{--directory=@var{directory}} (@kbd{-C @var{directory}})
175 @set ref-directory @ref{directory}
176 @set xref-directory @xref{directory}
177 @set pxref-directory @pxref{directory}
179 @set op-exclude @kbd{--exclude=@var{pattern}}
180 @set ref-exclude @ref{exclude}
181 @set xref-exclude @xref{exclude}
182 @set pxref-exclude @pxref{exclude}
184 @set op-exclude-from @kbd{--exclude-from=@var{file-of-patterns}} (@kbd{-X @var{file-of-patterns}})
185 @set ref-exclude-from @ref{exclude}
186 @set xref-exclude-from @xref{exclude}
187 @set pxref-exclude-from @pxref{exclude}
189 @set op-extract @kbd{--extract} (@kbd{--get}, @kbd{-x})
190 @set ref-extract @ref{extract}
191 @set xref-extract @xref{extract}
192 @set pxref-extract @pxref{extract}
194 @set op-file @kbd{--file=@var{archive-name}} (@kbd{-f @var{archive-name}})
195 @set ref-file @ref{file}
196 @set xref-file @xref{file}
197 @set pxref-file @pxref{file}
199 @set op-files-from @kbd{--files-from=@var{file-of-names}} (@kbd{-T @var{file-of-names}})
200 @set ref-files-from @ref{files}
201 @set xref-files-from @xref{files}
202 @set pxref-files-from @pxref{files}
204 @set op-force-local @kbd{--force-local}
205 @set ref-force-local @ref{file}
206 @set xref-force-local @xref{file}
207 @set pxref-force-local @pxref{file}
209 @set op-group @kbd{--group=@var{group}}
210 @set ref-group @ref{Option Summary}
211 @set xref-group @xref{Option Summary}
212 @set pxref-group @pxref{Option Summary}
214 @set op-gzip @kbd{--gzip} (@kbd{--gunzip}, @kbd{--ungzip}, @kbd{-z})
215 @set ref-gzip @ref{gzip}
216 @set xref-gzip @xref{gzip}
217 @set pxref-gzip @pxref{gzip}
219 @set op-help @kbd{--help}
220 @set ref-help @ref{help}
221 @set xref-help @xref{help}
222 @set pxref-help @pxref{help}
224 @set op-ignore-failed-read @kbd{--ignore-failed-read}
225 @set ref-ignore-failed-read @ref{Reading}
226 @set xref-ignore-failed-read @xref{Reading}
227 @set pxref-ignore-failed-read @pxref{Reading}
229 @set op-ignore-zeros @kbd{--ignore-zeros} (@kbd{-i})
230 @set ref-ignore-zeros @ref{Reading}
231 @set xref-ignore-zeros @xref{Reading}
232 @set pxref-ignore-zeros @pxref{Reading}
234 @set op-incremental @kbd{--incremental} (@kbd{-G})
235 @set ref-incremental @ref{Inc Dumps}
236 @set xref-incremental @xref{Inc Dumps}
237 @set pxref-incremental @pxref{Inc Dumps}
239 @set op-info-script @kbd{--info-script=@var{script-name}} (@kbd{--new-volume-script=@var{script-name}}, @kbd{-F @var{script-name}})
240 @set ref-info-script @ref{Multi-Volume Archives}
241 @set xref-info-script @xref{Multi-Volume Archives}
242 @set pxref-info-script @pxref{Multi-Volume Archives}
244 @set op-interactive @kbd{--interactive} (@kbd{-w})
245 @set ref-interactive @ref{interactive}
246 @set xref-interactive @xref{interactive}
247 @set pxref-interactive @pxref{interactive}
249 @set op-keep-old-files @kbd{--keep-old-files} (@kbd{-k})
250 @set ref-keep-old-files @ref{Writing}
251 @set xref-keep-old-files @xref{Writing}
252 @set pxref-keep-old-files @pxref{Writing}
254 @set op-label @kbd{--label=@var{archive-label}} (@kbd{-V @var{archive-label}})
255 @set ref-label @ref{label}
256 @set xref-label @xref{label}
257 @set pxref-label @pxref{label}
259 @set op-list @kbd{--list} (@kbd{-t})
260 @set ref-list @ref{list}
261 @set xref-list @xref{list}
262 @set pxref-list @pxref{list}
264 @set op-listed-incremental @kbd{--listed-incremental=@var{snapshot-file}} (@kbd{-g @var{snapshot-file}})
265 @set ref-listed-incremental @ref{Inc Dumps}
266 @set xref-listed-incremental @xref{Inc Dumps}
267 @set pxref-listed-incremental @pxref{Inc Dumps}
269 @set op-mode @kbd{--mode=@var{permissions}}
270 @set ref-mode @ref{Option Summary}
271 @set xref-mode @xref{Option Summary}
272 @set pxref-mode @pxref{Option Summary}
274 @set op-multi-volume @kbd{--multi-volume} (@kbd{-M})
275 @set ref-multi-volume @ref{Multi-Volume Archives}
276 @set xref-multi-volume @xref{Multi-Volume Archives}
277 @set pxref-multi-volume @pxref{Multi-Volume Archives}
279 @set op-newer-mtime @kbd{--newer-mtime=@var{date}}
280 @set ref-newer-mtime @ref{after}
281 @set xref-newer-mtime @xref{after}
282 @set pxref-newer-mtime @pxref{after}
284 @set op-no-recursion @kbd{--no-recursion}
285 @set ref-no-recursion @ref{recurse}
286 @set xref-no-recursion @xref{recurse}
287 @set pxref-no-recursion @pxref{recurse}
289 @set op-no-same-owner @kbd{--no-same-owner}
290 @set ref-no-same-owner @ref{Attributes}
291 @set xref-no-same-owner @xref{Attributes}
292 @set pxref-no-same-owner @pxref{Attributes}
294 @set op-no-same-permissions @kbd{--no-same-permissions}
295 @set ref-no-same-permissions @ref{Attributes}
296 @set xref-no-same-permissions @xref{Attributes}
297 @set pxref-no-same-permissions @pxref{Attributes}
299 @set op-null @kbd{--null}
300 @set ref-null @ref{files}
301 @set xref-null @xref{files}
302 @set pxref-null @pxref{files}
304 @set op-numeric-owner @kbd{--numeric-owner}
305 @set ref-numeric-owner @ref{Attributes}
306 @set xref-numeric-owner @xref{Attributes}
307 @set pxref-numeric-owner @pxref{Attributes}
309 @set op-old-archive @kbd{--old-archive} (@kbd{-o})
310 @set ref-old-archive @ref{old}
311 @set xref-old-archive @xref{old}
312 @set pxref-old-archive @pxref{old}
314 @set op-one-file-system @kbd{--one-file-system} (@kbd{-l})
315 @set ref-one-file-system @ref{one}
316 @set xref-one-file-system @xref{one}
317 @set pxref-one-file-system @pxref{one}
319 @set op-owner @kbd{--owner=@var{user}}
320 @set ref-owner @ref{Option Summary}
321 @set xref-owner @xref{Option Summary}
322 @set pxref-owner @pxref{Option Summary}
324 @set op-posix @kbd{--posix}
325 @set ref-posix @ref{posix}
326 @set xref-posix @xref{posix}
327 @set pxref-posix @pxref{posix}
329 @set op-preserve @kbd{--preserve}
330 @set ref-preserve @ref{Attributes}
331 @set xref-preserve @xref{Attributes}
332 @set pxref-preserve @pxref{Attributes}
334 @set op-record-size @kbd{--record-size=@var{size}}
335 @set ref-record-size @ref{Blocking}
336 @set xref-record-size @xref{Blocking}
337 @set pxref-record-size @pxref{Blocking}
339 @set op-recursive-unlink @kbd{--recursive-unlink}
340 @set ref-recursive-unlink @ref{Writing}
341 @set xref-recursive-unlink @xref{Writing}
342 @set pxref-recursive-unlink @pxref{Writing}
344 @set op-read-full-records @kbd{--read-full-records} (@kbd{-B})
345 @set ref-read-full-records @ref{Blocking}
346 @set xref-read-full-records @xref{Blocking}
347 @set pxref-read-full-records @pxref{Blocking}
348 @c FIXME: or should it be Reading, or Blocking Factor
350 @set op-remove-files @kbd{--remove-files}
351 @set ref-remove-files @ref{Writing}
352 @set xref-remove-files @xref{Writing}
353 @set pxref-remove-files @pxref{Writing}
355 @set op-rsh-command @kbd{rsh-command=@var{command}}
357 @set op-same-order @kbd{--same-order} (@kbd{--preserve-order}, @kbd{-s})
358 @set ref-same-order @ref{Scarce}
359 @set xref-same-order @xref{Scarce}
360 @set pxref-same-order @pxref{Scarce}
361 @c FIXME: or should it be Reading, or Attributes?
363 @set op-same-owner @kbd{--same-owner}
364 @set ref-same-owner @ref{Attributes}
365 @set xref-same-owner @xref{Attributes}
366 @set pxref-same-owner @pxref{Attributes}
368 @set op-same-permissions @kbd{--same-permissions} (@kbd{--preserve-permissions}, @kbd{-p})
369 @set ref-same-permissions @ref{Attributes}
370 @set xref-same-permissions @xref{Attributes}
371 @set pxref-same-permissions @pxref{Attributes}
372 @c FIXME: or should it be Writing?
374 @set op-show-omitted-dirs @kbd{--show-omitted-dirs}
375 @set ref-show-omitted-dirs @ref{verbose}
376 @set xref-show-omitted-dirs @xref{verbose}
377 @set pxref-show-omitted-dirs @pxref{verbose}
379 @set op-sparse @kbd{--sparse} (@kbd{-S})
380 @set ref-sparse @ref{sparse}
381 @set xref-sparse @xref{sparse}
382 @set pxref-sparse @pxref{sparse}
384 @set op-starting-file @kbd{--starting-file=@var{name}} (@kbd{-K @var{name}})
385 @set ref-starting-file @ref{Scarce}
386 @set xref-starting-file @xref{Scarce}
387 @set pxref-starting-file @pxref{Scarce}
389 @set op-suffix @kbd{--suffix=@var{suffix}}
390 @set ref-suffix @ref{Backup options}
391 @set xref-suffix @xref{Backup options}
392 @set pxref-suffix @pxref{Backup options}
394 @set op-tape-length @kbd{--tape-length=@var{1024-size}} (@kbd{-L @var{1024-size}})
395 @set ref-tape-length @ref{Using Multiple Tapes}
396 @set xref-tape-length @xref{Using Multiple Tapes}
397 @set pxref-tape-length @pxref{Using Multiple Tapes}
399 @set op-to-stdout @kbd{--to-stdout} (@kbd{-O})
400 @set ref-to-stdout @ref{Writing}
401 @set xref-to-stdout @xref{Writing}
402 @set pxref-to-stdout @pxref{Writing}
404 @set op-totals @kbd{--totals}
405 @set ref-totals @ref{verbose}
406 @set xref-totals @xref{verbose}
407 @set pxref-totals @pxref{verbose}
409 @set op-touch @kbd{--touch} (@kbd{-m})
410 @set ref-touch @ref{Writing}
411 @set xref-touch @xref{Writing}
412 @set pxref-touch @pxref{Writing}
414 @set op-unlink-first @kbd{--unlink-first} (@kbd{-U})
415 @set ref-unlink-first @ref{Writing}
416 @set xref-unlink-first @xref{Writing}
417 @set pxref-unlink-first @pxref{Writing}
419 @set op-update @kbd{--update} (@kbd{-u})
420 @set ref-update @ref{update}
421 @set xref-update @xref{update}
422 @set pxref-update @pxref{update}
424 @set op-use-compress-prog @kbd{--use-compress-prog=@var{program}}
425 @set ref-use-compress-prog @ref{gzip}
426 @set xref-use-compress-prog @xref{gzip}
427 @set pxref-use-compress-prog @pxref{gzip}
429 @set op-verbose @kbd{--verbose} (@kbd{-v})
430 @set ref-verbose @ref{verbose}
431 @set xref-verbose @xref{verbose}
432 @set pxref-verbose @pxref{verbose}
434 @set op-verify @kbd{--verify} (@kbd{-W})
435 @set ref-verify @ref{verify}
436 @set xref-verify @xref{verify}
437 @set pxref-verify @pxref{verify}
439 @set op-version @kbd{--version}
440 @set ref-version @ref{help}
441 @set xref-version @xref{help}
442 @set pxref-version @pxref{help}
444 @set op-version-control @kbd{--version-control=@var{method}}
445 @set ref-version-control @ref{Backup options}
446 @set xref-version-control @xref{Backup options}
447 @set pxref-version-control @pxref{Backup options}
449 @set op-volno-file @kbd{--volno-file=@var{file-of-number}}
450 @set ref-volno-file @ref{Using Multiple Tapes}
451 @set xref-volno-file @xref{Using Multiple Tapes}
452 @set pxref-volno-file @pxref{Using Multiple Tapes}
454 @include version.texi
456 @c Put everything in one index (arbitrarily chosen to be the concept index).
468 * tar: (tar). Making tape (or disk) archives.
474 This file documents GNU @code{tar}, a utility used to store, backup, and
477 Copyright 1992, 1994, 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
479 Permission is granted to make and distribute verbatim copies of
480 this manual provided the copyright notice and this permission notice
481 are preserved on all copies.
484 Permission is granted to process this file through TeX and print the
485 results, provided the printed document carries copying permission
486 notice identical to this one except for the removal of this paragraph
487 (this paragraph not being relevant to the printed manual).
490 Permission is granted to copy and distribute modified versions of this
491 manual under the conditions for verbatim copying, provided that the entire
492 resulting derived work is distributed under the terms of a permission
493 notice identical to this one.
495 Permission is granted to copy and distribute translations of this manual
496 into another language, under the above conditions for modified versions,
497 except that this permission notice may be stated in a translation approved
501 @setchapternewpage odd
503 @shorttitlepage GNU @code{tar}
506 @title GNU tar: an archiver tool
507 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
508 @author Melissa Weisshaus, Jay Fenlason,
509 @author Thomas Bushnell, n/BSG, Amy Gorin
510 @c he said to remove it: Fran@,{c}ois Pinard
511 @c i'm thinking about how the author page *should* look. -mew 2may96
514 @vskip 0pt plus 1filll
515 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999 Free Software
518 Permission is granted to make and distribute verbatim copies of
519 this manual provided the copyright notice and this permission notice
520 are preserved on all copies.
522 Permission is granted to copy and distribute modified versions of this
523 manual under the conditions for verbatim copying, provided that the entire
524 resulting derived work is distributed under the terms of a permission
525 notice identical to this one.
527 Permission is granted to copy and distribute translations of this manual
528 into another language, under the above conditions for modified versions,
529 except that this permission notice may be stated in a translation approved
535 This file documents GNU @code{tar}, which is a utility used to store,
536 backup, and transport files. @code{tar} is a tape (or disk) archiver.
537 This manual documents the release @value{VERSION}.
541 @node Top, Introduction, (dir), (dir)
550 * Date input formats::
555 --- The Detailed Node Listing ---
559 * Book Contents:: What this Book Contains
560 * Definitions:: Some Definitions
561 * What tar Does:: What @code{tar} Does
562 * Naming tar Archives:: How @code{tar} Archives are Named
564 * Authors:: GNU @code{tar} Authors
565 * Reports:: Reporting bugs or suggestions
567 Tutorial Introduction to @code{tar}
570 * stylistic conventions::
571 * basic tar options:: Basic @code{tar} Operations and Options
572 * frequent operations::
573 * Two Frequent Options::
574 * create:: How to Create Archives
575 * list:: How to List Archives
576 * extract:: How to Extract Members from an Archive
579 Two Frequently Used Options
585 How to Create Archives
587 * prepare for examples::
588 * Creating the archive::
597 How to Extract Members from an Archive
599 * extracting archives::
604 Invoking GNU @code{tar}
607 * using tar options::
614 The Three Option Styles
616 * Mnemonic Options:: Mnemonic Option Style
617 * Short Options:: Short Option Style
618 * Old Options:: Old Option Style
619 * Mixing:: Mixing Option Styles
621 All @code{tar} Options
623 * Operation Summary::
625 * Short Option Summary::
627 GNU @code{tar} Operations
636 Advanced GNU @code{tar} Operations
646 How to Add Files to Existing Archives: @code{--append}
648 * appending files:: Appending Files to an Archive
655 Options Used by @code{--extract}
657 * Reading:: Options to Help Read Archives
658 * Writing:: Changing How @code{tar} Writes Files
659 * Scarce:: Coping with Scarce Resources
661 Options to Help Read Archives
663 * read full records::
665 * Ignore Failed Read::
667 Changing How @code{tar} Writes Files
669 * Prevention Overwriting::
673 * Modification Times::
674 * Setting Access Permissions::
675 * Writing to Standard Output::
678 Options to Prevent Overwriting Files
684 Coping with Scarce Resources
689 Performing Backups and Restoring Files
691 * Full Dumps:: Using @code{tar} to Perform Full Dumps
692 * Inc Dumps:: Using @code{tar} to Perform Incremental Dumps
693 * incremental and listed-incremental:: The Incremental Options
694 * Backup Levels:: Levels of Backups
695 * Backup Parameters:: Setting Parameters for Backups and Restoration
696 * Scripted Backups:: Using the Backup Scripts
697 * Scripted Restoration:: Using the Restore Script
699 Setting Parameters for Backups and Restoration
701 * backup-specs example:: An Example Text of @file{Backup-specs}
702 * Script Syntax:: Syntax for @file{Backup-specs}
704 Choosing Files and Names for @code{tar}
706 * file:: Choosing the Archive's Name
707 * Selecting Archive Members::
708 * files:: Reading Names from a File
709 * exclude:: Excluding Some Files
711 * after:: Operating Only on New Files
712 * recurse:: Descending into Directories
713 * one:: Crossing Filesystem Boundaries
715 Reading Names from a File
721 * problems with exclude::
723 Crossing Filesystem Boundaries
725 * directory:: Changing Directory
726 * absolute:: Absolute File Names
730 * General date syntax:: Common rules.
731 * Calendar date item:: 19 Dec 1994.
732 * Time of day item:: 9:20pm.
733 * Time zone item:: EST, GMT, UTC, ...
734 * Day of week item:: Monday and others.
735 * Relative item in date strings:: next tuesday, 2 years ago.
736 * Pure numbers in date strings:: 19931219, 1440.
737 * Authors of getdate:: Bellovin, Salz, Berets, et al.
739 Controlling the Archive Format
741 * Portability:: Making @code{tar} Archives More Portable
742 * Compression:: Using Less Space through Compression
743 * Attributes:: Handling File Attributes
744 * Standard:: The Standard Format
745 * Extensions:: GNU Extensions to the Archive Format
746 * cpio:: Comparison of @code{tar} and @code{cpio}
748 Making @code{tar} Archives More Portable
750 * Portable Names:: Portable Names
751 * dereference:: Symbolic Links
752 * old:: Old V7 Archives
753 * posix:: POSIX archives
754 * Checksumming:: Checksumming Problems
756 Using Less Space through Compression
758 * gzip:: Creating and Reading Compressed Archives
759 * sparse:: Archiving Sparse Files
761 Tapes and Other Archive Media
763 * Device:: Device selection and switching
764 * Remote Tape Server::
765 * Common Problems and Solutions::
766 * Blocking:: Blocking
767 * Many:: Many archives on one tape
768 * Using Multiple Tapes:: Using Multiple Tapes
769 * label:: Including a Label in the Archive
775 * Format Variations:: Format Variations
776 * Blocking Factor:: The Blocking Factor of an Archive
778 Many Archives on One Tape
780 * Tape Positioning:: Tape Positions and Tape Marks
781 * mt:: The @code{mt} Utility
785 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
786 * Tape Files:: Tape Files
789 @node Introduction, Tutorial, Top, Top
790 @chapter Introduction
792 Welcome to the GNU @code{tar} manual. GNU @code{tar} is used to create
793 and manipulate files (@dfn{archives}) which are actually collections of
794 many other files; the program provides users with an organized and
795 systematic method for controlling a large amount of data.
798 * Book Contents:: What this Book Contains
799 * Definitions:: Some Definitions
800 * What tar Does:: What @code{tar} Does
801 * Naming tar Archives:: How @code{tar} Archives are Named
803 * Authors:: GNU @code{tar} Authors
804 * Reports:: Reporting bugs or suggestions
807 @node Book Contents, Definitions, Introduction, Introduction
809 @heading What this Book Contains
812 The first part of this chapter introduces you to various terms that will
813 recur throughout the book. It also tells you who has worked on GNU
814 @code{tar} and its documentation, and where you should send bug reports
817 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
818 gentle introduction for people who are new to using @code{tar}. It is
819 meant to be self contained, not requiring any reading from subsequent
820 chapters to make sense. It moves from topic to topic in a logical,
821 progressive order, building on information already explained.
823 Although the tutorial is paced and structured to allow beginners to
824 learn how to use @code{tar}, it is not intended solely for beginners.
825 The tutorial explains how to use the three most frequently used
826 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
827 two frequently used options (@samp{file} and @samp{verbose}). The other
828 chapters do not refer to the tutorial frequently; however, if a section
829 discusses something which is a complex variant of a basic concept, there
830 may be a cross reference to that basic concept. (The entire book,
831 including the tutorial, assumes that the reader understands some basic
832 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
834 The third chapter presents the remaining five operations, and
835 information about using @code{tar} options and option syntax.
837 @FIXME{this sounds more like a GNU Project Manuals Concept [tm] more
838 than the reality. should think about whether this makes sense to say
839 here, or not.} The other chapters are meant to be used as a
840 reference. Each chapter presents everything that needs to be said
841 about a specific topic.
843 One of the chapters (@pxref{Date input formats}) exists in its entirety
844 in other GNU manuals, and is mostly self-contained. In addition, one
845 section of this manual (@pxref{Standard}) contains a big quote which is
846 taken directly from @code{tar} sources.
848 In general, we give both the long and short (abbreviated) option names
849 at least once in each section where the relevant option is covered, so
850 that novice readers will become familiar with both styles. (A few
851 options have no short versions, and the relevant sections will
854 @node Definitions, What tar Does, Book Contents, Introduction
855 @section Some Definitions
859 The @code{tar} program is used to create and manipulate @code{tar}
860 archives. An @dfn{archive} is a single file which contains the contents
861 of many files, while still identifying the names of the files, their
862 owner(s), and so forth. (In addition, archives record access
863 permissions, user and group, size in bytes, and last modification time.
864 Some archives also record the file names in each archived directory, as
865 well as other file and directory information.) You can use @code{tar}
866 to @dfn{create} a new archive in a specified directory.
869 @cindex archive member
872 The files inside an archive are called @dfn{members}. Within this
873 manual, we use the term @dfn{file} to refer only to files accessible in
874 the normal ways (by @code{ls}, @code{cat}, and so forth), and the term
875 @dfn{member} to refer only to the members of an archive. Similarly, a
876 @dfn{file name} is the name of a file, as it resides in the filesystem,
877 and a @dfn{member name} is the name of an archive member within the
882 The term @dfn{extraction} refers to the process of copying an archive
883 member (or multiple members) into a file in the filesystem. Extracting
884 all the members of an archive is often called @dfn{extracting the
885 archive}. The term @dfn{unpack} can also be used to refer to the
886 extraction of many or all the members of an archive. Extracting an
887 archive does not destroy the archive's structure, just as creating an
888 archive does not destroy the copies of the files that exist outside of
889 the archive. You may also @dfn{list} the members in a given archive
890 (this is often thought of as ``printing'' them to the standard output,
891 or the command line), or @dfn{append} members to a pre-existing archive.
892 All of these operations can be performed using @code{tar}.
894 @node What tar Does, Naming tar Archives, Definitions, Introduction
895 @section What @code{tar} Does
898 The @code{tar} program provides the ability to create @code{tar}
899 archives, as well as various other kinds of manipulation. For example,
900 you can use @code{tar} on previously created archives to extract files,
901 to store additional files, or to update or list files which were already
904 Initially, @code{tar} archives were used to store files conveniently on
905 magnetic tape. The name @samp{tar} comes from this use; it stands for
906 @code{t}ape @code{ar}chiver. Despite the utility's name, @code{tar} can
907 direct its output to available devices, files, or other programs (using
908 pipes). @code{tar} may even access remote devices or files (as archives).
910 @FIXME{the following table entries need a bit of work..}
912 You can use @code{tar} archives in many ways. We want to stress a few
913 of them: storage, backup, and transportation.
917 Often, @code{tar} archives are used to store related files for
918 convenient file transfer over a network. For example, the GNU Project
919 distributes its software bundled into @code{tar} archives, so that
920 all the files relating to a particular program (or set of related
921 programs) can be transferred as a single unit.
923 A magnetic tape can store several files in sequence. However, the tape
924 has no names for these files; it only knows their relative position on
925 the tape. One way to store several files on one tape and retain their
926 names is by creating a @code{tar} archive. Even when the basic transfer
927 mechanism can keep track of names, as FTP can, the nuisance of handling
928 multiple files, directories, and multiple links makes @code{tar}
931 Archive files are also used for long-term storage. You can think of
932 this as transportation from the present into the future. (It is a
933 science-fiction idiom that you can move through time as well as in
934 space; the idea here is that @code{tar} can be used to move archives in
935 all dimensions, even time!)
938 Because the archive created by @code{tar} is capable of preserving file
939 information and directory structure, @code{tar} is commonly used for
940 performing full and incremental backups of disks. A backup puts a
941 collection of files (possibly pertaining to many users and
942 projects) together on a disk or a tape. This guards against accidental
943 destruction of the information in those files. GNU @code{tar} has
944 special features that allow it to be used to make incremental and full
945 dumps of all the files in a filesystem.
948 You can create an archive on one system, transfer it to another system,
949 and extract the contents there. This allows you to transport a group of
950 files from one system to another.
953 @node Naming tar Archives, posix compliance, What tar Does, Introduction
954 @section How @code{tar} Archives are Named
956 Conventionally, @code{tar} archives are given names ending with
957 @samp{.tar}. This is not necessary for @code{tar} to operate properly,
958 but this manual follows that convention in order to accustom readers to
959 it and to make examples more clear.
964 Often, people refer to @code{tar} archives as ``@code{tar} files,'' and
965 archive members as ``files'' or ``entries''. For people familiar with
966 the operation of @code{tar}, this causes no difficulty. However, in
967 this manual, we consistently refer to ``archives'' and ``archive
968 members'' to make learning to use @code{tar} easier for novice users.
970 @node posix compliance, Authors, Naming tar Archives, Introduction
971 @section POSIX Compliance
974 @FIXME{must ask franc,ois about this. dan hagerty thinks this might
975 be an issue, but we're not really sure at this time. dan just tried a
976 test case of mixing up options' orders while the variable was set, and
977 there was no problem...}
979 We make some of our recommendations throughout this book for one
980 reason in addition to what we think of as ``good sense''. The main
981 additional reason for a recommendation is to be compliant with the
982 POSIX standards. If you set the shell environment variable
983 @code{POSIXLY_CORRECT}, GNU @code{tar} will force you to adhere to
984 these standards. Therefore, if this variable is set and you violate
985 one of the POSIX standards in the way you phrase a command, for
986 example, GNU @code{tar} will not allow the command and will signal an
987 error message. You would then have to reorder the options or rephrase
988 the command to comply with the POSIX standards.
990 There is a chance in the future that, if you set this environment
991 variable, your archives will be forced to comply with POSIX standards,
992 also. No GNU @code{tar} extensions will be allowed.
994 @node Authors, Reports, posix compliance, Introduction
995 @section GNU @code{tar} Authors
997 GNU @code{tar} was originally written by John Gilmore, and modified by
998 many people. The GNU enhancements were written by Jay Fenlason, then
999 Joy Kendall, and the whole package has been further maintained by
1000 Thomas Bushnell, n/BSG, and finally Fran@,{c}ois Pinard, with
1001 the help of numerous and kind users.
1003 We wish to stress that @code{tar} is a collective work, and owes much to
1004 all those people who reported problems, offered solutions and other
1005 insights, or shared their thoughts and suggestions. An impressive, yet
1006 partial list of those contributors can be found in the @file{THANKS}
1007 file from the GNU @code{tar} distribution.
1009 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
1010 sure i want to spell out the history in this detail, at least not for
1011 the printed book. i'm just not sure it needs to be said this way.
1012 i'll think about it.}
1014 @FIXME{History is more important, and surely more interesting, than
1015 actual names. Quoting names without history would be meaningless. FP}
1017 Jay Fenlason put together a draft of a GNU @code{tar} manual,
1018 borrowing notes from the original man page from John Gilmore. This
1019 was withdrawn in version
1020 1.11. Thomas Bushnell, n/BSG and Amy Gorin worked on a tutorial and
1021 manual for GNU @code{tar}. Fran@,{c}ois Pinard put version 1.11.8
1022 of the manual together by taking information from all these sources
1023 and merging them. Melissa Weisshaus finally edited and redesigned the
1024 book to create version 1.12. @FIXME{update version number as
1025 necessary; i'm being optimistic!} @FIXME{Someone [maybe karl berry?
1026 maybe bob chassell? maybe melissa? maybe julie sussman?] needs to
1027 properly index the thing.}
1029 For version 1.12, Daniel Hagerty contributed a great deal of technical
1030 consulting. In particular, he is the primary author of @ref{Backups}.
1032 @node Reports, , Authors, Introduction
1033 @section Reporting bugs or suggestions
1036 @cindex reporting bugs
1037 If you find problems or have suggestions about this program or manual,
1038 please report them to @file{bug-tar@@gnu.org}.
1040 @node Tutorial, tar invocation, Introduction, Top
1041 @chapter Tutorial Introduction to @code{tar}
1043 This chapter guides you through some basic examples of three @code{tar}
1044 operations: @samp{--create}, @samp{--list}, and @samp{--extract}. If
1045 you already know how to use some other version of @code{tar}, then you
1046 may not need to read this chapter. This chapter omits most complicated
1047 details about how @code{tar} works.
1051 * stylistic conventions::
1052 * basic tar options:: Basic @code{tar} Operations and Options
1053 * frequent operations::
1054 * Two Frequent Options::
1055 * create:: How to Create Archives
1056 * list:: How to List Archives
1057 * extract:: How to Extract Members from an Archive
1061 @node assumptions, stylistic conventions, Tutorial, Tutorial
1063 @heading Assumptions this Tutorial Makes
1066 This chapter is paced to allow beginners to learn about @code{tar}
1067 slowly. At the same time, we will try to cover all the basic aspects of
1068 these three operations. In order to accomplish both of these tasks, we
1069 have made certain assumptions about your knowledge before reading this
1070 manual, and the hardware you will be using:
1074 Before you start to work through this tutorial, you should understand
1075 what the terms ``archive'' and ``archive member'' mean
1076 (@pxref{Definitions}). In addition, you should understand something
1077 about how Unix-type operating systems work, and you should know how to
1078 use some basic utilities. For example, you should know how to create,
1079 list, copy, rename, edit, and delete files and directories; how to
1080 change between directories; and how to figure out where you are in the
1081 filesystem. You should have some basic understanding of directory
1082 structure and how files are named according to which directory they are
1083 in. You should understand concepts such as standard output and standard
1084 input, what various definitions of the term ``argument'' mean, and the
1085 differences between relative and absolute path names. @FIXME{and what
1089 This manual assumes that you are working from your own home directory
1090 (unless we state otherwise). In this tutorial, you will create a
1091 directory to practice @code{tar} commands in. When we show path names,
1092 we will assume that those paths are relative to your home directory.
1093 For example, my home directory path is @file{/home/fsf/melissa}. All of
1094 my examples are in a subdirectory of the directory named by that path
1095 name; the subdirectory is called @file{practice}.
1098 In general, we show examples of archives which exist on (or can be
1099 written to, or worked with from) a directory on a hard disk. In most
1100 cases, you could write those archives to, or work with them on any other
1101 device, such as a tape drive. However, some of the later examples in
1102 the tutorial and next chapter will not work on tape drives.
1103 Additionally, working with tapes is much more complicated than working
1104 with hard disks. For these reasons, the tutorial does not cover working
1105 with tape drives. @xref{Media}, for complete information on using
1106 @code{tar} archives with tape drives.
1108 @FIXME{this is a cop out. need to add some simple tape drive info.}
1111 @node stylistic conventions, basic tar options, assumptions, Tutorial
1113 @heading Stylistic Conventions
1116 In the examples, @samp{$} represents a typical shell prompt. It
1117 precedes lines you should type; to make this more clear, those lines are
1118 shown in @kbd{this font}, as opposed to lines which represent the
1119 computer's response; those lines are shown in @code{this font}, or
1120 sometimes @samp{like this}. When we have lines which are too long to be
1121 displayed in any other way, we will show them like this:
1124 This is an example of a line which would otherwise not fit in this space.
1127 @FIXME{how often do we use smallexample?}
1129 @node basic tar options, frequent operations, stylistic conventions, Tutorial
1130 @section Basic @code{tar} Operations and Options
1132 @code{tar} can take a wide variety of arguments which specify and define
1133 the actions it will have on the particular set of files or the archive.
1134 The main types of arguments to @code{tar} fall into one of two classes:
1135 operations, and options.
1137 Some arguments fall into a class called @dfn{operations}; exactly one of
1138 these is both allowed and required for any instance of using @code{tar};
1139 you may @emph{not} specify more than one. People sometimes speak of
1140 @dfn{operating modes}. You are in a particular operating mode when you
1141 have specified the operation which specifies it; there are eight
1142 operations in total, and thus there are eight operating modes.
1144 The other arguments fall into the class known as @dfn{options}. You are
1145 not required to specify any options, and you are allowed to specify more
1146 than one at a time (depending on the way you are using @code{tar} at
1147 that time). Some options are used so frequently, and are so useful for
1148 helping you type commands more carefully that they are effectively
1149 ``required''. We will discuss them in this chapter.
1151 You can write most of the @code{tar} operations and options in any of
1152 three forms: long (mnemonic) form, short form, and old style. Some of
1153 the operations and options have no short or ``old'' forms; however, the
1154 operations and options which we will cover in this tutorial have
1155 corresponding abbreviations. @FIXME{make sure this is still the case,
1156 at the end}We will indicate those abbreviations appropriately to get
1157 you used to seeing them. (Note that the ``old style'' option forms
1158 exist in GNU @code{tar} for compatibility with Unix @code{tar}. We
1159 present a full discussion of this way of writing options and operations
1160 appears in @ref{Old Options}, and we discuss the other two styles of
1161 writing options in @ref{Mnemonic Options} and @ref{Short Options}.)
1163 In the examples and in the text of this tutorial, we usually use the
1164 long forms of operations and options; but the ``short'' forms produce
1165 the same result and can make typing long @code{tar} commands easier.
1166 For example, instead of typing
1169 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
1175 @kbd{tar -c -v -f afiles.tar apple angst aspic}
1181 @kbd{tar -cvf afiles.tar apple angst aspic}
1185 For more information on option syntax, see @ref{Advanced tar}. In
1186 discussions in the text, when we name an option by its long form, we
1187 also give the corresponding short option in parentheses.
1189 The term, ``option'', can be confusing at times, since ``operations''
1190 are often lumped in with the actual, @emph{optional} ``options'' in certain
1191 general class statements. For example, we just talked about ``short and
1192 long forms of options and operations''. However, experienced @code{tar}
1193 users often refer to these by shorthand terms such as, ``short and long
1194 options''. This term assumes that the ``operations'' are included, also.
1195 Context will help you determine which definition of ``options'' to use.
1197 Similarly, the term ``command'' can be confusing, as it is often used in
1198 two different ways. People sometimes refer to @code{tar} ``commands''.
1199 A @code{tar} @dfn{command} is the entire command line of user input
1200 which tells @code{tar} what to do --- including the operation, options,
1201 and any arguments (file names, pipes, other commands, etc). However,
1202 you will also sometimes hear the term ``the @code{tar} command''. When
1203 the word ``command'' is used specifically like this, a person is usually
1204 referring to the @code{tar} @emph{operation}, not the whole line.
1205 Again, use context to figure out which of the meanings the speaker
1208 @node frequent operations, Two Frequent Options, basic tar options, Tutorial
1209 @section The Three Most Frequently Used Operations
1211 Here are the three most frequently used operations (both short and long
1212 forms), as well as a brief description of their meanings. The rest of
1213 this chapter will cover how to use these operations in detail. We will
1214 present the rest of the operations in the next chapter.
1219 Create a new @code{tar} archive.
1222 List the contents of an archive.
1225 Extract one or more members from an archive.
1228 @node Two Frequent Options, create, frequent operations, Tutorial
1229 @section Two Frequently Used Options
1231 To understand how to run @code{tar} in the three operating modes listed
1232 previously, you also need to understand how to use two of the options to
1233 @code{tar}: @samp{--file} (which takes an archive file as an argument)
1234 and @samp{--verbose}. (You are usually not @emph{required} to specify
1235 either of these options when you run @code{tar}, but they can be very
1236 useful in making things more clear and helping you avoid errors.)
1240 * verbose tutorial::
1244 @node file tutorial, verbose tutorial, Two Frequent Options, Two Frequent Options
1245 @unnumberedsubsec The @samp{--file} Option
1248 @item --file=@var{archive-name}
1249 @itemx -f @var{archive-name}
1250 Specify the name of an archive file.
1253 You can specify an argument for the @value{op-file} option whenever you
1254 use @code{tar}; this option determines the name of the archive file
1255 that @code{tar} will work on.
1257 If you don't specify this argument, then @code{tar} will use a
1258 default, usually some physical tape drive attached to your machine.
1259 If there is no tape drive attached, or the default is not meaningful,
1260 then @code{tar} will print an error message. The error message might
1261 look roughly like one of the following:
1264 tar: can't open /dev/rmt8 : No such device or address
1265 tar: can't open /dev/rsmt0 : I/O error
1269 To avoid confusion, we recommend that you always specify an archive file
1270 name by using @value{op-file} when writing your @code{tar} commands.
1271 For more information on using the @value{op-file} option, see
1274 @node verbose tutorial, help tutorial, file tutorial, Two Frequent Options
1275 @unnumberedsubsec The @samp{--verbose} Option
1280 Show the files being worked on as @code{tar} is running.
1283 @value{op-verbose} shows details about the results of running
1284 @code{tar}. This can be especially useful when the results might not be
1285 obvious. For example, if you want to see the progress of @code{tar} as
1286 it writes files into the archive, you can use the @samp{--verbose}
1287 option. In the beginning, you may find it useful to use
1288 @samp{--verbose} at all times; when you are more accustomed to
1289 @code{tar}, you will likely want to use it at certain times but not at
1290 others. We will use @samp{--verbose} at times to help make something
1291 clear, and we will give many examples both using and not using
1292 @samp{--verbose} to show the differences.
1294 Sometimes, a single instance of @samp{--verbose} on the command line
1295 will show a full, @samp{ls} style listing of an archive or files,
1296 giving sizes, owners, and similar information. Other times,
1297 @samp{--verbose} will only show files or members that the particular
1298 operation is operating on at the time. In the latter case, you can
1299 use @samp{--verbose} twice in a command to get a listing such as that
1300 in the former case. For example, instead of saying
1303 @kbd{tar -cvf afiles.tar apple angst aspic}
1307 above, you might say
1310 @kbd{tar -cvvf afiles.tar apple angst aspic}
1314 This works equally well using short or long forms of options. Using
1315 long forms, you would simply write out the mnemonic form of the option
1319 $ @kbd{tar --create --verbose --verbose @dots{}}
1323 Note that you must double the hyphens properly each time.
1325 Later in the tutorial, we will give examples using @w{@samp{--verbose
1328 @node help tutorial, , verbose tutorial, Two Frequent Options
1329 @unnumberedsubsec Getting Help: Using the @code{--help} Option
1334 The @samp{--help} option to @code{tar} prints out a very brief list of
1335 all operations and option available for the current version of
1336 @code{tar} available on your system.
1339 @node create, list, Two Frequent Options, Tutorial
1340 @section How to Create Archives
1343 One of the basic operations of @code{tar} is @value{op-create}, which
1344 you use to create a @code{tar} archive. We will explain
1345 @samp{--create} first because, in order to learn about the other
1346 operations, you will find it useful to have an archive available to
1349 To make this easier, in this section you will first create a directory
1350 containing three files. Then, we will show you how to create an
1351 @emph{archive} (inside the new directory). Both the directory, and
1352 the archive are specifically for you to practice on. The rest of this
1353 chapter and the next chapter will show many examples using this
1354 directory and the files you will create: some of those files may be
1355 other directories and other archives.
1357 The three files you will archive in this example are called
1358 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1359 @file{collection.tar}.
1361 This section will proceed slowly, detailing how to use @samp{--create}
1362 in @code{verbose} mode, and showing examples using both short and long
1363 forms. In the rest of the tutorial, and in the examples in the next
1364 chapter, we will proceed at a slightly quicker pace. This section
1365 moves more slowly to allow beginning users to understand how
1369 * prepare for examples::
1370 * Creating the archive::
1376 @node prepare for examples, Creating the archive, create, create
1377 @subsection Preparing a Practice Directory for Examples
1379 To follow along with this and future examples, create a new directory
1380 called @file{practice} containing files called @file{blues}, @file{folk}
1381 and @file{jazz}. The files can contain any information you like:
1382 ideally, they should contain information which relates to their names,
1383 and be of different lengths. Our examples assume that @file{practice}
1384 is a subdirectory of your home directory.
1386 Now @code{cd} to the directory named @file{practice}; @file{practice}
1387 is now your @dfn{working directory}. (@emph{Please note}: Although
1388 the full path name of this directory is
1389 @file{/@var{homedir}/practice}, in our examples we will refer to
1390 this directory as @file{practice}; the @var{homedir} is presumed.
1392 In general, you should check that the files to be archived exist where
1393 you think they do (in the working directory) by running @code{ls}.
1394 Because you just created the directory and the files and have changed to
1395 that directory, you probably don't need to do that this time.
1397 It is very important to make sure there isn't already a file in the
1398 working directory with the archive name you intend to use (in this case,
1399 @samp{collection.tar}), or that you don't care about its contents.
1400 Whenever you use @samp{create}, @code{tar} will erase the current
1401 contents of the file named by @value{op-file} if it exists. @code{tar}
1402 will not tell you if you are about to overwrite a file unless you
1403 specify an option which does this. @FIXME{xref to the node for
1404 --backup!}To add files to an existing archive, you need to use a
1405 different option, such as @value{op-append}; see @ref{append} for
1406 information on how to do this.
1408 @node Creating the archive, create verbose, prepare for examples, create
1409 @subsection Creating the Archive
1411 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1412 archive named @file{collection.tar}, use the following command:
1415 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1418 The order of the arguments is not very important, @emph{when using long
1419 option forms}. You could also say:
1422 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1426 However, you can see that this order is harder to understand; this is
1427 why we will list the arguments in the order that makes the commands
1428 easiest to understand (and we encourage you to do the same when you use
1429 @code{tar}, to avoid errors).
1431 Note that the part of the command which says,
1432 @w{@kbd{--file=collection.tar}} is considered to be @emph{one} argument.
1433 If you substituted any other string of characters for
1434 @kbd{`collection.tar'}, then that string would become the name of the
1435 archive file you create.
1437 The order of the options becomes more important when you begin to use
1438 short forms. With short forms, if you type commands in the wrong order
1439 (even if you type them correctly in all other ways), you may end up with
1440 results you don't expect. For this reason, it is a good idea to get
1441 into the habit of typing options in the order that makes inherent sense.
1442 @xref{short create}, for more information on this.
1444 In this example, you type the command as shown above: @samp{--create}
1445 is the operation which creates the new archive
1446 (@file{collection.tar}), and @samp{--file} is the option which lets
1447 you give it the name you chose. The files, @file{blues}, @file{folk},
1448 and @file{jazz}, are now members of the archive, @file{collection.tar}
1449 (they are @dfn{file name arguments} to the @samp{--create} operation).
1450 @FIXME{xref here to the discussion of file name args?}Now that they are
1451 in the archive, they are called @emph{archive members}, not files.
1452 @FIXME{xref to definitions?}
1454 When you create an archive, you @emph{must} specify which files you want
1455 placed in the archive. If you do not specify any archive members, GNU
1456 @code{tar} will complain.
1458 If you now list the contents of the working directory (@kbd{ls}), you will
1459 find the archive file listed as well as the files you saw previously:
1462 blues folk jazz collection.tar
1466 Creating the archive @samp{collection.tar} did not destroy the copies of
1467 the files in the directory.
1469 Keep in mind that if you don't indicate an operation, @code{tar} will not
1470 run and will prompt you for one. If you don't name any files, @code{tar}
1471 will complain. You must have write access to the working directory,
1472 or else you will not be able to create an archive in that directory.
1474 @emph{Caution}: Do not attempt to use @value{op-create} to add files to
1475 an existing archive; it will delete the archive and write a new one.
1476 Use @value{op-append} instead. @xref{append}.
1478 @node create verbose, short create, Creating the archive, create
1479 @subsection Running @samp{--create} with @samp{--verbose}
1481 If you include the @value{op-verbose} option on the command line,
1482 @code{tar} will list the files it is acting on as it is working. In
1483 verbose mode, the @code{create} example above would appear as:
1486 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1492 This example is just like the example we showed which did not use
1493 @samp{--verbose}, except that @code{tar} generated the remaining lines
1495 (note the different font styles).
1501 In the rest of the examples in this chapter, we will frequently use
1502 @code{verbose} mode so we can show actions or @code{tar} responses that
1503 you would otherwise not see, and which are important for you to
1506 @node short create, create dir, create verbose, create
1507 @subsection Short Forms with @samp{create}
1509 As we said before, the @value{op-create} operation is one of the most
1510 basic uses of @code{tar}, and you will use it countless times.
1511 Eventually, you will probably want to use abbreviated (or ``short'')
1512 forms of options. A full discussion of the three different forms that
1513 options can take appears in @ref{Styles}; for now, here is what the
1514 previous example (including the @value{op-verbose} option) looks like
1515 using short option forms:
1518 $ @kbd{tar -cvf collection.tar blues folk jazz}
1525 As you can see, the system responds the same no matter whether you use
1526 long or short option forms.
1528 @FIXME{i don't like how this is worded:} One difference between using
1529 short and long option forms is that, although the exact placement of
1530 arguments following options is no more specific when using short forms,
1531 it is easier to become confused and make a mistake when using short
1532 forms. For example, suppose you attempted the above example in the
1536 $ @kbd{tar -cfv collection.tar blues folk jazz}
1540 In this case, @code{tar} will make an archive file called @file{v},
1541 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1542 the @samp{v} is the closest ``file name'' to the @samp{-f} option, and
1543 is thus taken to be the chosen archive file name. @code{tar} will try
1544 to add a file called @file{collection.tar} to the @file{v} archive file;
1545 if the file @file{collection.tar} did not already exist, @code{tar} will
1546 report an error indicating that this file does not exist. If the file
1547 @file{collection.tar} does already exist (e.g., from a previous command
1548 you may have run), then @code{tar} will add this file to the archive.
1549 Because the @samp{-v} option did not get registered, @code{tar} will not
1550 run under @samp{verbose} mode, and will not report its progress.
1552 The end result is that you may be quite confused about what happened,
1553 and possibly overwrite a file. To illustrate this further, we will show
1554 you how an example we showed previously would look using short forms.
1559 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1563 is confusing as it is. When shown using short forms, however, it
1564 becomes much more so:
1567 $ @kbd{tar blues -c folk -f collection.tar jazz}
1571 It would be very easy to put the wrong string of characters
1572 immediately following the @samp{-f}, but doing that could sacrifice
1575 For this reason, we recommend that you pay very careful attention to
1576 the order of options and placement of file and archive names,
1577 especially when using short option forms. Not having the option name
1578 written out mnemonically can affect how well you remember which option
1579 does what, and therefore where different names have to be placed.
1580 (Placing options in an unusual order can also cause @code{tar} to
1581 report an error if you have set the shell environment variable,
1582 @code{POSIXLY_CORRECT}; @pxref{posix compliance} for more information
1585 @node create dir, , short create, create
1586 @subsection Archiving Directories
1588 @cindex Archiving Directories
1589 @cindex Directories, Archiving
1590 You can archive a directory by specifying its directory name as a
1591 file name argument to @code{tar}. The files in the directory will be
1592 archived relative to the working directory, and the directory will be
1593 re-created along with its contents when the archive is extracted.
1595 To archive a directory, first move to its superior directory. If you
1596 have followed the previous instructions in this tutorial, you should
1605 This will put you into the directory which contains @file{practice},
1606 i.e. your home directory. Once in the superior directory, you can
1607 specify the subdirectory, @file{practice}, as a file name argument. To
1608 store @file{practice} in the new archive file @file{music.tar}, type:
1611 $ @kbd{tar --create --verbose --file=music.tar practice}
1615 @code{tar} should output:
1622 practice/collection.tar
1625 Note that the archive thus created is not in the subdirectory
1626 @file{practice}, but rather in the current working directory---the
1627 directory from which @code{tar} was invoked. Before trying to archive a
1628 directory from its superior directory, you should make sure you have
1629 write access to the superior directory itself, not only the directory
1630 you are trying archive with @code{tar}. For example, you will probably
1631 not be able to store your home directory in an archive by invoking
1632 @code{tar} from the root directory; @value{xref-absolute-names}. (Note
1633 also that @file{collection.tar}, the original archive file, has itself
1634 been archived. @code{tar} will accept any file as a file to be
1635 archived, regardless of its content. When @file{music.tar} is
1636 extracted, the archive file @file{collection.tar} will be re-written
1637 into the file system).
1639 If you give @code{tar} a command such as
1642 $ @kbd{tar --create --file=foo.tar .}
1646 @code{tar} will report @samp{tar: ./foo.tar is the archive; not dumped}.
1647 This happens because @code{tar} creates the archive @file{foo.tar} in
1648 the current directory before putting any files into it. Then, when
1649 @code{tar} attempts to add all the files in the directory @file{.} to
1650 the archive, it notices that the file @file{./foo.tar} is the same as the
1651 archive @file{foo.tar}, and skips it. (It makes no sense to put an archive
1652 into itself.) GNU @code{tar} will continue in this case, and create the
1653 archive normally, except for the exclusion of that one file.
1654 (@emph{Please note:} Other versions of @code{tar} are not so clever;
1655 they will enter an infinite loop when this happens, so you should not
1656 depend on this behavior unless you are certain you are running GNU
1657 @code{tar}.) @FIXME{bob doesn't like this sentence, since he does it
1658 all the time, and we've been doing it in the editing passes for this
1659 manual: In general, make sure that the archive is not inside a
1660 directory being dumped.}
1662 @node list, extract, create, Tutorial
1663 @section How to List Archives
1665 Frequently, you will find yourself wanting to determine exactly what a
1666 particular archive contains. You can use the @value{op-list} operation
1667 to get the member names as they currently appear in the archive, as well
1668 as various attributes of the files at the time they were archived. For
1669 example, you can examine the archive @file{collection.tar} that you
1670 created in the last section with the command,
1673 $ @kbd{tar --list --file=collection.tar}
1677 The output of @code{tar} would then be:
1685 @FIXME{we hope this will change. if it doesn't, need to show the
1686 creation of bfiles somewhere above!!! : }
1689 The archive @file{bfiles.tar} would list as follows:
1698 Be sure to use a @value{op-file} option just as with @value{op-create}
1699 to specify the name of the archive.
1701 If you use the @value{op-verbose} option with @samp{--list}, then
1702 @code{tar} will print out a listing reminiscent of @w{@samp{ls -l}},
1703 showing owner, file size, and so forth.
1705 If you had used @value{op-verbose} mode, the example above would look
1709 $ @kbd{tar --list --verbose --file=collection.tar folk}
1710 -rw-rw-rw- myself user 62 1990-05-23 10:55 folk
1713 @cindex File name arguments, using @code{--list} with
1714 @cindex @code{--list} with file name arguments
1715 You can specify one or more individual member names as arguments when
1716 using @samp{list}. In this case, @code{tar} will only list the
1717 names of members you identify. For example, @w{@kbd{tar --list
1718 --file=afiles.tar apple}} would only print @file{apple}.
1720 @FIXME{we hope the relevant aspects of this will change:}Because
1721 @code{tar} preserves paths, file names must be specified as they appear
1722 in the archive (ie., relative to the directory from which the archive
1723 was created). Therefore, it is essential when specifying member names
1724 to @code{tar} that you give the exact member names. For example,
1725 @w{@kbd{tar --list --file=bfiles birds}} would produce an error message
1726 something like @samp{tar: birds: Not found in archive}, because there is
1727 no member named @file{birds}, only one named @file{./birds}. While the
1728 names @file{birds} and @file{./birds} name the same file, @emph{member}
1729 names are compared using a simplistic name comparison, in which an exact
1730 match is necessary. @xref{absolute}.
1732 However, @w{@kbd{tar --list --file=collection.tar folk}} would respond
1733 with @file{folk}, because @file{folk} is in the archive file
1734 @file{collection.tar}. If you are not sure of the exact file name, try
1735 listing all the files in the archive and searching for the one you
1736 expect to find; remember that if you use @samp{--list} with no file
1737 names as arguments, @code{tar} will print the names of all the members
1738 stored in the specified archive.
1744 @node list dir, , list, list
1745 @unnumberedsubsec Listing the Contents of a Stored Directory
1748 @FIXME{i changed the order of these nodes around and haven't had a
1749 chance to play around with this node's example, yet. i have to play
1750 with it and see what it actually does for my own satisfaction, even if
1751 what it says *is* correct..}
1753 To get information about the contents of an archived directory,
1754 use the directory name as a file name argument in conjunction with
1755 @value{op-list}. To find out file attributes, include the
1756 @value{op-verbose} option.
1758 For example, to find out about files in the directory @file{practice}, in
1759 the archive file @file{music.tar}, type:
1762 $ @kbd{tar --list --verbose --file=music.tar practice}
1765 @code{tar} responds:
1768 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1769 -rw-rw-rw- myself user 42 1990-05-21 13:29 practice/blues
1770 -rw-rw-rw- myself user 62 1990-05-23 10:55 practice/folk
1771 -rw-rw-rw- myself user 40 1990-05-21 13:30 practice/jazz
1772 -rw-rw-rw- myself user 10240 1990-05-31 21:49 practice/collection.tar
1775 When you use a directory name as a file name argument, @code{tar} acts on
1776 all the files (including sub-directories) in that directory.
1778 @node extract, going further, list, Tutorial
1779 @section How to Extract Members from an Archive
1782 @cindex Retrieving files from an archive
1783 @cindex Resurrecting files from an archive
1785 Creating an archive is only half the job---there is no point in storing
1786 files in an archive if you can't retrieve them. The act of retrieving
1787 members from an archive so they can be used and manipulated as
1788 unarchived files again is called @dfn{extraction}. To extract files
1789 from an archive, use the @value{op-extract} operation. As with
1790 @value{op-create}, specify the name of the archive with @value{op-file}.
1791 Extracting an archive does not modify the archive in any way; you can
1792 extract it multiple times if you want or need to.
1794 Using @samp{--extract}, you can extract an entire archive, or specific
1795 files. The files can be directories containing other files, or not. As
1796 with @value{op-create} and @value{op-list}, you may use the short or the
1797 long form of the operation without affecting the performance.
1800 * extracting archives::
1801 * extracting files::
1803 * failing commands::
1806 @node extracting archives, extracting files, extract, extract
1807 @subsection Extracting an Entire Archive
1809 To extract an entire archive, specify the archive file name only, with
1810 no individual file names as arguments. For example,
1813 $ @kbd{tar -xvf collection.tar}
1820 -rw-rw-rw- me user 28 1996-10-18 16:31 jazz
1821 -rw-rw-rw- me user 21 1996-09-23 16:44 blues
1822 -rw-rw-rw- me user 20 1996-09-23 16:44 folk
1825 @node extracting files, extract dir, extracting archives, extract
1826 @subsection Extracting Specific Files
1828 To extract specific archive members, give their exact member names as
1829 arguments, as printed by @value{op-list}. If you had mistakenly deleted
1830 one of the files you had placed in the archive @file{collection.tar}
1831 earlier (say, @file{blues}), you can extract it from the archive without
1832 changing the archive's structure. It will be identical to the original
1833 file @file{blues} that you deleted. @FIXME{check this; will the times,
1834 permissions, owner, etc be the same, also?}
1836 First, make sure you are in the @file{practice} directory, and list the
1837 files in the directory. Now, delete the file, @samp{blues}, and list
1838 the files in the directory again.
1840 You can now extract the member @file{blues} from the archive file
1841 @file{collection.tar} like this:
1844 $ @kbd{tar --extract --file=collection.tar blues}
1848 If you list the files in the directory again, you will see that the file
1849 @file{blues} has been restored, with its original permissions, creation
1850 times, and owner.@FIXME{This is only accidentally true, but not in
1851 general. In most cases, one has to be root for restoring the owner, and
1852 use a special option for restoring permissions. Here, it just happens
1853 that the restoring user is also the owner of the archived members, and
1854 that the current @code{umask} is compatible with original permissions.}
1855 (These parameters will be identical to those which
1856 the file had when you originally placed it in the archive; any changes
1857 you may have made before deleting the file from the file system,
1858 however, will @emph{not} have been made to the archive member.) The
1859 archive file, @samp{collection.tar}, is the same as it was before you
1860 extracted @samp{blues}. You can confirm this by running @code{tar} with
1863 @FIXME{we hope this will change:}Remember that as with other operations,
1864 specifying the exact member name is important. @w{@kbd{tar --extract
1865 --file=bfiles.tar birds}} will fail, because there is no member named
1866 @file{birds}. To extract the member named @file{./birds}, you must
1867 specify @w{@kbd{tar --extract --file=bfiles.tar ./birds}}. To find the
1868 exact member names of the members of an archive, use @value{op-list}
1871 If you give the @value{op-verbose} option, then @value{op-extract} will
1872 print the names of the archive members as it extracts them.
1874 @node extract dir, failing commands, extracting files, extract
1875 @subsection Extracting Files that are Directories
1877 Extracting directories which are members of an archive is similar to
1878 extracting other files. The main difference to be aware of is that if
1879 the extracted directory has the same name as any directory already in
1880 the working directory, then files in the extracted directory will be
1881 placed into the directory of the same name. Likewise, if there are
1882 files in the pre-existing directory with the same names as the members
1883 which you extract, the files from the extracted archive will overwrite
1884 the files already in the working directory (and possible
1885 subdirectories). This will happen regardless of whether or not the
1886 files in the working directory were more recent than those extracted.
1888 However, if a file was stored with a directory name as part of its file
1889 name, and that directory does not exist under the working directory when
1890 the file is extracted, @code{tar} will create the directory.
1892 We can demonstrate how to use @samp{--extract} to extract a directory
1893 file with an example. Change to the @file{practice} directory if you
1894 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1895 go back to the parent directory and extract the archive
1896 @file{music.tar}. You may either extract the entire archive, or you may
1897 extract only the files you just deleted. To extract the entire archive,
1898 don't give any file names as arguments after the archive name
1899 @file{music.tar}. To extract only the files you deleted, use the
1903 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1906 @FIXME{need to show tar's response; used verbose above. also, here's a
1907 good place to demonstrate the -v -v thing. have to write that up
1908 (should be trivial, but i'm too tired!).}
1911 Because you created the directory with @file{practice} as part of the
1912 file names of each of the files by archiving the @file{practice}
1913 directory as @file{practice}, you must give @file{practice} as part
1914 of the file names when you extract those files from the archive.
1916 @FIXME{IMPORTANT! show the final structure, here. figure out what it
1919 @node failing commands, , extract dir, extract
1920 @subsection Commands That Will Fail
1922 Here are some sample commands you might try which will not work, and why
1925 If you try to use this command,
1928 $ @kbd{tar -xvf music.tar folk jazz}
1932 you will get the following response:
1935 tar: folk: Not found in archive
1936 tar: jazz: Not found in archive
1941 This is because these files were not originally @emph{in} the parent
1942 directory @file{..}, where the archive is located; they were in the
1943 @file{practice} directory, and their file names reflect this:
1946 $ @kbd{tar -tvf music.tar}
1952 @FIXME{make sure the above works when going through the examples in
1956 Likewise, if you try to use this command,
1959 $ @kbd{tar -tvf music.tar folk jazz}
1963 you would get a similar response. Members with those names are not in the
1964 archive. You must use the correct member names in order to extract the
1965 files from the archive.
1967 If you have forgotten the correct names of the files in the archive,
1968 use @w{@kbd{tar --list --verbose}} to list them correctly.
1970 @FIXME{more examples, here? hag thinks it's a good idea.}
1972 @node going further, , extract, Tutorial
1973 @section Going Further Ahead in this Manual
1975 @FIXME{need to write up a node here about the things that are going to
1976 be in the rest of the manual.}
1978 @node tar invocation, operations, Tutorial, Top
1979 @chapter Invoking GNU @code{tar}
1982 This chapter is about how one invokes the GNU @code{tar} command, from
1983 the command synopsis (@pxref{Synopsis}). There are numerous options,
1984 and many styles for writing them. One mandatory option specifies
1985 the operation @code{tar} should perform (@pxref{Operation Summary}),
1986 other options are meant to detail how this operation should be performed
1987 (@pxref{Option Summary}). Non-option arguments are not always interpreted
1988 the same way, depending on what the operation is.
1990 You will find in this chapter everything about option styles and rules for
1991 writing them (@pxref{Styles}). On the other hand, operations and options
1992 are fully described elsewhere, in other chapters. Here, you will find
1993 only synthetic descriptions for operations and options, together with
1994 pointers to other parts of the @code{tar} manual.
1996 Some options are so special they are fully described right in this
1997 chapter. They have the effect of inhibiting the normal operation of
1998 @code{tar} or else, they globally alter the amount of feedback the user
1999 receives about what is going on. These are the @value{op-help} and
2000 @value{op-version} (@pxref{help}), @value{op-verbose} (@pxref{verbose})
2001 and @value{op-interactive} options (@pxref{interactive}).
2005 * using tar options::
2013 @node Synopsis, using tar options, tar invocation, tar invocation
2014 @section General Synopsis of @code{tar}
2016 The GNU @code{tar} program is invoked as either one of:
2019 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
2020 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
2023 The second form is for when old options are being used.
2025 You can use @code{tar} to store files in an archive, to extract them from
2026 an archive, and to do other types of archive manipulation. The primary
2027 argument to @code{tar}, which is called the @dfn{operation}, specifies
2028 which action to take. The other arguments to @code{tar} are either
2029 @dfn{options}, which change the way @code{tar} performs an operation,
2030 or file names or archive members, which specify the files or members
2031 @code{tar} is to act on.
2033 You can actually type in arguments in any order, even if in this manual
2034 the options always precede the other arguments, to make examples easier
2035 to understand. Further, the option stating the main operation mode
2036 (the @code{tar} main command) is usually given first.
2038 Each @var{name} in the synopsis above is interpreted as an archive member
2039 name when the main command is one of @value{op-compare}, @value{op-delete},
2040 @value{op-extract}, @value{op-list} or @value{op-update}. When naming
2041 archive members, you must give the exact name of the member in the
2042 archive, as it is printed by @value{op-list}. For @value{op-append}
2043 and @value{op-create}, these @var{name} arguments specify the names
2044 of either files or directory hierarchies to place in the archive.
2045 These files or hierarchies should already exist in the file system,
2046 prior to the execution of the @code{tar} command.
2048 @code{tar} interprets relative file names as being relative to the
2049 working directory. @code{tar} will make all file names relative
2050 (by removing leading slashes when archiving or restoring files),
2051 unless you specify otherwise (using the @value{op-absolute-names}
2052 option). @value{xref-absolute-names}, for more information about
2053 @value{op-absolute-names}.
2055 If you give the name of a directory as either a file name or a member
2056 name, then @code{tar} acts recursively on all the files and directories
2057 beneath that directory. For example, the name @file{/} identifies all
2058 the files in the filesystem to @code{tar}.
2060 The distinction between file names and archive member names is especially
2061 important when shell globbing is used, and sometimes a source of confusion
2062 for newcomers. @xref{Wildcards}, for more information about globbing.
2063 The problem is that shells may only glob using existing files in the
2064 file system. Only @code{tar} itself may glob on archive members, so when
2065 needed, you must ensure that wildcard characters reach @code{tar} without
2066 being interpreted by the shell first. Using a backslash before @samp{*}
2067 or @samp{?}, or putting the whole argument between quotes, is usually
2068 sufficient for this.
2070 Even if @var{name}s are often specified on the command line, they
2071 can also be read from a text file in the file system, using the
2072 @value{op-files-from} option.
2074 If you don't use any file name arguments, @value{op-append},
2075 @value{op-delete} and @value{op-concatenate} will do nothing, while
2076 @value{op-create} will usually yield a diagnostic and inhibit @code{tar}
2077 execution. The other operations of @code{tar} (@value{op-list},
2078 @value{op-extract}, @value{op-compare}, and @value{op-update}) will act
2079 on the entire contents of the archive.
2082 @cindex return status
2083 Besides successful exits, GNU @code{tar} may fail for many reasons.
2084 Some reasons correspond to bad usage, that is, when the @code{tar}
2085 command is improperly written.
2086 Errors may be encountered later, while encountering an error
2087 processing the archive or the files. Some errors are recoverable,
2088 in which case the failure is delayed until @code{tar} has completed
2089 all its work. Some errors are such that it would not meaningful,
2090 or at least risky, to continue processing: @code{tar} then aborts
2091 processing immediately. All abnormal exits, whether immediate or
2092 delayed, should always be clearly diagnosed on @code{stderr}, after
2093 a line stating the nature of the error.
2095 GNU @code{tar} returns only a few exit statuses. I'm really
2096 aiming simplicity in that area, for now. If you are not using the
2097 @value{op-compare} option, zero means that everything went well, besides
2098 maybe innocuous warnings. Nonzero means that something went wrong.
2099 Right now, as of today, ``nonzero'' is almost always 2, except for
2100 remote operations, where it may be 128.
2102 @node using tar options, Styles, Synopsis, tar invocation
2103 @section Using @code{tar} Options
2105 GNU @code{tar} has a total of eight operating modes which allow you to
2106 perform a variety of tasks. You are required to choose one operating
2107 mode each time you employ the @code{tar} program by specifying one, and
2108 only one operation as an argument to the @code{tar} command (two lists
2109 of four operations each may be found at @ref{frequent operations} and
2110 @ref{Operations}). Depending on circumstances, you may also wish to
2111 customize how the chosen operating mode behaves. For example, you may
2112 wish to change the way the output looks, or the format of the files that
2113 you wish to archive may require you to do something special in order to
2114 make the archive look right.
2116 You can customize and control @code{tar}'s performance by running
2117 @code{tar} with one or more options (such as @value{op-verbose}, which
2118 we used in the tutorial). As we said in the tutorial, @dfn{options} are
2119 arguments to @code{tar} which are (as their name suggests) optional.
2120 Depending on the operating mode, you may specify one or more options.
2121 Different options will have different effects, but in general they all
2122 change details of the operation, such as archive format, archive name,
2123 or level of user interaction. Some options make sense with all
2124 operating modes, while others are meaningful only with particular modes.
2125 You will likely use some options frequently, while you will only use
2126 others infrequently, or not at all. (A full list of options is
2127 available in @pxref{All Options}.)
2129 Note that @code{tar} options are case sensitive. For example, the
2130 options @samp{-T} and @samp{-t} are different; the first requires an
2131 argument for stating the name of a file providing a list of @var{name}s,
2132 while the second does not require an argument and is another way to
2133 write @value{op-list}.
2135 In addition to the eight operations, there are many options to
2136 @code{tar}, and three different styles for writing both: long (mnemonic)
2137 form, short form, and old style. These styles are discussed below.
2138 Both the options and the operations can be written in any of these three
2141 @FIXME{menu at end of this node. need to think of an actual outline
2142 for this chapter; probably do that after stuff from chap. 4 is
2145 @node Styles, All Options, using tar options, tar invocation
2146 @section The Three Option Styles
2148 There are three styles for writing operations and options to the command
2149 line invoking @code{tar}. The different styles were developed at
2150 different times during the history of @code{tar}. These styles will be
2151 presented below, from the most recent to the oldest.
2153 Some options must take an argument. (For example, @value{op-file} takes
2154 the name of an archive file as an argument. If you do not supply an
2155 archive file name, @code{tar} will use a default, but this can be
2156 confusing; thus, we recommend that you always supply a specific archive
2157 file name.) Where you @emph{place} the arguments generally depends on
2158 which style of options you choose. We will detail specific information
2159 relevant to each option style in the sections on the different option
2160 styles, below. The differences are subtle, yet can often be very
2161 important; incorrect option placement can cause you to overwrite a
2162 number of important files. We urge you to note these differences, and
2163 only use the option style(s) which makes the most sense to you until you
2164 feel comfortable with the others.
2166 @FIXME{hag to write a brief paragraph on the option(s) which can
2167 optionally take an argument}
2170 * Mnemonic Options:: Mnemonic Option Style
2171 * Short Options:: Short Option Style
2172 * Old Options:: Old Option Style
2173 * Mixing:: Mixing Option Styles
2176 @node Mnemonic Options, Short Options, Styles, Styles
2177 @subsection Mnemonic Option Style
2179 @FIXME{have to decide whether or ot to replace other occurrences of
2180 "mnemonic" with "long", or *ugh* vice versa.}
2182 Each option has at least one long (or mnemonic) name starting with two
2183 dashes in a row, e.g.@: @samp{--list}. The long names are more clear than
2184 their corresponding short or old names. It sometimes happens that a
2185 single mnemonic option has many different different names which are
2186 synonymous, such as @samp{--compare} and @samp{--diff}. In addition,
2187 long option names can be given unique abbreviations. For example,
2188 @samp{--cre} can be used in place of @samp{--create} because there is no
2189 other mnemonic option which begins with @samp{cre}. (One way to find
2190 this out is by trying it and seeing what happens; if a particular
2191 abbreviation could represent more than one option, @code{tar} will tell
2192 you that that abbreviation is ambiguous and you'll know that that
2193 abbreviation won't work. You may also choose to run @samp{tar --help}
2194 to see a list of options. Be aware that if you run @code{tar} with a
2195 unique abbreviation for the long name of an option you didn't want to
2196 use, you are stuck; @code{tar} will perform the command as ordered.)
2198 Mnemonic options are meant to be obvious and easy to remember, and their
2199 meanings are generally easier to discern than those of their
2200 corresponding short options (see below). For example:
2203 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2207 gives a fairly good set of hints about what the command does, even
2208 for those not fully acquainted with @code{tar}.
2210 Mnemonic options which require arguments take those arguments
2211 immediately following the option name; they are introduced by an equal
2212 sign. For example, the @samp{--file} option (which tells the name
2213 of the @code{tar} archive) is given a file such as @file{archive.tar}
2214 as argument by using the notation @samp{--file=archive.tar} for the
2217 @node Short Options, Old Options, Mnemonic Options, Styles
2218 @subsection Short Option Style
2220 Most options also have a short option name. Short options start with
2221 a single dash, and are followed by a single character, e.g.@: @samp{-t}
2222 (which is equivalent to @samp{--list}). The forms are absolutely
2223 identical in function; they are interchangeable.
2225 The short option names are faster to type than long option names.
2227 Short options which require arguments take their arguments immediately
2228 following the option, usually separated by white space. It is also
2229 possible to stick the argument right after the short option name, using
2230 no intervening space. For example, you might write @w{@samp{-f
2231 archive.tar}} or @samp{-farchive.tar} instead of using
2232 @samp{--file=archive.tar}. Both @samp{--file=@var{archive-name}} and
2233 @w{@samp{-f @var{archive-name}}} denote the option which indicates a
2234 specific archive, here named @file{archive.tar}.
2236 Short options' letters may be clumped together, but you are not
2237 required to do this (as compared to old options; see below). When short
2238 options are clumped as a set, use one (single) dash for them all, e.g.@:
2239 @w{@samp{@code{tar} -cvf}}. Only the last option in such a set is allowed
2240 to have an argument@footnote{Clustering many options, the last of which
2241 has an argument, is a rather opaque way to write options. Some wonder if
2242 GNU @code{getopt} should not even be made helpful enough for considering
2243 such usages as invalid.}.
2245 When the options are separated, the argument for each option which requires
2246 an argument directly follows that option, as is usual for Unix programs.
2250 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2253 If you reorder short options' locations, be sure to move any arguments
2254 that belong to them. If you do not move the arguments properly, you may
2255 end up overwriting files.
2257 @node Old Options, Mixing, Short Options, Styles
2258 @subsection Old Option Style
2261 Like short options, old options are single letters. However, old options
2262 must be written together as a single clumped set, without spaces separating
2263 them or dashes preceding them@footnote{Beware that if you precede options
2264 with a dash, you are announcing the short option style instead of the
2265 old option style; short options are decoded differently.}. This set
2266 of letters must be the first to appear on the command line, after the
2267 @code{tar} program name and some white space; old options cannot appear
2268 anywhere else. The letter of an old option is exactly the same letter as
2269 the corresponding short option. For example, the old option @samp{t} is
2270 the same as the short option @samp{-t}, and consequently, the same as the
2271 mnemonic option @samp{--list}. So for example, the command @w{@samp{tar
2272 cv}} specifies the option @samp{-v} in addition to the operation @samp{-c}.
2274 @FIXME{bob suggests having an uglier example. :-) }
2276 When options that need arguments are given together with the command,
2277 all the associated arguments follow, in the same order as the options.
2278 Thus, the example given previously could also be written in the old
2282 $ @kbd{tar cvbf 20 /dev/rmt0}
2286 Here, @samp{20} is the argument of @samp{-b} and @samp{/dev/rmt0} is
2287 the argument of @samp{-f}.
2289 On the other hand, this old style syntax makes it difficult to match
2290 option letters with their corresponding arguments, and is often
2291 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2292 @samp{20} is the argument for @samp{-b}, @samp{/dev/rmt0} is the
2293 argument for @samp{-f}, and @samp{-v} does not have a corresponding
2294 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2295 /dev/rmt0}} is clearer, putting all arguments next to the option they
2298 If you want to reorder the letters in the old option argument, be
2299 sure to reorder any corresponding argument appropriately.
2301 This old way of writing @code{tar} options can surprise even experienced
2302 users. For example, the two commands:
2305 @kbd{tar cfz archive.tar.gz file}
2306 @kbd{tar -cfz archive.tar.gz file}
2310 are quite different. The first example uses @file{archive.tar.gz} as
2311 the value for option @samp{f} and recognizes the option @samp{z}. The
2312 second example, however, uses @file{z} as the value for option
2313 @samp{f}---probably not what was intended.
2315 Old options are kept for compatibility with old versions of @code{tar}.
2317 This second example could be corrected in many ways, among which the
2318 following are equivalent:
2321 @kbd{tar -czf archive.tar.gz file}
2322 @kbd{tar -cf archive.tar.gz -z file}
2323 @kbd{tar cf archive.tar.gz -z file}
2326 @FIXME{still could explain this better; it's redundant:}
2328 @cindex option syntax, traditional
2329 As far as we know, all @code{tar} programs, GNU and non-GNU, support
2330 old options. GNU @code{tar} supports them not only for historical
2331 reasons, but also because many people are used to them. For
2332 compatibility with Unix @code{tar}, the first argument is always
2333 treated as containing command and option letters even if it doesn't
2334 start with @samp{-}. Thus, @samp{tar c} is equivalent to @w{@samp{tar
2335 -c}:} both of them specify the @value{op-create} command to create an
2338 @node Mixing, , Old Options, Styles
2339 @subsection Mixing Option Styles
2341 All three styles may be intermixed in a single @code{tar} command, so
2342 long as the rules for each style are fully respected@footnote{Before GNU
2343 @code{tar} version 1.11.6, a bug prevented intermixing old style options
2344 with mnemonic options in some cases.}. Old style options and either of the
2345 modern styles of options may be mixed within a single @code{tar} command.
2346 However, old style options must be introduced as the first arguments only,
2347 following the rule for old options (old options must appear directly
2348 after the @code{tar} command and some white space). Modern options may
2349 be given only after all arguments to the old options have been collected.
2350 If this rule is not respected, a modern option might be falsely interpreted
2351 as the value of the argument to one of the old style options.
2353 For example, all the following commands are wholly equivalent, and
2354 illustrate the many combinations and orderings of option styles.
2357 @kbd{tar --create --file=archive.tar}
2358 @kbd{tar --create -f archive.tar}
2359 @kbd{tar --create -farchive.tar}
2360 @kbd{tar --file=archive.tar --create}
2361 @kbd{tar --file=archive.tar -c}
2362 @kbd{tar -c --file=archive.tar}
2363 @kbd{tar -c -f archive.tar}
2364 @kbd{tar -c -farchive.tar}
2365 @kbd{tar -cf archive.tar}
2366 @kbd{tar -cfarchive.tar}
2367 @kbd{tar -f archive.tar --create}
2368 @kbd{tar -f archive.tar -c}
2369 @kbd{tar -farchive.tar --create}
2370 @kbd{tar -farchive.tar -c}
2371 @kbd{tar c --file=archive.tar}
2372 @kbd{tar c -f archive.tar}
2373 @kbd{tar c -farchive.tar}
2374 @kbd{tar cf archive.tar}
2375 @kbd{tar f archive.tar --create}
2376 @kbd{tar f archive.tar -c}
2377 @kbd{tar fc archive.tar}
2380 On the other hand, the following commands are @emph{not} equivalent to
2384 @kbd{tar -f -c archive.tar}
2385 @kbd{tar -fc archive.tar}
2386 @kbd{tar -fcarchive.tar}
2387 @kbd{tar -farchive.tarc}
2388 @kbd{tar cfarchive.tar}
2392 These last examples mean something completely different from what the
2393 user intended (judging based on the example in the previous set which
2394 uses long options, whose intent is therefore very clear). The first
2395 four specify that the @code{tar} archive would be a file named
2396 @samp{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2397 respectively. The first two examples also specify a single non-option,
2398 @var{name} argument having the value @samp{archive.tar}. The last
2399 example contains only old style option letters (repeating option
2400 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2401 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2402 the first sentence of this paragraph..}
2404 @node All Options, help, Styles, tar invocation
2405 @section All @code{tar} Options
2407 The coming manual sections contain an alphabetical listing of all
2408 @code{tar} operations and options, with brief descriptions and cross
2409 references to more in-depth explanations in the body of the manual.
2410 They also contain an alphabetically arranged table of the short option
2411 forms with their corresponding long option. You can use this table as
2412 a reference for deciphering @code{tar} commands in scripts.
2415 * Operation Summary::
2417 * Short Option Summary::
2420 @node Operation Summary, Option Summary, All Options, All Options
2421 @subsection Operations
2428 Appends files to the end of the archive. @xref{append}.
2433 Same as @samp{--concatenate}. @xref{concatenate}.
2438 Compares archive members with their counterparts in the file
2439 system, and reports differences in file size, mode, owner,
2440 modification date and contents. @xref{compare}.
2445 Appends other @code{tar} archives to the end of the archive.
2451 Creates a new @code{tar} archive. @xref{create}.
2455 Deletes members from the archive. Don't try this on a archive on a
2456 tape! @xref{delete}.
2461 Same @samp{--compare}. @xref{compare}.
2466 Extracts members from the archive into the file system. @xref{extract}.
2471 Same as @samp{--extract}. @xref{extract}.
2476 Lists the members in an archive. @xref{list}.
2481 @FIXME{It was: A combination of the @samp{--compare} and @samp{--append} operations.
2482 This is not true and rather misleading, as @value{op-compare}
2483 does a lot more than @value{op-update} for ensuring files are identical.}
2484 Adds files to the end of the archive, but only if they are newer than
2485 their counterparts already in the archive, or if they do not already
2486 exist in the archive.
2491 @node Option Summary, Short Option Summary, Operation Summary, All Options
2492 @subsection @code{tar} Options
2496 @item --absolute-names
2499 Normally when creating an archive, @code{tar} strips an initial @samp{/} from
2500 member names. This option disables that behavior. @FIXME-xref{}
2504 (See @samp{--newer}.) @FIXME-pxref{}
2506 @item --atime-preserve
2508 Tells @code{tar} to preserve the access time field in a file's inode when
2509 dumping it. @FIXME-xref{}
2511 @item --backup=@var{backup-type}
2513 Rather than deleting files from the file system, @code{tar} will back them up
2514 using simple or numbered backups, depending upon @var{backup-type}.
2517 @item --block-number
2520 With this option present, @code{tar} prints error messages for read errors
2521 with the block number in the archive file. @FIXME-xref{}
2523 @item --blocking-factor=@var{blocking}
2524 @itemx -b @var{blocking}
2526 Sets the blocking factor @code{tar} uses to @var{blocking} x 512 bytes per
2527 record. @FIXME-xref{}
2532 This option tells @code{tar} to read or write archives through @code{bzip2}.
2537 This option directs @code{tar} to print periodic checkpoint messages as it
2538 reads through the archive. Its intended for when you want a visual
2539 indication that @code{tar} is still running, but don't want to see
2540 @samp{--verbose} output. @FIXME-xref{}
2546 @code{tar} will use the @code{compress} program when reading or writing the
2547 archive. This allows you to directly act on archives while saving
2548 space. @FIXME-xref{}
2550 @item --confirmation
2552 (See @samp{--interactive}.) @FIXME-pxref{}
2557 When creating a @code{tar} archive, @code{tar} will archive the file that a symbolic
2558 link points to, rather than archiving the symlink. @FIXME-xref{}
2560 @item --directory=@var{dir}
2563 When this option is specified, @code{tar} will change its current directory
2564 to @var{dir} before performing any operations. When this option is used
2565 during archive creation, it is order sensitive. @FIXME-xref{}
2567 @item --exclude=@var{pattern}
2569 When performing operations, @code{tar} will skip files that match
2570 @var{pattern}. @FIXME-xref{}
2572 @item --exclude-from=@var{file}
2573 @itemx -X @var{file}
2575 Similar to @samp{--exclude}, except @code{tar} will use the list of patterns
2576 in the file @var{file}. @FIXME-xref{}
2578 @item --file=@var{archive}
2579 @itemx -f @var{archive}
2581 @code{tar} will use the file @var{archive} as the @code{tar} archive it
2582 performs operations on, rather than @code{tar}'s compilation dependent
2583 default. @FIXME-xref{}
2585 @item --files-from=@var{file}
2586 @itemx -T @var{file}
2588 @code{tar} will use the contents of @var{file} as a list of archive members
2589 or files to operate on, in addition to those specified on the
2590 command-line. @FIXME-xref{}
2594 Forces @code{tar} to interpret the filename given to @samp{--file} as a local
2595 file, even if it looks like a remote tape drive name. @FIXME-xref{}
2597 @item --group=@var{group}
2599 Files added to the @code{tar} archive will have a group id of @var{group},
2600 rather than the group from the source file. @var{group} is first decoded
2601 as a group symbolic name, but if this interpretation fails, it has to be
2602 a decimal numeric group ID. @FIXME-xref{}
2604 Also see the comments for the @value{op-owner} option.
2608 (See @samp{--gzip}.) @FIXME-pxref{}
2615 This option tells @code{tar} to read or write archives through @code{gzip},
2616 allowing @code{tar} to directly operate on several kinds of compressed
2617 archives transparently. @FIXME-xref{}
2621 @code{tar} will print out a short message summarizing the operations and
2622 options to @code{tar} and exit. @FIXME-xref{}
2624 @item --ignore-failed-read
2626 Instructs @code{tar} to exit successfully if it encounters an
2627 unreadable file. @xref{Reading}.
2629 @item --ignore-umask
2630 @FIXME{does this exist?}
2632 (See @samp{--preserve-permissions}; @pxref{Writing}.)
2634 @item --ignore-zeros
2637 With this option, @code{tar} will ignore zeroed blocks in the archive, which
2638 normally signals EOF. @xref{Reading}.
2643 Used to inform @code{tar} that it is working with an old GNU-format
2644 incremental backup archive. It is intended primarily for backwards
2645 compatibility only. @FIXME-xref{}
2647 @item --info-script=@var{script-file}
2648 @itemx --new-volume-script=@var{script-file}
2649 @itemx -F @var{script-file}
2651 When @code{tar} is performing multi-tape backups, @var{script-file} is run
2652 at the end of each tape. @FIXME-xref{}
2655 @itemx --confirmation
2658 Specifies that @code{tar} should ask the user for confirmation before
2659 performing potentially destructive options, such as overwriting files.
2662 @item --keep-old-files
2665 When extracting files from an archive, @code{tar} will not overwrite existing
2666 files if this option is present. @xref{Writing}.
2668 @item --label=@var{name}
2669 @itemx -V @var{name}
2671 When creating an archive, instructs @code{tar} to write @var{name} as a name
2672 record in the archive. When extracting or listing archives, @code{tar} will
2673 only operate on archives that have a label matching the pattern
2674 specified in @var{name}. @FIXME-xref{}
2676 @item --listed-incremental=@var{snapshot-file}
2677 @itemx -g @var{snapshot-file}
2679 During a @samp{--create} operation, specifies that the archive that
2680 @code{tar} creates is a new GNU-format incremental backup, using
2681 @var{snapshot-file} to determine which files to backup.
2682 With other operations, informs @code{tar} that the archive is in incremental
2683 format. @FIXME-xref{}
2685 @item --mode=@var{permissions}
2687 When adding files to an archive, @code{tar} will use @var{permissions}
2688 for the archive members, rather than the permissions from the files.
2689 The program @code{chmod} and this @code{tar} option share the same syntax
2690 for what @var{permissions} might be. @xref{File permissions, Permissions,
2691 File permissions, fileutils, GNU file utilities}. This reference also
2692 has useful information for those not being overly familiar with the Unix
2695 Of course, @var{permissions} might be plainly specified as an octal number.
2696 However, by using generic symbolic modifications to mode bits, this allows
2697 more flexibility. For example, the value @samp{a+rw} adds read and write
2698 permissions for everybody, while retaining executable bits on directories
2699 or on any other file already marked as executable.
2701 @item --multi-volume
2704 Informs @code{tar} that it should create or otherwise operate on a
2705 multi-volume @code{tar} archive. @FIXME-xref{}
2707 @item --new-volume-script
2711 @item --newer=@var{date}
2712 @itemx --after-date=@var{date}
2715 When creating an archive, @code{tar} will only add files that have changed
2716 since @var{date}. @FIXME-xref{}
2720 In conjunction with @samp{--newer}, @code{tar} will only add files whose
2721 contents have changed (as opposed to just @samp{--newer}, which will
2722 also back up files for which any status information has changed).
2724 @item --no-recursion
2726 With this option, @code{tar} will not recurse into directories unless a
2727 directory is explicitly named as an argument to @code{tar}. @FIXME-xref{}
2729 @item --no-same-owner
2731 When extracting an archive, do not attempt to preserve the owner
2732 specified in the @code{tar} archive. This the default behavior
2733 for ordinary users; this option has an effect only for the superuser.
2735 @item --no-same-permissions
2737 When extracting an archive, subtract the user's umask from files from
2738 the permissions specified in the archive. This is the default behavior
2739 for ordinary users; this option has an effect only for the superuser.
2743 When @code{tar} is using the @samp{--files-from} option, this option
2744 instructs @code{tar} to expect filenames terminated with @kbd{NUL}, so
2745 @code{tar} can correctly work with file names that contain newlines.
2748 @item --numeric-owner
2750 This option will notify @code{tar} that it should use numeric user and group
2751 IDs when creating a @code{tar} file, rather than names. @FIXME-xref{}
2755 (See @samp{--portability}.) @FIXME-pxref{}
2757 @item --one-file-system
2760 Used when creating an archive. Prevents @code{tar} from recursing into
2761 directories that are on different file systems from the current
2762 directory. @FIXME-xref{}
2764 @item --owner=@var{user}
2766 Specifies that @code{tar} should use @var{user} as the owner of members
2767 when creating archives, instead of the user associated with the source
2768 file. @var{user} is first decoded as a user symbolic name, but if
2769 this interpretation fails, it has to be a decimal numeric user ID.
2772 There is no value indicating a missing number, and @samp{0} usually means
2773 @code{root}. Some people like to force @samp{0} as the value to offer in
2774 their distributions for the owner of files, because the @code{root} user is
2775 anonymous anyway, so that might as well be the owner of anonymous archives.
2778 @itemx --old-archive
2781 Tells @code{tar} to create an archive that is compatible with Unix V7
2782 @code{tar}. @FIXME-xref{}
2786 Instructs @code{tar} to create a POSIX compliant @code{tar} archive. @FIXME-xref{}
2790 Synonymous with specifying both @samp{--preserve-permissions} and
2791 @samp{--same-order}. @FIXME-xref{}
2793 @item --preserve-order
2795 (See @samp{--same-order}; @pxref{Reading}.)
2797 @item --preserve-permissions
2798 @itemx --same-permissions
2801 When @code{tar} is extracting an archive, it normally subtracts the users'
2802 umask from the permissions specified in the archive and uses that
2803 number as the permissions to create the destination file. Specifying
2804 this option instructs @code{tar} that it should use the permissions directly
2805 from the archive. @xref{Writing}.
2807 @item --read-full-records
2810 Specifies that @code{tar} should reblock its input, for reading from pipes on
2811 systems with buggy implementations. @xref{Reading}.
2813 @item --record-size=@var{size}
2815 Instructs @code{tar} to use @var{size} bytes per record when accessing the
2816 archive. @FIXME-xref{}
2818 @item --recursive-unlink
2820 Similar to the @samp{--unlink-first} option, removing existing
2821 directory hierarchies before extracting directories of the same name
2822 from the archive. @xref{Writing}.
2824 @item --remove-files
2826 Directs @code{tar} to remove the source file from the file system after
2827 appending it to an archive. @FIXME-xref{}
2829 @item --rsh-command=@var{cmd}
2831 Notifies @code{tar} that is should use @var{cmd} to communicate with remote
2832 devices. @FIXME-xref{}
2835 @itemx --preserve-order
2838 This option is an optimization for @code{tar} when running on machines with
2839 small amounts of memory. It informs @code{tar} that the list of file
2840 arguments has already been sorted to match the order of files in the
2841 archive. @xref{Reading}.
2845 When extracting an archive, @code{tar} will attempt to preserve the owner
2846 specified in the @code{tar} archive with this option present.
2847 This is the default behavior for the superuser; this option has an
2848 effect only for ordinary users. @FIXME-xref{}
2850 @item --same-permissions
2852 (See @samp{--preserve-permissions}; @pxref{Writing}.)
2854 @item --show-omitted-dirs
2856 Instructs @code{tar} to mention directories its skipping over when operating
2857 on a @code{tar} archive. @FIXME-xref{}
2862 Invokes a GNU extension when adding files to an archive that handles
2863 sparse files efficiently. @FIXME-xref{}
2865 @item --starting-file=@var{name}
2866 @itemx -K @var{name}
2868 This option affects extraction only; @code{tar} will skip extracting
2869 files in the archive until it finds one that matches @var{name}.
2872 @item --suffix=@var{suffix}
2874 Alters the suffix @code{tar} uses when backing up files from the default
2875 @samp{~}. @FIXME-xref{}
2877 @item --tape-length=@var{num}
2880 Specifies the length of tapes that @code{tar} is writing as being
2881 @w{@var{num} x 1024} bytes long. @FIXME-xref{}
2886 During extraction, @code{tar} will extract files to stdout rather than to the
2887 file system. @xref{Writing}.
2891 Displays the total number of bytes written after creating an archive.
2897 Sets the modification time of extracted files to the extraction time,
2898 rather than the modification time stored in the archive.
2903 (See @samp{--compress}.) @FIXME-pxref{}
2907 (See @samp{--gzip}.) @FIXME-pxref{}
2909 @item --unlink-first
2912 Directs @code{tar} to remove the corresponding file from the file system
2913 before extracting it from the archive. @xref{Writing}.
2915 @item --use-compress-program=@var{prog}
2917 Instructs @code{tar} to access the archive through @var{prog}, which is
2918 presumed to be a compression program of some sort. @FIXME-xref{}
2923 Specifies that @code{tar} should be more verbose about the operations its
2924 performing. This option can be specified multiple times for some
2925 operations to increase the amount of information displayed. @FIXME-xref{}
2930 Verifies that the archive was correctly written when creating an
2931 archive. @FIXME-xref{}
2935 @code{tar} will print an informational message about what version it is and a
2936 copyright message, some credits, and then exit. @FIXME-xref{}
2938 @item --volno-file=@var{file}
2940 Used in conjunction with @samp{--multi-volume}. @code{tar} will keep track
2941 of which volume of a multi-volume archive its working in @var{file}.
2945 @node Short Option Summary, , Option Summary, All Options
2946 @subsection Short Options Cross Reference
2948 Here is an alphabetized list of all of the short option forms, matching
2949 them with the equivalent long option.
2955 @samp{--concatenate}
2959 @samp{--read-full-records}
2967 @samp{--info-script}
2971 @samp{--incremental}
2979 @samp{--starting-file}
2983 @samp{--tape-length}
2987 @samp{--multi-volume}
2999 @samp{--absolute-names}
3003 @samp{--block-number}
3015 @samp{--unlink-first}
3027 @samp{--exclude-from}
3035 @samp{--blocking-factor}
3051 @samp{--listed-incremental}
3055 @samp{--dereference}
3059 @samp{--ignore-zeros}
3063 @samp{--keep-old-files}
3067 @samp{--one-file-system}
3075 @samp{--portability}
3079 @samp{--preserve-permissions}
3103 @samp{--interactive}
3115 @node help, verbose, All Options, tar invocation
3116 @section GNU @code{tar} documentation
3118 Being careful, the first thing is really checking that you are using GNU
3119 @code{tar}, indeed. The @value{op-version} option will generate a message
3120 giving confirmation that you are using GNU @code{tar}, with the precise
3121 version of GNU @code{tar} you are using. @code{tar} identifies itself
3122 and prints the version number to the standard output, then immediately
3123 exits successfully, without doing anything else, ignoring all other
3124 options. For example, @w{@samp{tar --version}} might return:
3127 tar (GNU tar) @value{VERSION}
3131 The first occurrence of @samp{tar} in the result above is the program
3132 name in the package (for example, @code{rmt} is another program), while
3133 the second occurrence of @samp{tar} is the name of the package itself,
3134 containing possibly many programs. The package is currently named
3135 @samp{tar}, after the name of the main program it contains@footnote{There
3136 are plans to merge the @code{cpio} and @code{tar} packages into a single one
3137 which would be called @code{paxutils}. So, who knows if, one of this days,
3138 the @value{op-version} would not yield @w{@samp{tar (GNU paxutils) 3.2}}}.
3140 Another thing you might want to do is checking the spelling or meaning
3141 of some particular @code{tar} option, without resorting to this manual,
3142 for once you have carefully read it. GNU @code{tar} has a short help
3143 feature, triggerable through the @value{op-help} option. By using this
3144 option, @code{tar} will print a usage message listing all available
3145 options on standard output, then exit successfully, without doing
3146 anything else and ignoring all other options. Even if this is only a
3147 brief summary, it may be several screens long. So, if you are not
3148 using some kind of scrollable window, you might prefer to use something
3152 $ @kbd{tar --help | less}
3156 presuming, here, that you like using @code{less} for a pager. Other
3157 popular pagers are @code{more} and @code{pg}. If you know about some
3158 @var{keyword} which interests you and do not want to read all the
3159 @value{op-help} output, another common idiom is doing:
3162 tar --help | grep @var{keyword}
3166 for getting only the pertinent lines.
3168 The perceptive reader would have noticed some contradiction in the
3169 previous paragraphs. It is written that both @value{op-version} and
3170 @value{op-help} print something, and have all other options ignored. In
3171 fact, they cannot ignore each other, and one of them has to win. We do
3172 not specify which is stronger, here; experiment if you really wonder!
3174 The short help output is quite succinct, and you might have to get back
3175 to the full documentation for precise points. If you are reading this
3176 paragraph, you already have the @code{tar} manual in some form. This
3177 manual is available in printed form, as a kind of small book. It may
3178 printed out of the GNU @code{tar} distribution, provided you have @TeX{}
3179 already installed somewhere, and a laser printer around. Just configure
3180 the distribution, execute the command @w{@samp{make dvi}}, then print
3181 @file{doc/tar.dvi} the usual way (contact your local guru to know how).
3182 If GNU @code{tar} has been conveniently installed at your place, this
3183 manual is also available in interactive, hypertextual form as an Info
3184 file. Just call @w{@samp{info tar}} or, if you do not have the
3185 @code{info} program handy, use the Info reader provided within GNU
3186 Emacs, calling @samp{tar} from the main Info menu.
3188 There is currently no @code{man} page for GNU @code{tar}. If you observe
3189 such a @code{man} page on the system you are running, either it does not
3190 long to GNU @code{tar}, or it has not been produced by GNU. Currently,
3191 GNU @code{tar} documentation is provided in Texinfo format only, if we
3192 except, of course, the short result of @kbd{tar --help}.
3194 @node verbose, interactive, help, tar invocation
3195 @section Checking @code{tar} progress
3197 @cindex Progress information
3198 @cindex Status information
3199 @cindex Information on progress and status of operations
3200 @cindex Verbose operation
3201 @cindex Block number where error occurred
3202 @cindex Error message, block number of
3203 @cindex Version of the @code{tar} program
3205 @cindex Getting more information during the operation
3206 @cindex Information during operation
3207 @cindex Feedback from @code{tar}
3209 Typically, @code{tar} performs most operations without reporting any
3210 information to the user except error messages. When using @code{tar}
3211 with many options, particularly ones with complicated or
3212 difficult-to-predict behavior, it is possible to make serious mistakes.
3213 @code{tar} provides several options that make observing @code{tar}
3214 easier. These options cause @code{tar} to print information as it
3215 progresses in its job, and you might want to use them just for being
3216 more careful about what is going on, or merely for entertaining
3217 yourself. If you have encountered a problem when operating on an
3218 archive, however, you may need more information than just an error
3219 message in order to solve the problem. The following options can be
3220 helpful diagnostic tools.
3222 Normally, the @value{op-list} command to list an archive prints just
3223 the file names (one per line) and the other commands are silent.
3224 When used with most operations, the @value{op-verbose} option causes
3225 @code{tar} to print the name of each file or archive member as it
3226 is processed. This and the other options which make @code{tar} print
3227 status information can be useful in monitoring @code{tar}.
3229 With @value{op-create} or @value{op-extract}, @value{op-verbose} used once
3230 just prints the names of the files or members as they are processed.
3231 Using it twice causes @code{tar} to print a longer listing (reminiscent
3232 of @samp{ls -l}) for each member. Since @value{op-list} already prints
3233 the names of the members, @value{op-verbose} used once with @value{op-list}
3234 causes @code{tar} to print an @samp{ls -l} type listing of the files
3235 in the archive. The following examples both extract members with
3239 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3240 $ @kbd{tar xvv archive.tar}
3243 Verbose output appears on the standard output except when an archive is
3244 being written to the standard output, as with @samp{tar --create
3245 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3246 installer let standard output be the default archive). In that case
3247 @code{tar} writes verbose output to the standard error stream.
3249 The @value{op-totals} option---which is only meaningful when used with
3250 @value{op-create}---causes @code{tar} to print the total
3251 amount written to the archive, after it has been fully created.
3253 The @value{op-checkpoint} option prints an occasional message
3254 as @code{tar} reads or writes the archive. In fact, it print
3255 directory names while reading the archive. It is designed for
3256 those who don't need the more detailed (and voluminous) output of
3257 @value{op-block-number}, but do want visual confirmation that @code{tar}
3258 is actually making forward progress.
3260 @FIXME{There is some confusion here. It seems that -R once wrote a
3261 message at @samp{every} record read or written.}
3263 The @value{op-show-omitted-dirs} option, when reading an archive---with
3264 @value{op-list} or @value{op-extract}, for example---causes a message
3265 to be printed for each directory in the archive which is skipped.
3266 This happens regardless of the reason for skipping: the directory might
3267 not have been named on the command line (implicitly or explicitly),
3268 it might be excluded by the use of the @value{op-exclude} option, or
3271 If @value{op-block-number} is used, @code{tar} prints, along with every
3272 message it would normally produce, the block number within the archive
3273 where the message was triggered. Also, supplementary messages are
3274 triggered when reading blocks full of NULs, or when hitting end of file on
3275 the archive. As of now, if the archive if properly terminated with a NUL
3276 block, the reading of the file may stop before end of file is met, so the
3277 position of end of file will not usually show when @value{op-block-number}
3278 is used. Note that GNU @code{tar} drains the archive before exiting when
3279 reading the archive from a pipe.
3281 This option is especially useful when reading damaged archives, since
3282 it helps pinpoint the damaged sections. It can also be used with
3283 @value{op-list} when listing a file-system backup tape, allowing you to
3284 choose among several backup tapes when retrieving a file later, in
3285 favor of the tape where the file appears earliest (closest to the
3286 front of the tape). @FIXME-xref{when the node name is set and the
3287 backup section written.}
3289 @node interactive, , verbose, tar invocation
3290 @section Asking for Confirmation During Operations
3291 @cindex Interactive operation
3293 Typically, @code{tar} carries out a command without stopping for
3294 further instructions. In some situations however, you may want to
3295 exclude some files and archive members from the operation (for instance
3296 if disk or storage space is tight). You can do this by excluding
3297 certain files automatically (@pxref{Choosing}), or by performing
3298 an operation interactively, using the @value{op-interactive} option.
3299 @code{tar} also accepts @samp{--confirmation} for this option.
3301 When the @value{op-interactive} option is specified, before
3302 reading, writing, or deleting files, @code{tar} first prints a message
3303 for each such file, telling what operation it intends to take, then asks
3304 for confirmation on the terminal. The actions which require
3305 confirmation include adding a file to the archive, extracting a file
3306 from the archive, deleting a file from the archive, and deleting a file
3307 from disk. To confirm the action, you must type a line of input
3308 beginning with @samp{y}. If your input line begins with anything other
3309 than @samp{y}, @code{tar} skips that file.
3311 If @code{tar} is reading the archive from the standard input,
3312 @code{tar} opens the file @file{/dev/tty} to support the interactive
3315 Verbose output is normally sent to standard output, separate from
3316 other error messages. However, if the archive is produced directly
3317 on standard output, then verbose output is mixed with errors on
3318 @code{stderr}. Producing the archive on standard output may be used
3319 as a way to avoid using disk space, when the archive is soon to be
3320 consumed by another process reading it, say. Some people felt the need
3321 of producing an archive on stdout, still willing to segregate between
3322 verbose output and error output. A possible approach would be using a
3323 named pipe to receive the archive, and having the consumer process to
3324 read from that named pipe. This has the advantage of letting standard
3325 output free to receive verbose output, all separate from errors.
3327 @node operations, Backups, tar invocation, Top
3328 @chapter GNU @code{tar} Operations
3339 @node Basic tar, Advanced tar, operations, operations
3340 @section Basic GNU @code{tar} Operations
3342 The basic @code{tar} operations, @value{op-create}, @value{op-list} and
3343 @value{op-extract}, are currently presented and described in the tutorial
3344 chapter of this manual. This section provides some complementary notes
3345 for these operations.
3348 @item @value{op-create}
3350 Creating an empty archive would have some kind of elegance. One can
3351 initialize an empty archive and later use @value{op-append} for adding
3352 all members. Some applications would not welcome making an exception
3353 in the way of adding the first archive member. On the other hand,
3354 many people reported that it is dangerously too easy for @code{tar}
3355 to destroy a magnetic tape with an empty archive@footnote{This is well
3356 described in @cite{Unix-haters Handbook}, by Simson Garfinkel, Daniel
3357 Weise & Steven Strassmann, IDG Books, ISBN 1-56884-203-1.}. The two most
3362 Mistakingly using @code{create} instead of @code{extract}, when the
3363 intent was to extract the full contents of an archive. This error
3364 is likely: keys @kbd{c} and @kbd{x} are right next ot each other on
3365 the QWERTY keyboard. Instead of being unpacked, the archive then
3366 gets wholly destroyed. When users speak about @dfn{exploding} an
3367 archive, they usually mean something else :-).
3370 Forgetting the argument to @code{file}, when the intent was to create
3371 an archive with a single file in it. This error is likely because a
3372 tired user can easily add the @kbd{f} key to the cluster of option
3373 letters, by the mere force of habit, without realizing the full
3374 consequence of doing so. The usual consequence is that the single
3375 file, which was meant to be saved, is rather destroyed.
3378 So, recognizing the likelihood and the catastrophical nature of these
3379 errors, GNU @code{tar} now takes some distance from elegance, and
3380 cowardly refuses to create an archive when @value{op-create} option is
3381 given, there are no arguments besides options, and @value{op-files-from}
3382 option is @emph{not} used. To get around the cautiousness of GNU
3383 @code{tar} and nevertheless create an archive with nothing in it,
3384 one may still use, as the value for the @value{op-files-from} option,
3385 a file with no names in it, as shown in the following commands:
3388 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3389 @kbd{tar cfT empty-archive.tar /dev/null}
3392 @item @value{op-extract}
3394 A socket is stored, within a GNU @code{tar} archive, as a pipe.
3396 @item @value{op-list}
3398 GNU @code{tar} now shows dates as @samp{1996-11-09}, while it used to
3399 show them as @samp{Nov 11 1996}. (One can revert to the old behavior by
3400 defining @code{USE_OLD_CTIME} in @file{src/list.c} before reinstalling.)
3401 But preferably, people should get used to ISO 8601 dates. Local
3402 American dates should be made available again with full date localization
3403 support, once ready. In the meantime, programs not being localizable
3404 for dates should prefer international dates, that's really the way to go.
3406 Look up @url{http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html} if you
3407 are curious, it contains a detailed explanation of the ISO 8601 standard.
3411 @node Advanced tar, extract options, Basic tar, operations
3412 @section Advanced GNU @code{tar} Operations
3414 Now that you have learned the basics of using GNU @code{tar}, you may
3415 want to learn about further ways in which @code{tar} can help you.
3417 This chapter presents five, more advanced operations which you probably
3418 won't use on a daily basis, but which serve more specialized functions.
3419 We also explain the different styles of options and why you might want
3420 to use one or another, or a combination of them in your @code{tar}
3421 commands. Additionally, this chapter includes options which allow you to
3422 define the output from @code{tar} more carefully, and provide help and
3423 error correction in special circumstances.
3425 @FIXME{check this after the chapter is actually revised to make sure
3426 it still introduces the info in the chapter correctly : ).}
3438 @node Operations, current state, Advanced tar, Advanced tar
3439 @subsection The Five Advanced @code{tar} Operations
3442 In the last chapter, you learned about the first three operations to
3443 @code{tar}. This chapter presents the remaining five operations to
3444 @code{tar}: @samp{--append}, @samp{--update}, @samp{--concatenate},
3445 @samp{--delete}, and @samp{--compare}.
3447 You are not likely to use these operations as frequently as those
3448 covered in the last chapter; however, since they perform specialized
3449 functions, they are quite useful when you do need to use them. We
3450 will give examples using the same directory and files that you created
3451 in the last chapter. As you may recall, the directory is called
3452 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3453 @samp{rock}, and the two archive files you created are
3454 @samp{collection.tar} and @samp{music.tar}.
3456 We will also use the archive files @samp{afiles.tar} and
3457 @samp{bfiles.tar}. @samp{afiles.tar} contains the members @samp{apple},
3458 @samp{angst}, and @samp{aspic}. @samp{bfiles.tar} contains the members
3459 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3461 Unless we state otherwise, all practicing you do and examples you follow
3462 in this chapter will take place in the @file{practice} directory that
3463 you created in the previous chapter; see @ref{prepare for examples}.
3464 (Below in this section, we will remind you of the state of the examples
3465 where the last chapter left them.)
3467 The five operations that we will cover in this chapter are:
3472 Add new entries to an archive that already exists.
3475 Add more recent copies of archive members to the end of an archive, if
3480 Add one or more pre-existing archives to the end of another archive.
3482 Delete items from an archive (does not work on tapes).
3486 Compare archive members to their counterparts in the file system.
3489 @node current state, append, Operations, Advanced tar
3491 @subsection The Current State of the Practice Files
3494 Currently, the listing of the directory using @code{ls} is as follows:
3501 The archive file @samp{collection.tar} looks like this:
3504 $ @kbd{tar -tvf collection.tar}
3509 The archive file @samp{music.tar} looks like this:
3512 $ @kbd{tar -tvf music.tar}
3516 @FIXME{need to fill in the above!!!}
3518 @node append, update, current state, Advanced tar
3519 @subsection How to Add Files to Existing Archives: @code{--append}
3522 If you want to add files to an existing archive, you don't need to
3523 create a new archive; you can use @value{op-append}. The archive must
3524 already exist in order to use @samp{--append}. (A related operation
3525 is the @samp{--update} operation; you can use this to add newer
3526 versions of archive members to an existing archive. To learn how to
3527 do this with @samp{--update}, @pxref{update}.)
3529 @FIXME{Explain in second paragraph whether you can get to the previous
3530 version -- explain whole situation somewhat more clearly.}
3532 If you use @value{op-append} to add a file that has the same name as an
3533 archive member to an archive containing that archive member, then the
3534 old member is not deleted. What does happen, however, is somewhat
3535 complex. @code{tar} @emph{allows} you to have infinite numbers of files
3536 with the same name. Some operations treat these same-named members no
3537 differently than any other set of archive members: for example, if you
3538 view an archive with @value{op-list}, you will see all of those members
3539 listed, with their modification times, owners, etc.
3541 Other operations don't deal with these members as perfectly as you might
3542 prefer; if you were to use @value{op-extract} to extract the archive,
3543 only the most recently added copy of a member with the same name as four
3544 other members would end up in the working directory. This is because
3545 @samp{--extract} extracts an archive in the order the members appeared
3546 in the archive; the most recently archived members will be extracted
3547 last. Additionally, an extracted member will @emph{overwrite} a file of
3548 the same name which existed in the directory already, and @code{tar}
3549 will not prompt you about this. Thus, only the most recently archived
3550 member will end up being extracted, as it will overwrite the one
3551 extracted before it, and so on.
3553 @FIXME{ hag -- you might want to incorporate some of the above into the
3554 MMwtSN node; not sure. i didn't know how to make it simpler...}
3556 There are a few ways to get around this. @FIXME-xref{Multiple Members
3557 with the Same Name.}
3559 @cindex Members, replacing with other members
3560 @cindex Replacing members with other members
3561 If you want to replace an archive member, use @value{op-delete} to
3562 delete the member you want to remove from the archive, , and then use
3563 @samp{--append} to add the member you want to be in the archive. Note
3564 that you can not change the order of the archive; the most recently
3565 added member will still appear last. In this sense, you cannot truly
3566 ``replace'' one member with another. (Replacing one member with another
3567 will not work on certain types of media, such as tapes; see @ref{delete}
3568 and @ref{Media}, for more information.)
3571 * appending files:: Appending Files to an Archive
3575 @node appending files, multiple, append, append
3576 @subsubsection Appending Files to an Archive
3578 @cindex Adding files to an Archive
3579 @cindex Appending files to an Archive
3580 @cindex Archives, Appending files to
3582 The simplest way to add a file to an already existing archive is the
3583 @value{op-append} operation, which writes specified files into the
3584 archive whether or not they are already among the archived files.
3585 When you use @samp{--append}, you @emph{must} specify file name
3586 arguments, as there is no default. If you specify a file that already
3587 exists in the archive, another copy of the file will be added to the
3588 end of the archive. As with other operations, the member names of the
3589 newly added files will be exactly the same as their names given on the
3590 command line. The @value{op-verbose} option will print out the names
3591 of the files as they are written into the archive.
3593 @samp{--append} cannot be performed on some tape drives, unfortunately,
3594 due to deficiencies in the formats those tape drives use. The archive
3595 must be a valid @code{tar} archive, or else the results of using this
3596 operation will be unpredictable. @xref{Media}.
3598 To demonstrate using @samp{--append} to add a file to an archive,
3599 create a file called @file{rock} in the @file{practice} directory.
3600 Make sure you are in the @file{practice} directory. Then, run the
3601 following @code{tar} command to add @file{rock} to
3602 @file{collection.tar}:
3605 $ @kbd{tar --append --file=collection.tar rock}
3609 If you now use the @value{op-list} operation, you will see that
3610 @file{rock} has been added to the archive:
3613 $ @kbd{tar --list --file=collection.tar}
3614 -rw-rw-rw- me user 28 1996-10-18 16:31 jazz
3615 -rw-rw-rw- me user 21 1996-09-23 16:44 blues
3616 -rw-rw-rw- me user 20 1996-09-23 16:44 folk
3617 -rw-rw-rw- me user 20 1996-09-23 16:44 rock
3620 @FIXME{in theory, dan will (soon) try to turn this node into what it's
3621 title claims it will become...}
3623 @node multiple, , appending files, append
3624 @subsubsection Multiple Files with the Same Name
3626 You can use @value{op-append} to add copies of files which have been
3627 updated since the archive was created. (However, we do not recommend
3628 doing this since there is another @code{tar} option called
3629 @samp{--update}; @pxref{update} for more information. We describe this
3630 use of @samp{--append} here for the sake of completeness.) @FIXME{is
3631 this really a good idea, to give this whole description for something
3632 which i believe is basically a Stupid way of doing something? certain
3633 aspects of it show ways in which tar is more broken than i'd personally
3634 like to admit to, specifically the last sentence. On the other hand, i
3635 don't think it's a good idea to be saying that re explicitly don't
3636 recommend using something, but i can't see any better way to deal with
3637 the situation.}When you extract the archive, the older version will be
3638 effectively lost. This works because files are extracted from an
3639 archive in the order in which they were archived. Thus, when the
3640 archive is extracted, a file archived later in time will overwrite a
3641 file of the same name which was archived earlier, even though the older
3642 version of the file will remain in the archive unless you delete all
3643 versions of the file.
3645 Supposing you change the file @file{blues} and then append the changed
3646 version to @file{collection.tar}. As you saw above, the original
3647 @file{blues} is in the archive @file{collection.tar}. If you change the
3648 file and append the new version of the file to the archive, there will
3649 be two copies in the archive. When you extract the archive, the older
3650 version of the file will be extracted first, and then overwritten by the
3651 newer version when it is extracted.
3653 You can append the new, changed copy of the file @file{blues} to the
3654 archive in this way:
3657 $ @kbd{tar --append --verbose --file=collection.tar blues}
3662 Because you specified the @samp{--verbose} option, @code{tar} has
3663 printed the name of the file being appended as it was acted on. Now
3664 list the contents of the archive:
3667 $ @kbd{tar --list --verbose --file=collection.tar}
3668 -rw-rw-rw- me user 28 1996-10-18 16:31 jazz
3669 -rw-rw-rw- me user 21 1996-09-23 16:44 blues
3670 -rw-rw-rw- me user 20 1996-09-23 16:44 folk
3671 -rw-rw-rw- me user 20 1996-09-23 16:44 rock
3672 -rw-rw-rw- me user 58 1996-10-24 18:30 blues
3676 The newest version of @file{blues} is now at the end of the archive
3677 (note the different creation dates and file sizes). If you extract
3678 the archive, the older version of the file @file{blues} will be
3679 overwritten by the newer version. You can confirm this by extracting
3680 the archive and running @samp{ls} on the directory. @xref{Writing},
3681 for more information. (@emph{Please note:} This is the case unless
3682 you employ the @value{op-backup} option. @FIXME-ref{Multiple Members
3683 with the Same Name}.)
3685 @node update, concatenate, append, Advanced tar
3686 @subsection Updating an Archive
3688 @cindex Updating an archive
3690 In the previous section, you learned how to use @value{op-append} to add
3691 a file to an existing archive. A related operation is
3692 @value{op-update}. The @samp{--update} operation updates a @code{tar}
3693 archive by comparing the date of the specified archive members against
3694 the date of the file with the same name. If the file has been modified
3695 more recently than the archive member, then the newer version of the
3696 file is added to the archive (as with @value{op-append}).
3698 Unfortunately, you cannot use @samp{--update} with magnetic tape drives.
3699 The operation will fail.
3701 @FIXME{other examples of media on which --update will fail? need to ask
3702 charles and/or mib/thomas/dave shevett..}
3704 Both @samp{--update} and @samp{--append} work by adding to the end
3705 of the archive. When you extract a file from the archive, only the
3706 version stored last will wind up in the file system, unless you use
3707 the @value{op-backup} option. @FIXME-ref{Multiple Members with the
3714 @node how to update, , update, update
3715 @subsubsection How to Update an Archive Using @code{--update}
3717 You must use file name arguments with the @value{op-update} operation.
3718 If you don't specify any files, @code{tar} won't act on any files and
3719 won't tell you that it didn't do anything (which may end up confusing
3722 @FIXME{note: the above parenthetical added because in fact, this
3723 behavior just confused the author. :-) }
3725 To see the @samp{--update} option at work, create a new file,
3726 @file{classical}, in your practice directory, and some extra text to the
3727 file @file{blues}, using any text editor. Then invoke @code{tar} with
3728 the @samp{update} operation and the @value{op-verbose} option specified,
3729 using the names of all the files in the practice directory as file name
3733 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
3740 Because we have specified verbose mode, @code{tar} prints out the names
3741 of the files it is working on, which in this case are the names of the
3742 files that needed to be updated. If you run @samp{tar --list} and look
3743 at the archive, you will see @file{blues} and @file{classical} at its
3744 end. There will be a total of two versions of the member @samp{blues};
3745 the one at the end will be newer and larger, since you added text before
3748 (The reason @code{tar} does not overwrite the older file when updating
3749 it is because writing to the middle of a section of tape is a difficult
3750 process. Tapes are not designed to go backward. @xref{Media}, for more
3751 information about tapes.
3753 @value{op-update} is not suitable for performing backups for two
3754 reasons: it does not change directory content entries, and it lengthens
3755 the archive every time it is used. The GNU @code{tar} options intended
3756 specifically for backups are more efficient. If you need to run
3757 backups, please consult @ref{Backups}.
3759 @node concatenate, delete, update, Advanced tar
3760 @subsection Combining Archives with @code{--concatenate}
3762 @cindex Adding archives to an archive
3763 @cindex Concatenating Archives
3764 Sometimes it may be convenient to add a second archive onto the end of
3765 an archive rather than adding individual files to the archive. To add
3766 one or more archives to the end of another archive, you should use the
3767 @value{op-concatenate} operation.
3769 To use @samp{--concatenate}, name the archives to be concatenated on the
3770 command line. (Nothing happens if you don't list any.) The members,
3771 and their member names, will be copied verbatim from those archives. If
3772 this causes multiple members to have the same name, it does not delete
3773 any members; all the members with the same name coexist. @FIXME-ref{For
3774 information on how this affects reading the archive, Multiple
3775 Members with the Same Name.}
3777 To demonstrate how @samp{--concatenate} works, create two small archives
3778 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
3779 files from @file{practice}:
3782 $ @kbd{tar -cvf bluesrock.tar blues rock}
3785 $ @kbd{tar -cvf folkjazz.tar folk jazz}
3791 If you like, You can run @samp{tar --list} to make sure the archives
3792 contain what they are supposed to:
3795 $ @kbd{tar -tvf bluesrock.tar}
3796 -rw-rw-rw- melissa user 105 1997-01-21 19:42 blues
3797 -rw-rw-rw- melissa user 33 1997-01-20 15:34 rock
3798 $ @kbd{tar -tvf folkjazz.tar}
3799 -rw-rw-rw- melissa user 20 1996-09-23 16:44 folk
3800 -rw-rw-rw- melissa user 65 1997-01-30 14:15 jazz
3803 We can concatenate these two archives with @code{tar}:
3807 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
3810 If you now list the contents of the @file{bluesclass.tar}, you will see
3811 that now it also contains the archive members of @file{jazzfolk.tar}:
3814 $ @kbd{tar --list --file=bluesrock.tar}
3821 When you use @samp{--concatenate}, the source and target archives must
3822 already exist and must have been created using compatible format
3823 parameters. @FIXME-pxref{Matching Format Parameters}The new,
3824 concatenated archive will be called by the same name as the first
3825 archive listed on the command line. @FIXME{is there a way to specify a
3828 Like @value{op-append}, this operation cannot be performed on some
3829 tape drives, due to deficiencies in the formats those tape drives use.
3831 @cindex @code{concatenate} vs @code{cat}
3832 @cindex @code{cat} vs @code{concatenate}
3833 It may seem more intuitive to you to want or try to use @code{cat} to
3834 concatenate two archives instead of using the @samp{--concatenate}
3835 operation; after all, @code{cat} is the utility for combining files.
3837 However, @code{tar} archives incorporate an end-of-file marker which
3838 must be removed if the concatenated archives are to be read properly as
3839 one archive. @samp{--concatenate} removes the end-of-archive marker
3840 from the target archive before each new archive is appended. If you use
3841 @code{cat} to combine the archives, the result will not be a valid
3842 @code{tar} format archive. If you need to retrieve files from an
3843 archive that was added to using the @code{cat} utility, use the
3844 @value{op-ignore-zeros} option. @xref{Ignore Zeros}, for further
3845 information on dealing with archives improperly combined using the
3846 @code{cat} shell utility.
3848 @FIXME{this shouldn't go here. where should it go?} You must specify
3849 the source archives using @value{op-file} (@value{pxref-file}). If you
3850 do not specify the target archive, @code{tar} uses the value of the
3851 environment variable @code{TAPE}, or, if this has not been set, the
3852 default archive name.
3854 @node delete, compare, concatenate, Advanced tar
3855 @subsection Removing Archive Members Using @samp{--delete}
3857 @cindex Deleting files from an archive
3858 @cindex Removing files from an archive
3860 You can remove members from an archive by using the @value{op-delete}
3861 option. Specify the name of the archive with @value{op-file} and then
3862 specify the names of the members to be deleted; if you list no member
3863 names, nothing will be deleted. The @value{op-verbose} option will
3864 cause @code{tar} to print the names of the members as they are deleted.
3865 As with @value{op-extract}, you must give the exact member names when
3866 using @samp{tar --delete}. @samp{--delete} will remove all versions of
3867 the named file from the archive. The @samp{--delete} operation can run
3870 Unlike other operations, @samp{--delete} has no short form.
3872 @cindex Tapes, using @code{--delete} and
3873 @cindex Deleting from tape archives
3874 This operation will rewrite the archive. You can only use
3875 @samp{--delete} on an archive if the archive device allows you to
3876 write to any point on the media, such as a disk; because of this, it
3877 does not work on magnetic tapes. Do not try to delete an archive member
3878 from a magnetic tape; the action will not succeed, and you will be
3879 likely to scramble the archive and damage your tape. There is no safe
3880 way (except by completely re-writing the archive) to delete files from
3881 most kinds of magnetic tape. @xref{Media}.
3883 To delete all versions of the file @file{blues} from the archive
3884 @file{collection.tar} in the @file{practice} directory, make sure you
3885 are in that directory, and then,
3888 $ @kbd{tar --list --file=collection.tar}
3898 $ @kbd{tar --delete --file=collection.tar blues}
3899 $ @kbd{tar --list --file=collection.tar}
3906 @FIXME{I changed the order of these nodes around and haven't had a chance
3907 to fix the above example's results, yet. I have to play with this and
3908 follow it and see what it actually does!}
3910 The @value{op-delete} option has been reported to work properly when
3911 @code{tar} acts as a filter from @code{stdin} to @code{stdout}.
3913 @node compare, , delete, Advanced tar
3914 @subsection Comparing Archive Members with the File System
3915 @cindex Verifying the currency of an archive
3918 The @samp{--compare} (@samp{-d}), or @samp{--diff} operation compares
3919 specified archive members against files with the same names, and then
3920 reports differences in file size, mode, owner, modification date and
3921 contents. You should @emph{only} specify archive member names, not file
3922 names. If you do not name any members, then @code{tar} will compare the
3923 entire archive. If a file is represented in the archive but does not
3924 exist in the file system, @code{tar} reports a difference.
3926 You have to specify the record size of the archive when modifying an
3927 archive with a non-default record size.
3929 @code{tar} ignores files in the file system that do not have
3930 corresponding members in the archive.
3932 The following example compares the archive members @file{rock},
3933 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
3934 files of the same name in the file system. (Note that there is no file,
3935 @file{funk}; @code{tar} will report an error message.)
3938 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
3941 tar: funk not found in archive
3945 @FIXME{what does this actually depend on? i'm making a guess,
3946 here.}Depending on the system where you are running @code{tar} and the
3947 version you are running, @code{tar} may have a different error message,
3951 funk: does not exist
3954 @FIXME-xref{somewhere, for more information about format parameters.
3955 Melissa says: such as "format variations"? But why? Clearly I don't
3956 get it yet; I'll deal when I get to that section.}
3958 The spirit behind the @value{op-compare} option is to check whether the
3959 archive represents the current state of files on disk, more than validating
3960 the integrity of the archive media. For this later goal, @xref{verify}.
3962 @node extract options, backup, Advanced tar, operations
3963 @section Options Used by @code{--extract}
3966 @FIXME{i need to get dan to go over these options with me and see if
3967 there's a better way of organizing them.}
3969 The previous chapter showed how to use @value{op-extract} to extract
3970 an archive into the filesystem. Various options cause @code{tar} to
3971 extract more information than just file contents, such as the owner,
3972 the permissions, the modification date, and so forth. This section
3973 presents options to be used with @samp{--extract} when certain special
3974 considerations arise. You may review the information presented in
3975 @ref{extract} for more basic information about the
3976 @samp{--extract} operation.
3979 * Reading:: Options to Help Read Archives
3980 * Writing:: Changing How @code{tar} Writes Files
3981 * Scarce:: Coping with Scarce Resources
3984 @node Reading, Writing, extract options, extract options
3985 @subsection Options to Help Read Archives
3986 @cindex Options when reading archives
3987 @cindex Reading incomplete records
3988 @cindex Records, incomplete
3989 @cindex End-of-archive entries, ignoring
3990 @cindex Ignoring end-of-archive entries
3991 @cindex Large lists of file names on small machines
3992 @cindex Small memory
3993 @cindex Running out of space
3996 Normally, @code{tar} will request data in full record increments from
3997 an archive storage device. If the device cannot return a full record,
3998 @code{tar} will report an error. However, some devices do not always
3999 return full records, or do not require the last record of an archive to
4000 be padded out to the next record boundary. To keep reading until you
4001 obtain a full record, or to accept an incomplete record if it contains
4002 an end-of-archive marker, specify the @value{op-read-full-records} option
4003 in conjunction with the @value{op-extract} or @value{op-list} operations.
4004 @value{xref-read-full-records}.
4006 The @value{op-read-full-records} option is turned on by default when
4007 @code{tar} reads an archive from standard input, or from a remote
4008 machine. This is because on BSD Unix systems, attempting to read a
4009 pipe returns however much happens to be in the pipe, even if it is
4010 less than was requested. If this option were not enabled, @code{tar}
4011 would fail as soon as it read an incomplete record from the pipe.
4013 If you're not sure of the blocking factor of an archive, you can
4014 read the archive by specifying @value{op-read-full-records} and
4015 @value{op-blocking-factor}, using a blocking factor larger than what the
4016 archive uses. This lets you avoid having to determine the blocking factor
4017 of an archive. @value{xref-blocking-factor}.
4020 * read full records::
4022 * Ignore Failed Read::
4025 @node read full records, Ignore Zeros, Reading, Reading
4026 @unnumberedsubsubsec Reading Full Records
4028 @FIXME{need sentence or so of intro here}
4031 @item --read-full-records
4033 Use in conjunction with @value{op-extract} to read an archive which
4034 contains incomplete records, or one which has a blocking factor less
4035 than the one specified.
4038 @node Ignore Zeros, Ignore Failed Read, read full records, Reading
4039 @unnumberedsubsubsec Ignoring Blocks of Zeros
4041 Normally, @code{tar} stops reading when it encounters a block of zeros
4042 between file entries (which usually indicates the end of the archive).
4043 @value{op-ignore-zeros} allows @code{tar} to completely read an archive
4044 which contains a block of zeros before the end (i.e.@: a damaged
4045 archive, or one which was created by @code{cat}-ing several archives
4048 The @value{op-ignore-zeros} option is turned off by default because many
4049 versions of @code{tar} write garbage after the end-of-archive entry,
4050 since that part of the media is never supposed to be read. GNU
4051 @code{tar} does not write after the end of an archive, but seeks to
4052 maintain compatiblity among archiving utilities.
4055 @item --ignore-zeros
4057 To ignore blocks of zeros (ie.@: end-of-archive entries) which may be
4058 encountered while reading an archive. Use in conjunction with
4059 @value{op-extract} or @value{op-list}.
4062 @node Ignore Failed Read, , Ignore Zeros, Reading
4063 @unnumberedsubsubsec Ignore Fail Read
4065 @FIXME{Is this in the right place? It doesn't exist anywhere else in
4066 the book (except the appendix), and has no further explanation. For that
4067 matter, what does it mean?!}
4070 @item --ignore-failed-read
4071 Do not exit with nonzero on unreadable files or directories.
4074 @node Writing, Scarce, Reading, extract options
4075 @subsection Changing How @code{tar} Writes Files
4076 @cindex Overwriting old files, prevention
4077 @cindex Protecting old files
4078 @cindex Modification times of extracted files
4079 @cindex Permissions of extracted files
4080 @cindex Modes of extracted files
4081 @cindex Writing extracted files to standard output
4082 @cindex Standard output, writing extracted files to
4085 @FIXME{need to mention the brand new option, --backup}
4088 * Prevention Overwriting::
4091 * Recursive Unlink::
4092 * Modification Times::
4093 * Setting Access Permissions::
4094 * Writing to Standard Output::
4098 @node Prevention Overwriting, Keep Old Files, Writing, Writing
4099 @unnumberedsubsubsec Options to Prevent Overwriting Files
4101 Normally, @code{tar} writes extracted files into the file system without
4102 regard to the files already on the system; i.e., files with the same
4103 names as archive members are overwritten when the archive is extracted.
4104 If the name of a corresponding file name is a symbolic link, the file
4105 pointed to by the symbolic link will be overwritten instead of the
4106 symbolic link itself (if this is possible). Moreover, special devices,
4107 empty directories and even symbolic links are automatically removed if
4108 they are found to be on the way of the proper extraction.
4110 To prevent @code{tar} from extracting an archive member from an archive
4111 if doing so will overwrite a file in the file system, use
4112 @value{op-keep-old-files} in conjunction with @samp{--extract}. When
4113 this option is specified, @code{tar} will report an error stating the
4114 name of the files in conflict instead of overwriting the file with the
4115 corresponding extracted archive member.
4117 @FIXME{these two P's have problems. i don't understand what they're
4118 trying to talk about well enough to fix them; i may have just made them
4119 worse (in particular the first of the two). waiting to talk with hag.}
4121 The @value{op-unlink-first} option removes existing files, symbolic links,
4122 empty directories, devices, etc., @emph{prior} to extracting over them.
4123 In particular, using this option will prevent replacing an already existing
4124 symbolic link by the name of an extracted file, since the link itself
4125 is removed prior to the extraction, rather than the file it points to.
4126 On some systems, the backing store for the executable @emph{is} the
4127 original program text. You could use the @value{op-unlink-first} option
4128 to prevent segmentation violations or other woes when extracting arbitrary
4129 executables over currently running copies. Note that if something goes
4130 wrong with the extraction and you @emph{did} use this option, you might
4131 end up with no file at all. Without this option, if something goes wrong
4132 with the extraction, the existing file is not overwritten and preserved.
4134 @FIXME{huh?} If you specify the @value{op-recursive-unlink} option,
4135 @code{tar} removes @emph{anything} that keeps you from extracting a file
4136 as far as current permissions will allow it. This could include removal
4137 of the contents of a full directory hierarchy. For example, someone
4138 using this feature may be very surprised at the results when extracting
4139 a directory entry from the archive. This option can be dangerous; be
4140 very aware of what you are doing if you choose to use it.
4145 * Recursive Unlink::
4148 @node Keep Old Files, Unlink First, Prevention Overwriting, Writing
4149 @unnumberedsubsubsec Keep Old Files
4152 @item --keep-old-files
4154 Do not overwrite existing files from archive. The
4155 @value{op-keep-old-files} option prevents @code{tar} from over-writing
4156 existing files with files with the same name from the archive.
4157 The @value{op-keep-old-files} option is meaningless with @value{op-list}.
4158 Prevents @code{tar} from overwriting files in the file system during
4162 @node Unlink First, Recursive Unlink, Keep Old Files, Writing
4163 @unnumberedsubsubsec Unlink First
4166 @item --unlink-first
4168 Try removing files before extracting over them, instead of trying to
4172 @node Recursive Unlink, Modification Times, Unlink First, Writing
4173 @unnumberedsubsubsec Recursive Unlink
4176 @item --recursive-unlink
4177 When this option is specified, try removing files and directory hierarchies
4178 before extracting over them. @emph{This is a dangerous option!}
4181 Some people argue that GNU @code{tar} should not hesitate to overwrite
4182 files with other files when extracting. When extracting a @code{tar}
4183 archive, they expect to see a faithful copy of the state of the filesystem
4184 when the archive was created. It is debatable that this would always
4185 be a proper behavior. For example, suppose one has an archive in
4186 which @file{usr/local} is a link to @file{usr/local2}. Since then,
4187 maybe the site removed the link and renamed the whole hierarchy from
4188 @file{/usr/local2} to @file{/usr/local}. Such things happen all the time.
4189 I guess it would not be welcome at all that GNU @code{tar} removes the
4190 whole hierarchy just to make room for the link to be reinstated (unless it
4191 @emph{also} simultaneously restores the full @file{/usr/local2}, of course!
4192 GNU @code{tar} is indeed able to remove a whole hierarchy to reestablish a
4193 symbolic link, for example, but @emph{only if} @value{op-recursive-unlink}
4194 is specified to allow this behavior. In any case, single files are
4197 @node Modification Times, Setting Access Permissions, Recursive Unlink, Writing
4198 @unnumberedsubsubsec Setting Modification Times
4200 Normally, @code{tar} sets the modification times of extracted files to
4201 the modification times recorded for the files in the archive, but
4202 limits the permissions of extracted files by the current @code{umask}
4205 To set the modification times of extracted files to the time when
4206 the files were extracted, use the @value{op-touch} option in
4207 conjunction with @value{op-extract}.
4212 Sets the modification time of extracted archive members to the time
4213 they were extracted, not the time recorded for them in the archive.
4214 Use in conjunction with @value{op-extract}.
4217 @node Setting Access Permissions, Writing to Standard Output, Modification Times, Writing
4218 @unnumberedsubsubsec Setting Access Permissions
4220 To set the modes (access permissions) of extracted files to those
4221 recorded for those files in the archive, use @samp{--same-permissions}
4222 in conjunction with the @value{op-extract} operation. @FIXME{Should be
4223 aliased to ignore-umask.}
4226 @item --preserve-permission
4227 @itemx --same-permission
4228 @itemx --ignore-umask
4230 Set modes of extracted archive members to those recorded in the
4231 archive, instead of current umask settings. Use in conjunction with
4235 @FIXME{Following paragraph needs to be rewritten: why doesn't this cat
4236 files together, why is this useful. is it really useful with
4237 more than one file?}
4239 @node Writing to Standard Output, remove files, Setting Access Permissions, Writing
4240 @unnumberedsubsubsec Writing to Standard Output
4242 To write the extracted files to the standard output, instead of
4243 creating the files on the file system, use @value{op-to-stdout} in
4244 conjunction with @value{op-extract}. This option is useful if you are
4245 extracting files to send them through a pipe, and do not need to
4246 preserve them in the file system. If you extract multiple members,
4247 they appear on standard output concatenated, in the order they are
4248 found in the archive.
4253 Writes files to the standard output. Used in conjunction with
4254 @value{op-extract}. Extract files to standard output. When this option
4255 is used, instead of creating the files specified, @code{tar} writes
4256 the contents of the files extracted to its standard output. This may
4257 be useful if you are only extracting the files in order to send them
4258 through a pipe. This option is meaningless with @value{op-list}.
4261 @FIXME{Why would you want to do such a thing, how are files separated on
4262 the standard output? is this useful with more that one file? Are
4263 pipes the real reason?}
4265 @node remove files, , Writing to Standard Output, Writing
4266 @unnumberedsubsubsec Removing Files
4268 @FIXME{the various macros in the front of the manual think that this
4269 option goes in this section. i have no idea; i only know it's nowhere
4270 else in the book...}
4273 @item --remove-files
4274 Remove files after adding them to the archive.
4277 @node Scarce, , Writing, extract options
4278 @subsection Coping with Scarce Resources
4279 @cindex Middle of the archive, starting in the
4280 @cindex Running out of space during extraction
4281 @cindex Disk space, running out of
4282 @cindex Space on the disk, recovering from lack of
4290 @node Starting File, Same Order, Scarce, Scarce
4291 @unnumberedsubsubsec Starting File
4294 @item --starting-file=@var{name}
4295 @itemx -K @var{name}
4296 Starts an operation in the middle of an archive. Use in conjunction
4297 with @value{op-extract} or @value{op-list}.
4300 If a previous attempt to extract files failed due to lack of disk
4301 space, you can use @value{op-starting-file} to start extracting only
4302 after member @var{name} of the archive. This assumes, of course, that
4303 there is now free space, or that you are now extracting into a
4304 different file system. (You could also choose to suspend @code{tar},
4305 remove unnecessary files from the file system, and then restart the
4306 same @code{tar} operation. In this case, @value{op-starting-file} is
4307 not necessary. @value{xref-incremental}, @value{xref-interactive},
4308 and @value{ref-exclude}.)
4310 @node Same Order, , Starting File, Scarce
4311 @unnumberedsubsubsec Same Order
4315 @itemx --preserve-order
4317 To process large lists of file names on machines with small amounts of
4318 memory. Use in conjunction with @value{op-compare},
4320 or @value{op-extract}.
4323 @FIXME{we don't need/want --preserve to exist any more (from melissa:
4324 ie, don't want that *version* of the option to exist, or don't want
4325 the option to exist in either version?}
4327 @FIXME{i think this explanation is lacking.}
4329 The @value{op-same-order} option tells @code{tar} that the list of file
4330 names to be listed or extracted is sorted in the same order as the
4331 files in the archive. This allows a large list of names to be used,
4332 even on a small machine that would not otherwise be able to hold all
4333 the names in memory at the same time. Such a sorted list can easily be
4334 created by running @samp{tar -t} on the archive and editing its output.
4336 This option is probably never needed on modern computer systems.
4338 @node backup, Applications, extract options, operations
4339 @section Backup options
4341 @cindex backup options
4343 GNU @code{tar} offers options for making backups of files before writing
4344 new versions. These options control the details of these backups.
4345 They may apply to the archive itself before it is created or rewritten,
4346 as well as individual extracted members. Other GNU programs (@code{cp},
4347 @code{install}, @code{ln}, and @code{mv}, for example) offer similar
4350 Backup options may prove unexpectedly useful when extracting archives
4351 containing many members having identical name, or when extracting archives
4352 on systems having file name limitations, making different members appear
4353 has having similar names through the side-effect of name truncation.
4354 (This is true only if we have a good scheme for truncated backup names,
4355 which I'm not sure at all: I suspect work is needed in this area.)
4356 When any existing file is backed up before being overwritten by extraction,
4357 then clashing files are automatically be renamed to be unique, and the
4358 true name is kept for only the last file of a series of clashing files.
4359 By using verbose mode, users may track exactly what happens.
4361 At the detail level, some decisions are still experimental, and may
4362 change in the future, we are waiting comments from our users. So, please
4363 do not learn to depend blindly on the details of the backup features.
4364 For example, currently, directories themselves are never renamed through
4365 using these options, so, extracting a file over a directory still has
4366 good chances to fail. Also, backup options apply to created archives,
4367 not only to extracted members. For created archives, backups will not
4368 be attempted when the archive is a block or character device, or when it
4369 refers to a remote file.
4371 For the sake of simplicity and efficiency, backups are made by renaming old
4372 files prior to creation or extraction, and not by copying. The original
4373 name is restored if the file creation fails. If a failure occurs after a
4374 partial extraction of a file, both the backup and the partially extracted
4381 @cindex backups, making
4382 Make backups of files that are about to be overwritten or removed.
4383 Without this option, the original versions are destroyed.
4385 @item --suffix=@var{suffix}
4387 @cindex backup suffix
4388 @vindex SIMPLE_BACKUP_SUFFIX
4389 Append @var{suffix} to each backup file made with @samp{-b}. If this
4390 option is not specified, the value of the @code{SIMPLE_BACKUP_SUFFIX}
4391 environment variable is used. And if @code{SIMPLE_BACKUP_SUFFIX} is not
4392 set, the default is @samp{~}, just as in Emacs.
4394 @item --version-control=@var{method}
4395 @opindex --version-control
4396 @vindex VERSION_CONTROL
4397 @cindex backup files, type made
4398 Use @var{method} to determine the type of backups made with @value{op-backup}.
4399 If this option is not specified, the value of the @code{VERSION_CONTROL}
4400 environment variable is used. And if @code{VERSION_CONTROL} is not set,
4401 the default backup type is @samp{existing}.
4403 @vindex version-control @r{Emacs variable}
4404 This option corresponds to the Emacs variable @samp{version-control};
4405 the same values for @var{method} are accepted as in Emacs. This options
4406 also more descriptive name. The valid @var{method}s (unique
4407 abbreviations are accepted):
4412 @opindex numbered @r{backup method}
4413 Always make numbered backups.
4417 @opindex existing @r{backup method}
4418 Make numbered backups of files that already have them, simple backups
4423 @opindex simple @r{backup method}
4424 Always make simple backups.
4430 Some people express the desire to @emph{always} use the @var{op-backup}
4431 option, by defining some kind of alias or script. This is not as easy
4432 as one may thing, due to the fact old style options should appear first
4433 and consume arguments a bit unpredictably for an alias or script. But,
4434 if you are ready to give up using old style options, you may resort to
4435 using something like (a Bourne shell function here):
4438 tar () @{ /usr/local/bin/tar --backup $*; @}
4441 @node Applications, looking ahead, backup, operations
4442 @section Notable @code{tar} Usages
4445 @FIXME{Using Unix file linking capability to recreate directory
4446 structures---linking files into one subdirectory and then
4447 @code{tar}ring that directory.}
4449 @FIXME{Nice hairy example using absolute-names, newer, etc.}
4452 You can easily use archive files to transport a group of files from
4453 one system to another: put all relevant files into an archive on one
4454 computer system, transfer the archive to another system, and extract
4455 the contents there. The basic transfer medium might be magnetic tape,
4456 Internet FTP, or even electronic mail (though you must encode the
4457 archive with @code{uuencode} in order to transport it properly by
4458 mail). Both machines do not have to use the same operating system, as
4459 long as they both support the @code{tar} program.
4461 For example, here is how you might copy a directory's contents from
4462 one disk to another, while preserving the dates, modes, owners and
4463 link-structure of all the files therein. In this case, the transfer
4464 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
4467 $ @kbd{cd sourcedir; tar -cf - . | (cd targetdir; tar -xf -)}
4471 The command also works using short option forms:
4473 @FIXME{The following using standard input/output correct??}
4475 $ @w{@kbd{cd sourcedir; tar --create --file=- . | (cd targetdir; tar --extract --file=-)}}
4479 This is one of the easiest methods to transfer a @code{tar} archive.
4481 @node looking ahead, , Applications, operations
4482 @section Looking Ahead: The Rest of this Manual
4484 You have now seen how to use all eight of the operations available to
4485 @code{tar}, and a number of the possible options. The next chapter
4486 explains how to choose and change file and archive names, how to use
4487 files to store names of other files which you can then call as
4488 arguments to @code{tar} (this can help you save time if you expect to
4489 archive the same list of files a number of times), and so forth.
4490 @FIXME{in case it's not obvious, i'm making this up in some sense
4491 based on my imited memory of what the next chapter *really* does. i
4492 just wanted to flesh out this final section a little bit so i'd
4493 remember to sitck it in here. :-)}
4495 If there are too many files to conveniently list on the command line,
4496 you can list the names in a file, and @code{tar} will read that file.
4497 @value{xref-files-from}.
4499 There are various ways of causing @code{tar} to skip over some files,
4500 and not archive them. @xref{Choosing}.
4502 @node Backups, Choosing, operations, Top
4503 @chapter Performing Backups and Restoring Files
4506 GNU @code{tar} is distributed along with the scripts which the Free
4507 Software Foundation uses for performing backups. There is no corresponding
4508 scripts available yet for doing restoration of files. Even if there is
4509 a good chance those scripts may be satisfying to you, they are not the
4510 only scripts or methods available for doing backups and restore. You may
4511 well create your own, or use more sophisticated packages dedicated to
4514 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
4515 Automatic Network Disk Archiver), a backup system developed by James
4516 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
4517 This is free software, and it is available at these places:
4520 http://www.cs.umd.edu/projects/amanda/amanda.html
4521 ftp://ftp.cs.umd.edu/pub/amanda
4526 Here is a possible plan for a future documentation about the backuping
4527 scripts which are provided within the GNU @code{tar} distribution.
4533 . + different levels of dumps
4534 . - full dump = dump everything
4535 . - level 1, level 2 dumps etc, -
4536 A level n dump dumps everything changed since the last level
4539 . + how to use scripts for dumps (ie, the concept)
4540 . - scripts to run after editing backup specs (details)
4542 . + Backup Specs, what is it.
4543 . - how to customize
4544 . - actual text of script [/sp/dump/backup-specs]
4547 . - rsh doesn't work
4548 . - rtape isn't installed
4551 . + the --incremental option of tar
4554 . - write protection
4556 . : different sizes and types, useful for different things
4557 . - files and tape marks
4558 one tape mark between files, two at end.
4559 . - positioning the tape
4560 MT writes two at end of write,
4561 backspaces over one when writing again.
4566 This chapter documents both the provided FSF scripts and @code{tar}
4567 options which are more specific to usage as a backup tool.
4569 To @dfn{back up} a file system means to create archives that contain
4570 all the files in that file system. Those archives can then be used to
4571 restore any or all of those files (for instance if a disk crashes or a
4572 file is accidentally deleted). File system @dfn{backups} are also
4576 * Full Dumps:: Using @code{tar} to Perform Full Dumps
4577 * Inc Dumps:: Using @code{tar} to Perform Incremental Dumps
4578 * incremental and listed-incremental:: The Incremental Options
4579 * Backup Levels:: Levels of Backups
4580 * Backup Parameters:: Setting Parameters for Backups and Restoration
4581 * Scripted Backups:: Using the Backup Scripts
4582 * Scripted Restoration:: Using the Restore Script
4585 @node Full Dumps, Inc Dumps, Backups, Backups
4586 @section Using @code{tar} to Perform Full Dumps
4592 @cindex corrupted archives
4593 Full dumps should only be made when no other people or programs
4594 are modifying files in the filesystem. If files are modified while
4595 @code{tar} is making the backup, they may not be stored properly in
4596 the archive, in which case you won't be able to restore them if you
4597 have to. (Files not being modified are written with no trouble, and do
4598 not corrupt the entire archive.)
4600 You will want to use the @value{op-label} option to give the archive a
4601 volume label, so you can tell what this archive is even if the label
4602 falls off the tape, or anything like that.
4604 Unless the filesystem you are dumping is guaranteed to fit on
4605 one volume, you will need to use the @value{op-multi-volume} option.
4606 Make sure you have enough tapes on hand to complete the backup.
4608 If you want to dump each filesystem separately you will need to use
4609 the @value{op-one-file-system} option to prevent @code{tar} from crossing
4610 filesystem boundaries when storing (sub)directories.
4612 The @value{op-incremental} option is not needed, since this is a complete
4613 copy of everything in the filesystem, and a full restore from this
4614 backup would only be done onto a completely empty disk.
4616 Unless you are in a hurry, and trust the @code{tar} program (and your
4617 tapes), it is a good idea to use the @value{op-verify} option, to make
4618 sure your files really made it onto the dump properly. This will
4619 also detect cases where the file was modified while (or just after)
4620 it was being archived. Not all media (notably cartridge tapes) are
4621 capable of being verified, unfortunately.
4623 @value{op-listed-incremental} take a file name argument always. If the
4624 file doesn't exist, run a level zero dump, creating the file. If the
4625 file exists, uses that file to see what has changed.
4627 @value{op-incremental} @FIXME{look it up}
4629 @value{op-incremental} handle old GNU-format incremental backup.
4631 This option should only be used when creating an incremental backup of
4632 a filesystem. When the @value{op-incremental} option is used, @code{tar}
4633 writes, at the beginning of the archive, an entry for each of the
4634 directories that will be operated on. The entry for a directory
4635 includes a list of all the files in the directory at the time the
4636 dump was done, and a flag for each file indicating whether the file
4637 is going to be put in the archive. This information is used when
4638 doing a complete incremental restore.
4640 Note that this option causes @code{tar} to create a non-standard
4641 archive that may not be readable by non-GNU versions of the @code{tar}
4644 The @value{op-incremental} option means the archive is an incremental
4645 backup. Its meaning depends on the command that it modifies.
4647 If the @value{op-incremental} option is used with @value{op-list}, @code{tar}
4648 will list, for each directory in the archive, the list of files in
4649 that directory at the time the archive was created. This information
4650 is put out in a format that is not easy for humans to read, but which
4651 is unambiguous for a program: each file name is preceded by either a
4652 @samp{Y} if the file is present in the archive, an @samp{N} if the
4653 file is not included in the archive, or a @samp{D} if the file is
4654 a directory (and is included in the archive). Each file name is
4655 terminated by a null character. The last file is followed by an
4656 additional null and a newline to indicate the end of the data.
4658 If the @value{op-incremental} option is used with @value{op-extract}, then
4659 when the entry for a directory is found, all files that currently
4660 exist in that directory but are not listed in the archive @emph{are
4661 deleted from the directory}.
4663 This behavior is convenient when you are restoring a damaged file
4664 system from a succession of incremental backups: it restores the
4665 entire state of the file system to that which obtained when the backup
4666 was made. If you don't use @value{op-incremental}, the file system will
4667 probably fill up with files that shouldn't exist any more.
4669 @value{op-listed-incremental} handle new GNU-format incremental backup.
4670 This option handles new GNU-format incremental backup. It has much the
4671 same effect as @value{op-incremental}, but also the time when the dump
4672 is done and the list of directories dumped is written to the given
4673 @var{file}. When restoring, only files newer than the saved time are
4674 restored, and the directory list is used to speed up operations.
4676 @value{op-listed-incremental} acts like @value{op-incremental}, but when
4677 used in conjunction with @value{op-create} will also cause @code{tar} to
4678 use the file @var{file}, which contains information about the state
4679 of the filesystem at the time of the last backup, to decide which
4680 files to include in the archive being created. That file will then
4681 be updated by @code{tar}. If the file @var{file} does not exist when
4682 this option is specified, @code{tar} will create it, and include all
4683 appropriate files in the archive.
4685 The file, which is archive independent, contains the date it was last
4686 modified and a list of devices, inode numbers and directory names.
4687 @code{tar} will archive files with newer mod dates or inode change
4688 times, and directories with an unchanged inode number and device but
4689 a changed directory name. The file is updated after the files to
4690 be archived are determined, but before the new archive is actually
4693 GNU @code{tar} actually writes the file twice: once before the data
4694 and written, and once after.
4696 @node Inc Dumps, incremental and listed-incremental, Full Dumps, Backups
4697 @section Using @code{tar} to Perform Incremental Dumps
4700 @cindex incremental dumps
4701 @cindex dumps, incremental
4703 Performing incremental dumps is similar to performing full dumps,
4704 although a few more options will usually be needed.
4706 A standard scheme is to do a @emph{monthly} (full) dump once a month,
4707 a @emph{weekly} dump once a week of everything since the last monthly
4708 and a @emph{daily} every day of everything since the last (weekly or
4711 Here is a sample script to dump the directory hierarchies @samp{/usr}
4717 --blocking-factor=126 \
4719 --label="`hostname` /usr /var `date +%Y-%m-%d`" \
4720 --listed-incremental=/var/log/usr-var.snar \
4725 This script uses the file @file{/var/log/usr-var.snar} as a snapshot to
4726 store information about the previous tar dump.
4728 The blocking factor 126 is an attempt to make the tape drive stream.
4729 Some tape devices cannot handle 64 kB blocks or larger, and require the
4730 block size to be a multiple of 1 kB; for these devices, 126 is the
4731 largest blocking factor that can be used.
4733 @node incremental and listed-incremental, Backup Levels, Inc Dumps, Backups
4734 @section The Incremental Options
4737 @value{op-incremental} is used in conjunction with @value{op-create},
4738 @value{op-extract} or @value{op-list} when backing up and restoring file
4739 systems. An archive cannot be extracted or listed with the
4740 @value{op-incremental} option specified unless it was created with the
4741 option specified. This option should only be used by a script, not by
4742 the user, and is usually disregarded in favor of
4743 @value{op-listed-incremental}, which is described below.
4745 @value{op-incremental} in conjunction with @value{op-create} causes
4746 @code{tar} to write, at the beginning of the archive, an entry for
4747 each of the directories that will be archived. The entry for a
4748 directory includes a list of all the files in the directory at the
4749 time the archive was created and a flag for each file indicating
4750 whether or not the file is going to be put in the archive.
4752 Note that this option causes @code{tar} to create a non-standard
4753 archive that may not be readable by non-GNU versions of the @code{tar}
4756 @value{op-incremental} in conjunction with @value{op-extract} causes
4757 @code{tar} to read the lists of directory contents previously stored
4758 in the archive, @emph{delete} files in the file system that did not
4759 exist in their directories when the archive was created, and then
4760 extract the files in the archive.
4762 This behavior is convenient when restoring a damaged file system from
4763 a succession of incremental backups: it restores the entire state of
4764 the file system to that which obtained when the backup was made. If
4765 @value{op-incremental} isn't specified, the file system will probably
4766 fill up with files that shouldn't exist any more.
4768 @value{op-incremental} in conjunction with @value{op-list}, causes
4769 @code{tar} to print, for each directory in the archive, the list of
4770 files in that directory at the time the archive was created. This
4771 information is put out in a format that is not easy for humans to
4772 read, but which is unambiguous for a program: each file name is
4773 preceded by either a @samp{Y} if the file is present in the archive,
4774 an @samp{N} if the file is not included in the archive, or a @samp{D}
4775 if the file is a directory (and is included in the archive). Each
4776 file name is terminated by a null character. The last file is followed
4777 by an additional null and a newline to indicate the end of the data.
4779 @value{op-listed-incremental} acts like @value{op-incremental}, but when
4780 used in conjunction with @value{op-create} will also cause @code{tar}
4781 to use the file @var{snapshot-file}, which contains information about
4782 the state of the file system at the time of the last backup, to decide
4783 which files to include in the archive being created. That file will
4784 then be updated by @code{tar}. If the file @var{file} does not exist
4785 when this option is specified, @code{tar} will create it, and include
4786 all appropriate files in the archive.
4788 The file @var{file}, which is archive independent, contains the date
4789 it was last modified and a list of devices, inode numbers and
4790 directory names. @code{tar} will archive files with newer mod dates
4791 or inode change times, and directories with an unchanged inode number
4792 and device but a changed directory name. The file is updated after
4793 the files to be archived are determined, but before the new archive is
4796 Despite it should be obvious that a device has a non-volatile value, NFS
4797 devices have non-dependable values when an automounter gets in the picture.
4798 This led to a great deal of spurious redumping in incremental dumps,
4799 so it is somewhat useless to compare two NFS devices numbers over time.
4800 So @code{tar} now considers all NFS devices as being equal when it comes
4801 to comparing directories; this is fairly gross, but there does not seem
4802 to be a better way to go.
4804 @FIXME{this section needs to be written}
4806 @node Backup Levels, Backup Parameters, incremental and listed-incremental, Backups
4807 @section Levels of Backups
4810 An archive containing all the files in the file system is called a
4811 @dfn{full backup} or @dfn{full dump}. You could insure your data by
4812 creating a full dump every day. This strategy, however, would waste a
4813 substantial amount of archive media and user time, as unchanged files
4814 are daily re-archived.
4816 It is more efficient to do a full dump only occasionally. To back up
4817 files between full dumps, you can a incremental dump. A @dfn{level
4818 one} dump archives all the files that have changed since the last full
4821 A typical dump strategy would be to perform a full dump once a week,
4822 and a level one dump once a day. This means some versions of files
4823 will in fact be archived more than once, but this dump strategy makes
4824 it possible to restore a file system to within one day of accuracy by
4825 only extracting two archives---the last weekly (full) dump and the
4826 last daily (level one) dump. The only information lost would be in
4827 files changed or created since the last daily backup. (Doing dumps
4828 more than once a day is usually not worth the trouble).
4830 GNU @code{tar} comes with scripts you can use to do full and level-one
4831 dumps. Using scripts (shell programs) to perform backups and
4832 restoration is a convenient and reliable alternative to typing out
4833 file name lists and @code{tar} commands by hand.
4835 Before you use these scripts, you need to edit the file
4836 @file{backup-specs}, which specifies parameters used by the backup
4837 scripts and by the restore script. @FIXME{There is no such restore
4838 script!}@FIXME-xref{Script Syntax}Once the backup parameters
4839 are set, you can perform backups or restoration by running the
4842 The name of the restore script is @code{restore}. @FIXME{There is
4843 no such restore script!}The names of the level one and full backup
4844 scripts are, respectively, @code{level-1} and @code{level-0}.
4845 The @code{level-0} script also exists under the name @code{weekly}, and
4846 the @code{level-1} under the name @code{daily}---these additional names
4847 can be changed according to your backup schedule. @FIXME-xref{Scripted
4848 Restoration, for more information on running the restoration script.}
4849 @FIXME-xref{Scripted Backups, for more information on running the
4852 @emph{Please Note:} The backup scripts and the restoration scripts are
4853 designed to be used together. While it is possible to restore files by
4854 hand from an archive which was created using a backup script, and to create
4855 an archive by hand which could then be extracted using the restore script,
4856 it is easier to use the scripts.@FIXME{There is no such restore script!}
4857 @value{xref-incremental}, and @value{xref-listed-incremental},
4858 before making such an attempt.
4860 @FIXME{shorten node names}
4862 @node Backup Parameters, Scripted Backups, Backup Levels, Backups
4863 @section Setting Parameters for Backups and Restoration
4866 The file @file{backup-specs} specifies backup parameters for the
4867 backup and restoration scripts provided with @code{tar}. You must
4868 edit @file{backup-specs} to fit your system configuration and schedule
4869 before using these scripts.
4871 @FIXME{This about backup scripts needs to be written: BS is a shell
4872 script .... thus ... @file{backup-specs} is in shell script syntax.}
4874 @FIXME-xref{Script Syntax, for an explanation of this syntax.}
4876 @FIXME{Whats a parameter .... looked at by the backup scripts
4877 ... which will be expecting to find ... now syntax ... value is linked
4878 to lame ... @file{backup-specs} specifies the following parameters:}
4882 The user name of the backup administrator.
4885 The hour at which the backups are done. This can be a number from 0
4886 to 23, or the string @samp{now}.
4889 The device @code{tar} writes the archive to. This device should be
4890 attached to the host on which the dump scripts are run.
4892 @FIXME{examples for all ...}
4895 The command to use to obtain the status of the archive device,
4896 including error count. On some tape drives there may not be such a
4897 command; in that case, simply use `TAPE_STATUS=false'.
4900 The blocking factor @code{tar} will use when writing the dump archive.
4901 @value{xref-blocking-factor}.
4904 A list of file systems to be dumped. You can include any directory
4905 name in the list---subdirectories on that file system will be
4906 included, regardless of how they may look to other networked machines.
4907 Subdirectories on other file systems will be ignored.
4909 The host name specifies which host to run @code{tar} on, and should
4910 normally be the host that actually contains the file system. However,
4911 the host machine must have GNU @code{tar} installed, and must be able
4912 to access the directory containing the backup scripts and their
4913 support files using the same file name that is used on the machine
4914 where the scripts are run (ie. what @code{pwd} will print when in that
4915 directory on that machine). If the host that contains the file system
4916 does not have this capability, you can specify another host as long as
4917 it can access the file system through NFS.
4920 A list of individual files to be dumped. These should be accessible
4921 from the machine on which the backup script is run.
4923 @FIXME{Same file name, be specific. Through NFS ...}
4928 * backup-specs example:: An Example Text of @file{Backup-specs}
4929 * Script Syntax:: Syntax for @file{Backup-specs}
4932 @node backup-specs example, Script Syntax, Backup Parameters, Backup Parameters
4933 @subsection An Example Text of @file{Backup-specs}
4936 The following is the text of @file{backup-specs} as it appears at FSF:
4939 # site-specific parameters for file system backup.
4941 ADMINISTRATOR=friedman
4943 TAPE_FILE=/dev/nrsmt0
4944 TAPE_STATUS="mts -t $TAPE_FILE"
4959 apple-gunkies:/com/mailer/gnu
4960 apple-gunkies:/com/archive/gnu"
4962 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
4966 @node Script Syntax, , backup-specs example, Backup Parameters
4967 @subsection Syntax for @file{Backup-specs}
4970 @file{backup-specs} is in shell script syntax. The following
4971 conventions should be considered when editing the script:
4972 @FIXME{"conventions?"}
4974 A quoted string is considered to be contiguous, even if it is on more
4975 than one line. Therefore, you cannot include commented-out lines
4976 within a multi-line quoted string. BACKUP_FILES and BACKUP_DIRS are
4977 the two most likely parameters to be multi-line.
4979 A quoted string typically cannot contain wildcards. In
4980 @file{backup-specs}, however, the parameters BACKUP_DIRS and
4981 BACKUP_FILES can contain wildcards.
4983 @node Scripted Backups, Scripted Restoration, Backup Parameters, Backups
4984 @section Using the Backup Scripts
4987 The syntax for running a backup script is:
4990 @file{script-name} [@var{time-to-be-run}]
4993 where @var{time-to-be-run} can be a specific system time, or can be
4994 @kbd{now}. If you do not specify a time, the script runs at the time
4995 specified in @file{backup-specs}. @FIXME-pxref{Script Syntax}
4997 You should start a script with a tape or disk mounted. Once you
4998 start a script, it prompts you for new tapes or disks as it
4999 needs them. Media volumes don't have to correspond to archive
5000 files---a multi-volume archive can be started in the middle of a
5001 tape that already contains the end of another multi-volume archive.
5002 The @code{restore} script prompts for media by its archive volume,
5003 so to avoid an error message you should keep track of which tape
5004 (or disk) contains which volume of the archive. @FIXME{There is
5005 no such restore script!} @FIXME-xref{Scripted Restoration}
5006 @FIXME{Have file names changed?}
5008 The backup scripts write two files on the file system. The first is a
5009 record file in @file{/etc/tar-backup/}, which is used by the scripts
5010 to store and retrieve information about which files were dumped. This
5011 file is not meant to be read by humans, and should not be deleted by
5012 them. @FIXME-xref{incremental and listed-incremental, for a more
5013 detailed explanation of this file.}
5015 The second file is a log file containing the names of the file systems
5016 and files dumped, what time the backup was made, and any error
5017 messages that were generated, as well as how much space was left in
5018 the media volume after the last volume of the archive was written.
5019 You should check this log file after every backup. The file name is
5020 @file{log-@var{mmm-ddd-yyyy}-level-1} or
5021 @file{log-@var{mmm-ddd-yyyy}-full}.
5023 The script also prints the name of each system being dumped to the
5026 @node Scripted Restoration, , Scripted Backups, Backups
5027 @section Using the Restore Script
5032 The @code{tar} distribution does not provide restoring scripts.
5039 @strong{Warning:} The GNU @code{tar} distribution does @emph{not}
5040 provide any such @code{restore} script yet. This section is only
5041 listed here for documentation maintenance purposes. In any case,
5042 all contents is subject to change as things develop.
5045 @FIXME{A section on non-scripted restore may be a good idea.}
5047 To restore files that were archived using a scripted backup, use the
5048 @code{restore} script. The syntax for the script is:
5050 where ***** are the file systems to restore from, and
5051 ***** is a regular expression which specifies which files to
5052 restore. If you specify --all, the script restores all the files
5055 You should start the restore script with the media containing the
5056 first volume of the archive mounted. The script will prompt for other
5057 volumes as they are needed. If the archive is on tape, you don't need
5058 to rewind the tape to to its beginning---if the tape head is
5059 positioned past the beginning of the archive, the script will rewind
5060 the tape as needed. @FIXME-xref{Media, for a discussion of tape
5063 If you specify @samp{--all} as the @var{files} argument, the
5064 @code{restore} script extracts all the files in the archived file
5065 system into the active file system.
5068 @strong{Warning:} The script will delete files from the active file
5069 system if they were not in the file system when the archive was made.
5072 @value{xref-incremental}, and @value{ref-listed-incremental},
5073 for an explanation of how the script makes that determination.
5075 @FIXME{this may be an option, not a given}
5079 @node Choosing, Date input formats, Backups, Top
5080 @chapter Choosing Files and Names for @code{tar}
5083 @FIXME{Melissa (still) Doesn't Really Like This ``Intro'' Paragraph!!!}
5085 Certain options to @code{tar} enable you to specify a name for your
5086 archive. Other options let you decide which files to include or exclude
5087 from the archive, based on when or whether files were modified, whether
5088 the file names do or don't match specified patterns, or whether files
5089 are in specified directories.
5092 * file:: Choosing the Archive's Name
5093 * Selecting Archive Members::
5094 * files:: Reading Names from a File
5095 * exclude:: Excluding Some Files
5097 * after:: Operating Only on New Files
5098 * recurse:: Descending into Directories
5099 * one:: Crossing Filesystem Boundaries
5102 @node file, Selecting Archive Members, Choosing, Choosing
5103 @section Choosing and Naming Archive Files
5104 @cindex Naming an archive
5105 @cindex Archive Name
5106 @cindex Directing output
5107 @cindex Choosing an archive file
5108 @cindex Where is the archive?
5111 @FIXME{should the title of this section actually be, "naming an
5114 By default, @code{tar} uses an archive file name that was compiled when
5115 it was built on the system; usually this name refers to some physical
5116 tape drive on the machine. However, the person who installed @code{tar}
5117 on the system may not set the default to a meaningful value as far as
5118 most users are concerned. As a result, you will usually want to tell
5119 @code{tar} where to find (or create) the archive. The @value{op-file}
5120 option allows you to either specify or name a file to use as the archive
5121 instead of the default archive file location.
5124 @item --file=@var{archive-name}
5125 @itemx -f @var{archive-name}
5126 Name the archive to create or operate on. Use in conjunction with
5130 For example, in this @code{tar} command,
5133 $ @kbd{tar -cvf collection.tar blues folk jazz}
5137 @file{collection.tar} is the name of the archive. It must directly
5138 follow the @samp{-f} option, since whatever directly follows @samp{-f}
5139 @emph{will} end up naming the archive. If you neglect to specify an
5140 archive name, you may end up overwriting a file in the working directory
5141 with the archive you create since @code{tar} will use this file's name
5142 for the archive name.
5144 An archive can be saved as a file in the file system, sent through a
5145 pipe or over a network, or written to an I/O device such as a tape,
5146 floppy disk, or CD write drive.
5148 @cindex Writing new archives
5149 @cindex Archive creation
5150 If you do not name the archive, @code{tar} uses the value of the
5151 environment variable @code{TAPE} as the file name for the archive. If
5152 that is not available, @code{tar} uses a default, compiled-in archive
5153 name, usually that for tape unit zero (ie. @file{/dev/tu00}).
5154 @code{tar} always needs an archive name.
5156 If you use @file{-} as an @var{archive-name}, @code{tar} reads the
5157 archive from standard input (when listing or extracting files), or
5158 writes it to standard output (when creating an archive). If you use
5159 @file{-} as an @var{archive-name} when modifying an archive,
5160 @code{tar} reads the original archive from its standard input and
5161 writes the entire new archive to its standard output.
5163 @FIXME{might want a different example here; this is already used in
5164 "notable tar usages".}
5167 $ @kbd{cd sourcedir; tar -cf - . | (cd targetdir; tar -xf -)}
5172 @cindex Standard input and output
5173 @cindex tar to standard input and output
5174 To specify an archive file on a device attached to a remote machine,
5178 @kbd{--file=@var{hostname}:/@var{dev}/@var{file name}}
5182 @code{tar} will complete the remote connection, if possible, and
5183 prompt you for a username and password. If you use
5184 @samp{--file=@@@var{hostname}:/@var{dev}/@var{file name}}, @code{tar}
5185 will complete the remote connection, if possible, using your username
5186 as the username on the remote machine.
5188 If the archive file name includes a colon (@samp{:}), then it is assumed
5189 to be a file on another machine. If the archive file is
5190 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
5191 host @var{host}. The remote host is accessed using the @code{rsh}
5192 program, with a username of @var{user}. If the username is omitted
5193 (along with the @samp{@@} sign), then your user name will be used.
5194 (This is the normal @code{rsh} behavior.) It is necessary for the
5195 remote machine, in addition to permitting your @code{rsh} access, to
5196 have the @file{/usr/ucb/rmt} program installed. If you need to use a
5197 file whose name includes a colon, then the remote tape drive behavior
5198 can be inhibited by using the @value{op-force-local} option.
5200 @FIXME{i know we went over this yesterday, but bob (and now i do again,
5201 too) thinks it's out of the middle of nowhere. it doesn't seem to tie
5202 into what came before it well enough <<i moved it now, is it better
5203 here?>>. bob also comments that if Amanda isn't free software, we
5204 shouldn't mention it..}
5206 When the archive is being created to @file{/dev/null}, GNU @code{tar}
5207 tries to minimize input and output operations. The Amanda backup
5208 system, when used with GNU @code{tar}, has an initial sizing pass which
5211 @node Selecting Archive Members, files, file, Choosing
5212 @section Selecting Archive Members
5213 @cindex Specifying files to act on
5214 @cindex Specifying archive members
5216 @dfn{File Name arguments} specify which files in the file system
5217 @code{tar} operates on, when creating or adding to an archive, or which
5218 archive members @code{tar} operates on, when reading or deleting from
5219 an archive. @xref{Operations}.
5221 To specify file names, you can include them as the last arguments on
5222 the command line, as follows:
5224 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
5227 If you specify a directory name as a file name argument, all the files
5228 in that directory are operated on by @code{tar}.
5230 If you do not specify files when @code{tar} is invoked with
5231 @value{op-create}, @code{tar} operates on all the non-directory files in
5232 the working directory. If you specify either @value{op-list} or
5233 @value{op-extract}, @code{tar} operates on all the archive members in the
5234 archive. If you specify any operation other than one of these three,
5235 @code{tar} does nothing.
5237 By default, @code{tar} takes file names from the command line. However,
5238 there are other ways to specify file or member names, or to modify the
5239 manner in which @code{tar} selects the files or members upon which to
5240 operate. @FIXME{add xref here}In general, these methods work both for
5241 specifying the names of files and archive members.
5243 @node files, exclude, Selecting Archive Members, Choosing
5244 @section Reading Names from a File
5247 @cindex Reading file names from a file
5248 @cindex Lists of file names
5249 @cindex File Name arguments, alternatives
5250 Instead of giving the names of files or archive members on the command
5251 line, you can put the names into a file, and then use the
5252 @value{op-files-from} option to @code{tar}. Give the name of the file
5253 which contains the list of files to include as the argument to
5254 @samp{--files-from}. In the list, the file names should be separated by
5255 newlines. You will frequently use this option when you have generated
5256 the list of files to archive with the @code{find} utility.
5259 @item --files-from=@var{file name}
5260 @itemx -T @var{file name}
5261 Get names to extract or create from file @var{file name}.
5264 If you give a single dash as a file name for @samp{--files-from}, (i.e.,
5265 you specify either @samp{--files-from=-} or @samp{-T -}), then the file
5266 names are read from standard input.
5268 Unless you are running @code{tar} with @samp{--create}, you can not use
5269 both @samp{--files-from=-} and @samp{--file=-} (@samp{-f -}) in the same
5272 @FIXME{add bob's example, from his message on 2-10-97}
5274 The following example shows how to use @code{find} to generate a list of
5275 files smaller than 400K in length and put that list into a file
5276 called @file{small-files}. You can then use the @samp{-T} option to
5277 @code{tar} to specify the files from that file, @file{small-files}, to
5278 create the archive @file{little.tgz}. (The @samp{-z} option to
5279 @code{tar} compresses the archive with @code{gzip}; @pxref{gzip} for
5283 $ @kbd{find . -size -400 -print > small-files}
5284 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
5288 @FIXME{say more here to conclude the example/section?}
5294 @node nul, , files, files
5296 @unnumberedsubsec @kbd{NUL} Terminated File Names
5299 @cindex File names, terminated by @kbd{NUL}
5300 @cindex @kbd{NUL} terminated file names
5301 The @value{op-null} option causes @value{op-files-from} to read file
5302 names terminated by a @code{NUL} instead of a newline, so files whose
5303 names contain newlines can be archived using @samp{--files-from}.
5307 Only consider @kbd{NUL} terminated file names, instead of files that
5308 terminate in a newline.
5311 The @samp{--null} option is just like the one in GNU @code{xargs} and
5312 @code{cpio}, and is useful with the @samp{-print0} predicate of GNU
5313 @code{find}. In @code{tar}, @samp{--null} also causes
5314 @value{op-directory} options to be treated as file names to archive, in
5315 case there are any files out there called @file{-C}.
5317 This example shows how to use @code{find} to generate a list of files
5318 larger than 800K in length and put that list into a file called
5319 @file{long-files}. The @samp{-print0} option to @code{find} just just
5320 like @samp{-print}, except that it separates files with a @kbd{NUL}
5321 rather than with a newline. You can then run @code{tar} with both the
5322 @samp{--null} and @samp{-T} options to specify that @code{tar} get the
5323 files from that file, @file{long-files}, to create the archive
5324 @file{big.tgz}. The @samp{--null} option to @code{tar} will cause
5325 @code{tar} to recognize the @kbd{NUL} separator between files.
5328 $ @kbd{find . -size +800 -print0 > long-files}
5329 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
5332 @FIXME{say anything else here to conclude the section?}
5334 @node exclude, Wildcards, files, Choosing
5335 @section Excluding Some Files
5336 @cindex File names, excluding files by
5337 @cindex Excluding files by name and pattern
5338 @cindex Excluding files by file system
5341 To avoid operating on files whose names match a particular pattern,
5342 use the @value{op-exclude} or @value{op-exclude-from} options.
5345 @item --exclude=@var{pattern}
5346 Causes @code{tar} to ignore files that match the @var{pattern}.
5350 The @value{op-exclude} option prevents any file or member whose name
5351 matches the shell wildcard (@var{pattern}) from being operated on.
5352 For example, to create an archive with all the contents of the directory
5353 @file{src} except for files whose names end in @file{.o}, use the
5354 command @samp{tar -cf src.tar --exclude='*.o' src}.
5356 A @var{pattern} containing @samp{/} excludes a name if an initial
5357 subsequence of the name's components matches @var{pattern}; a
5358 @var{pattern} without @samp{/} excludes a name if it matches any of its
5359 name components. For example, the pattern @samp{*b/RCS} contains
5360 @samp{/}, so it excludes @file{blob/RCS} and @file{.blob/RCS/f} but not
5361 @file{blob/RCSit/RCS} or @file{/blob/RCS}, whereas the pattern
5362 @samp{RCS} excludes all these names. Conversely, the pattern @samp{*.o}
5363 lacks @samp{/}, so it excludes @file{.f.o}, @file{d/f.o}, and
5366 Other than optionally stripping leading @samp{/} from names
5367 (@pxref{absolute}), patterns and candidate names are used as-is. For
5368 example, trailing @samp{/} is not trimmed from a user-specified name
5369 before deciding whether to exclude it.
5371 You may give multiple @samp{--exclude} options.
5374 @item --exclude-from=@var{file}
5375 @itemx -X @var{file}
5376 Causes @code{tar} to ignore files that match the patterns listed in
5380 @findex exclude-from
5381 Use the @samp{--exclude-from=@var{file-of-patterns}} option to read a
5382 list of shell wildcards, one per line, from @var{file}; @code{tar} will
5383 ignore files matching those regular expressions. Thus if @code{tar} is
5384 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
5385 single line @file{*.o}, no files whose names end in @file{.o} will be
5386 added to the archive.
5388 @FIXME{do the exclude options files need to have stuff separated by
5389 newlines the same as the files-from option does?}
5392 * problems with exclude::
5395 @node problems with exclude, , exclude, exclude
5396 @unnumberedsubsec Problems with Using the @code{exclude} Options
5398 Some users find @samp{exclude} options confusing. Here are some common
5403 The main operating mode of @code{tar} does not act on a path name
5404 explicitly listed on the command line if one of its file name
5405 components is excluded. In the example above, if
5406 you create an archive and exclude files that end with @samp{*.o}, but
5407 explicitly name the file @samp{dir.o/foo} after all the options have been
5408 listed, @samp{dir.o/foo} will be excluded from the archive.
5411 You can sometimes confuse the meanings of @value{op-exclude} and
5412 @value{op-exclude-from}. Be careful: use @value{op-exclude} when files
5413 to be excluded are given as a pattern on the command line. Use
5414 @samp{--exclude-from=@var{file-of-patterns}} to introduce the name of a
5415 file which contains a list of patterns, one per line; each of these
5416 patterns can exclude zero, one, or many files.
5419 When you use @value{op-exclude}, be sure to quote the @var{pattern}
5420 parameter, so GNU @code{tar} sees wildcard characters like @samp{*}.
5421 If you do not do this, the shell might expand the @samp{*} itself
5422 using files at hand, so @code{tar} might receive a list of files
5423 instead of one pattern, or none at all, making the command somewhat
5424 illegal. This might not correspond to what you want.
5429 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
5436 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
5440 You must use use shell syntax, or globbing, rather than @code{regexp}
5441 syntax, when using exclude options in @code{tar}. If you try to use
5442 @code{regexp} syntax to describe files to be excluded, your command
5446 In earlier versions of @code{tar}, what is now the
5447 @samp{--exclude-from=@var{file-of-patterns}} option was called
5448 @samp{--exclude-@var{pattern}} instead. Now,
5449 @samp{--exclude=@var{pattern}} applies to patterns listed on the command
5450 line and @samp{--exclude-from=@var{file-of-patterns}} applies to
5451 patterns listed in a file.
5455 @node Wildcards, after, exclude, Choosing
5456 @section Wildcards Patterns and Matching
5458 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
5459 @samp{*} or @samp{?} for example, are replaced and expanded into all
5460 existing files matching the given pattern. However, @code{tar} often
5461 uses wildcard patterns for matching (or globbing) archive members instead
5462 of actual files in the filesystem. Wildcard patterns are also used for
5463 verifying volume labels of @code{tar} archives. This section has the
5464 purpose of explaining wildcard syntax for @code{tar}.
5466 @FIXME{the next few paragraphs need work.}
5468 A @var{pattern} should be written according to shell syntax, using wildcard
5469 characters to effect globbing. Most characters in the pattern stand
5470 for themselves in the matched string, and case is significant: @samp{a}
5471 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
5472 pattern matches any single character in the matched string. The character
5473 @samp{*} in the pattern matches zero, one, or more single characters in
5474 the matched string. The character @samp{\} says to take the following
5475 character of the pattern @emph{literally}; it is useful when one needs to
5476 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
5478 The character @samp{[}, up to the matching @samp{]}, introduces a character
5479 class. A @dfn{character class} is a list of acceptable characters
5480 for the next single character of the matched string. For example,
5481 @samp{[abcde]} would match any of the first five letters of the alphabet.
5482 Note that within a character class, all of the ``special characters''
5483 listed above other than @samp{\} lose their special meaning; for example,
5484 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
5485 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
5486 the characters @samp{-} and @samp{]} must either come @emph{first} or
5487 @emph{last} in a character class.)
5489 @cindex Excluding characters from a character class
5490 @cindex Character class, excluding characters from
5491 If the first character of the class after the opening @samp{[}
5492 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
5493 Rather than listing character to match, it lists those characters which
5494 are @emph{forbidden} as the next single character of the matched string.
5496 Other characters of the class stand for themselves. The special
5497 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
5498 letters, is meant to represent all characters between @var{a} and
5501 @FIXME{need to add a sentence or so here to make this clear for those
5502 who don't have dan around.}
5504 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
5505 special for wildcard matches. However, if a pattern completely matches
5506 a directory prefix of a matched string, then it matches the full matched
5507 string: excluding a directory also excludes all the files beneath it.
5509 There are some discussions floating in the air and asking for modifications
5510 in the way GNU @code{tar} accomplishes wildcard matches. We perceive
5511 any change of semantics in this area as a delicate thing to impose on
5512 GNU @code{tar} users. On the other hand, the GNU project should be
5513 progressive enough to correct any ill design: compatibility at all price
5514 is not always a good attitude. In conclusion, it is @emph{possible}
5515 that slight amendments be later brought to the previous description.
5516 Your opinions on the matter are welcome.
5518 @node after, recurse, Wildcards, Choosing
5519 @section Operating Only on New Files
5520 @cindex Excluding file by age
5521 @cindex Modification time, excluding files by
5522 @cindex Age, excluding files by
5525 The @value{op-after-date} option causes @code{tar} to only work on files
5526 whose modification or inode-changed times are newer than the @var{date}
5527 given. If you use this option when creating or appending to an archive,
5528 the archive will only include new files. If you use @samp{--after-date}
5529 when extracting an archive, @code{tar} will only extract files newer
5530 than the @var{date} you specify.
5532 If you only want @code{tar} to make the date comparison based on
5533 modification of the actual contents of the file (rather than inode
5534 changes), then use the @value{op-newer-mtime} option.
5536 You may use these options with any operation. Note that these options
5537 differ from the @value{op-update} operation in that they allow you to
5538 specify a particular date against which @code{tar} can compare when
5539 deciding whether or not to archive the files.
5542 @item --after-date=@var{date}
5543 @itemx --newer=@var{date}
5544 @itemx -N @var{date}
5545 Only store files newer than @var{date}.
5547 Acts on files only if their modification or inode-changed times are
5548 later than @var{date}. Use in conjunction with any operation.
5550 @item --newer-mtime=@var{date}
5551 Acts like @value{op-after-date}, but only looks at modification times.
5554 These options limit @code{tar} to only operating on files which have
5555 been modified after the date specified. A file is considered to have
5556 changed if the contents have been modified, or if the owner,
5557 permissions, and so forth, have been changed. (For more information on
5558 how to specify a date, see @ref{Date input formats}; remember that the
5559 entire date argument must be quoted if it contains any spaces.)
5561 Gurus would say that @value{op-after-date} tests both the @code{mtime}
5562 (time the contents of the file were last modified) and @code{ctime}
5563 (time the file's status was last changed: owner, permissions, etc)
5564 fields, while @value{op-newer-mtime} tests only @code{mtime} field.
5566 To be precise, @value{op-after-date} checks @emph{both} @code{mtime} and
5567 @code{ctime} and processes the file if either one is more recent than
5568 @var{date}, while @value{op-newer-mtime} only checks @code{mtime} and
5569 disregards @code{ctime}. Neither uses @code{atime} (the last time the
5570 contents of the file were looked at).
5572 Date specifiers can have embedded spaces. Because of this, you may need
5573 to quote date arguments to keep the shell from parsing them as separate
5576 @FIXME{Need example of --newer-mtime with quoted argument.}
5579 @strong{Please Note:} @value{op-after-date} and @value{op-newer-mtime}
5580 should not be used for incremental backups. Some files (such as those
5581 in renamed directories) are not selected properly by these options.
5582 @xref{incremental and listed-incremental}.
5585 To select files newer than the modification time of a file that already
5586 exists, you can use the @samp{--reference} (@samp{-r}) option of GNU
5587 @code{date}, available in GNU shell utilities 1.13 or later. It returns
5588 the time stamp of the already-existing file; this time stamp expands to
5589 become the referent date which @samp{--newer} uses to determine which
5590 files to archive. For example, you could say,
5593 $ @kbd{tar -cf @var{archive.tar} --newer="`date -r @var{file}`" /home}
5597 @FIXME{which tells -- need to fill this in!}
5599 @node recurse, one, after, Choosing
5600 @section Descending into Directories
5601 @cindex Avoiding recursion in directories
5602 @cindex Descending directories, avoiding
5603 @cindex Directories, avoiding recursion
5604 @cindex Recursion in directories, avoiding
5607 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
5609 @FIXME{show dan bob's comments, from 2-10-97}
5611 Usually, @code{tar} will recursively explore all directories (either
5612 those given on the command line or through the @value{op-files-from}
5613 option) for the various files they contain. However, you may not always
5614 want @code{tar} to act this way.
5616 The @value{op-no-recursion} option inhibits @code{tar}'s recursive descent
5617 into specified directories. If you specify @samp{--no-recursion}, you can
5618 use the @code{find} utility for hunting through levels of directories to
5619 construct a list of file names which you could then pass to @code{tar}.
5620 @code{find} allows you to be more selective when choosing which files to
5621 archive; see @ref{files} for more information on using @code{find} with
5622 @code{tar}, or look.
5625 @item --no-recursion
5626 Prevents @code{tar} from recursively descending directories.
5629 When you use @samp{--no-recursion}, GNU @code{tar} grabs directory entries
5630 themselves, but does not descend on them recursively. Many people use
5631 @code{find} for locating files they want to back up, and since
5632 @code{tar} @emph{usually} recursively descends on directories, they have
5633 to use the @samp{@w{! -d}} option to @code{find} @FIXME{needs more
5634 explanation or a cite to another info file}as they usually do not want
5635 all the files in a directory. They then use the @value{op-file-from}
5636 option to archive the files located via @code{find}.
5638 The problem when restoring files archived in this manner is that the
5639 directories themselves are not in the archive; so the
5640 @value{op-same-permissions} option does not affect them---while users
5641 might really like it to. Specifying @value{op-no-recursion} is a way to
5642 tell @code{tar} to grab only the directory entries given to it, adding
5643 no new files on its own.
5645 @FIXME{example here}
5647 @node one, , recurse, Choosing
5648 @section Crossing Filesystem Boundaries
5649 @cindex File system boundaries, not crossing
5652 @code{tar} will normally automatically cross file system boundaries in
5653 order to archive files which are part of a directory tree. You can
5654 change this behavior by running @code{tar} and specifying
5655 @value{op-one-file-system}. This option only affects files that are
5656 archived because they are in a directory that is being archived;
5657 @code{tar} will still archive files explicitly named on the command line
5658 or through @value{op-files-from}, regardless of where they reside.
5661 @item --one-file-system
5663 Prevents @code{tar} from crossing file system boundaries when
5664 archiving. Use in conjunction with any write operation.
5667 The @samp{--one-file-system} option causes @code{tar} to modify its
5668 normal behavior in archiving the contents of directories. If a file in
5669 a directory is not on the same filesystem as the directory itself, then
5670 @code{tar} will not archive that file. If the file is a directory
5671 itself, @code{tar} will not archive anything beneath it; in other words,
5672 @code{tar} will not cross mount points.
5674 It is reported that using this option, the mount point is is archived,
5675 but nothing under it.
5677 This option is useful for making full or incremental archival backups of
5678 a file system. If this option is used in conjunction with
5679 @value{op-verbose}, files that are excluded are mentioned by name on the
5683 * directory:: Changing Directory
5684 * absolute:: Absolute File Names
5687 @node directory, absolute, one, one
5688 @subsection Changing the Working Directory
5690 @FIXME{need to read over this node now for continuity; i've switched
5691 things around some.}
5693 @cindex Changing directory mid-stream
5694 @cindex Directory, changing mid-stream
5695 @cindex Working directory, specifying
5698 To change the working directory in the middle of a list of file names,
5699 either on the command line or in a file specified using
5700 @value{op-files-from}, use @value{op-directory}. This will change the
5701 working directory to the directory @var{directory} after that point in
5705 @item --directory=@var{directory}
5706 @itemx -C @var{directory}
5707 Changes the working directory in the middle of a command line.
5713 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
5717 will place the files @file{grape} and @file{prune} from the current
5718 directory into the archive @file{jams.tar}, followed by the file
5719 @file{cherry} from the directory @file{food}. This option is especially
5720 useful when you have several widely separated files that you want to
5721 store in the same archive.
5723 Note that the file @file{cherry} is recorded in the archive under the
5724 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
5725 archive will contain three files that all appear to have come from the
5726 same directory; if the archive is extracted with plain @samp{tar
5727 --extract}, all three files will be written in the current directory.
5729 Contrast this with the command,
5732 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
5736 which records the third file in the archive under the name
5737 @file{red/cherry} so that, if the archive is extracted using
5738 @samp{tar --extract}, the third file will be written in a subdirectory
5739 named @file{orange-colored}.
5741 You can use the @samp{--directory} option to make the archive
5742 independent of the original name of the directory holding the files.
5743 The following command places the files @file{/etc/passwd},
5744 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
5748 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
5752 However, the names of the archive members will be exactly what they were
5753 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
5754 They will not appear to be related by file name to the original
5755 directories where those files were located.
5757 Note that @samp{--directory} options are interpreted consecutively. If
5758 @samp{--directory} specifies a relative file name, it is interpreted
5759 relative to the then current directory, which might not be the same as
5760 the original current working directory of @code{tar}, due to a previous
5761 @samp{--directory} option.
5763 @FIXME{dan: does this mean that you *can* use the short option form, but
5764 you can *not* use the long option form with --files-from? or is this
5767 When using @samp{--files-from} (@pxref{files}), you can put @samp{-C}
5768 options in the file list. Unfortunately, you cannot put
5769 @samp{--directory} options in the file list. (This interpretation can
5770 be disabled by using the @value{op-null} option.)
5772 @node absolute, , directory, one
5773 @subsection Absolute File Names
5778 @itemx --absolute-names
5779 Do not strip leading slashes from file names.
5782 By default, GNU @code{tar} drops a leading @samp{/} on input or output.
5783 This option turns off this behavior.
5784 Tt is roughly equivalent to changing to the
5785 root directory before running @code{tar} (except it also turns off the
5786 usual warning message).
5788 When @code{tar} extracts archive members from an archive, it strips any
5789 leading slashes (@samp{/}) from the member name. This causes absolute
5790 member names in the archive to be treated as relative file names. This
5791 allows you to have such members extracted wherever you want, instead of
5792 being restricted to extracting the member in the exact directory named
5793 in the archive. For example, if the archive member has the name
5794 @file{/etc/passwd}, @code{tar} will extract it as if the name were
5795 really @file{etc/passwd}.
5797 Other @code{tar} programs do not do this. As a result, if you create an
5798 archive whose member names start with a slash, they will be difficult
5799 for other people with a non-GNU @code{tar} program to use. Therefore,
5800 GNU @code{tar} also strips leading slashes from member names when
5801 putting members into the archive. For example, if you ask @code{tar} to
5802 add the file @file{/bin/ls} to an archive, it will do so, but the member
5803 name will be @file{bin/ls}.
5805 If you use the @value{op-absolute-names} option, @code{tar} will do
5806 neither of these transformations.
5808 To archive or extract files relative to the root directory, specify
5809 the @value{op-absolute-names} option.
5811 Normally, @code{tar} acts on files relative to the working
5812 directory---ignoring superior directory names when archiving, and
5813 ignoring leading slashes when extracting.
5815 When you specify @value{op-absolute-names}, @code{tar} stores file names
5816 including all superior directory names, and preserves leading slashes.
5817 If you only invoked @code{tar} from the root directory you would never
5818 need the @value{op-absolute-names} option, but using this option may be
5819 more convenient than switching to root.
5821 @FIXME{Should be an example in the tutorial/wizardry section using this
5822 to transfer files between systems.}
5824 @FIXME{Is write access an issue?}
5827 @item --absolute-names
5828 Preserves full file names (including superior directory names) when
5829 archiving files. Preserves leading slash when extracting files.
5833 @FIXME{this is still horrible; need to talk with dan on monday.}
5835 @code{tar} prints out a message about removing the @samp{/} from file
5836 names. This message appears once per GNU @code{tar} invocation. It
5837 represents something which ought to be told; ignoring what it means can
5838 cause very serious surprises, later.
5840 Some people, nevertheless, do not want to see this message. Wanting to
5841 play really dangerously, one may of course redirect @code{tar} standard
5842 error to the sink. For example, under @code{sh}:
5845 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
5849 Another solution, both nicer and simpler, would be to change to
5850 the @file{/} directory first, and then avoid absolute notation.
5854 $ @kbd{(cd / && tar -c -f archive.tar home)}
5855 $ @kbd{tar -c -f archive.tar -C / home}
5858 @node Date input formats, Formats, Choosing, Top
5859 @chapter Date input formats
5861 @cindex date input formats
5865 Our units of temporal measurement, from seconds on up to months, are so
5866 complicated, asymmetrical and disjunctive so as to make coherent mental
5867 reckoning in time all but impossible. Indeed, had some tyrannical god
5868 contrived to enslave our minds to time, to make it all but impossible
5869 for us to escape subjection to sodden routines and unpleasant surprises,
5870 he could hardly have done better than handing down our present system.
5871 It is like a set of trapezoidal building blocks, with no vertical or
5872 horizontal surfaces, like a language in which the simplest thought
5873 demands ornate constructions, useless particles and lengthy
5874 circumlocutions. Unlike the more successful patterns of language and
5875 science, which enable us to face experience boldly or at least
5876 level-headedly, our system of temporal calculation silently and
5877 persistently encourages our terror of time.
5879 @dots{} It is as though architects had to measure length in feet, width
5880 in meters and height in ells; as though basic instruction manuals
5881 demanded a knowledge of five different languages. It is no wonder then
5882 that we often look into our own immediate past or future, last Tuesday
5883 or a week from Sunday, with feelings of helpless confusion. @dots{}
5885 --- Robert Grudin, @cite{Time and the Art of Living}.
5888 This section describes the textual date representations that GNU
5889 programs accept. These are the strings you, as a user, can supply as
5890 arguments to the various programs. The C interface (via the
5891 @code{getdate} function) is not described here.
5893 @cindex beginning of time, for Unix
5894 @cindex epoch, for Unix
5895 Although the date syntax here can represent any possible time since zero
5896 A.D., computer integers are not big enough for such a (comparatively)
5897 long time. The earliest date semantically allowed on Unix systems is
5898 midnight, 1 January 1970 UCT.
5901 * General date syntax:: Common rules.
5902 * Calendar date item:: 19 Dec 1994.
5903 * Time of day item:: 9:20pm.
5904 * Time zone item:: EST, GMT, UTC, ...
5905 * Day of week item:: Monday and others.
5906 * Relative item in date strings:: next tuesday, 2 years ago.
5907 * Pure numbers in date strings:: 19931219, 1440.
5908 * Authors of getdate:: Bellovin, Salz, Berets, et al.
5912 @node General date syntax, Calendar date item, Date input formats, Date input formats
5913 @section General date syntax
5915 @cindex general date syntax
5917 @cindex items in date strings
5918 A @dfn{date} is a string, possibly empty, containing many items
5919 separated by white space. The white space may be omitted when no
5920 ambiguity arises. The empty string means the beginning of today (i.e.,
5921 midnight). Order of the items is immaterial. A date string may contain
5922 many flavors of items:
5925 @item calendar date items
5926 @item time of the day items
5927 @item time zone items
5928 @item day of the week items
5929 @item relative items
5933 @noindent We describe each of these item types in turn, below.
5935 @cindex numbers, written-out
5936 @cindex ordinal numbers
5937 @findex first @r{in date strings}
5938 @findex next @r{in date strings}
5939 @findex last @r{in date strings}
5940 A few numbers may be written out in words in most contexts. This is
5941 most useful for specifying day of the week items or relative items (see
5942 below). Here is the list: @samp{first} for 1, @samp{next} for 2,
5943 @samp{third} for 3, @samp{fourth} for 4, @samp{fifth} for 5,
5944 @samp{sixth} for 6, @samp{seventh} for 7, @samp{eighth} for 8,
5945 @samp{ninth} for 9, @samp{tenth} for 10, @samp{eleventh} for 11 and
5946 @samp{twelfth} for 12. Also, @samp{last} means exactly @math{-1}.
5948 @cindex months, written-out
5949 When a month is written this way, it is still considered to be written
5950 numerically, instead of being ``spelled in full''; this changes the
5953 @cindex case, ignored in dates
5954 @cindex comments, in dates
5955 Alphabetic case is completely ignored in dates. Comments may be introduced
5956 between round parentheses, as long as included parentheses are properly
5957 nested. Hyphens not followed by a digit are currently ignored. Leading
5958 zeros on numbers are ignored.
5961 @node Calendar date item, Time of day item, General date syntax, Date input formats
5962 @section Calendar date item
5964 @cindex calendar date item
5966 A @dfn{calendar date item} specifies a day of the year. It is
5967 specified differently, depending on whether the month is specified
5968 numerically or literally. All these strings specify the same calendar date:
5971 1970-09-17 # ISO 8601.
5972 70-9-17 # This century assumed by default.
5973 70-09-17 # Leading zeros are ignored.
5974 9/17/72 # Common U.S. writing.
5976 24 Sept 72 # September has a special abbreviation.
5977 24 Sep 72 # Three-letter abbreviations always allowed.
5983 The year can also be omitted. In this case, the last specified year is
5984 used, or the current year if none. For example:
5993 @cindex ISO 8601 date format
5994 @cindex date format, ISO 8601
5995 For numeric months, the ISO 8601 format
5996 @samp{@var{year}-@var{month}-@var{day}} is allowed, where @var{year} is
5997 any positive number, @var{month} is a number between 01 and 12, and
5998 @var{day} is a number between 01 and 31. A leading zero must be present
5999 if a number is less than ten. If @var{year} is less than 100, then 1900
6000 is added to it to force a date in this century. The construct
6001 @samp{@var{month}/@var{day}/@var{year}}, popular in the United States,
6002 is accepted. Also @samp{@var{month}/@var{day}}, omitting the year.
6004 @cindex month names in date strings
6005 @cindex abbreviations for months
6006 Literal months may be spelled out in full: @samp{January},
6007 @samp{February}, @samp{March}, @samp{April}, @samp{May}, @samp{June},
6008 @samp{July}, @samp{August}, @samp{September}, @samp{October},
6009 @samp{November} or @samp{December}. Literal months may be abbreviated
6010 to their first three letters, possibly followed by an abbreviating dot.
6011 It is also permitted to write @samp{Sept} instead of @samp{September}.
6013 When months are written literally, the calendar date may be given as any
6017 @var{day} @var{month} @var{year}
6018 @var{day} @var{month}
6019 @var{month} @var{day} @var{year}
6020 @var{day}-@var{month}-@var{year}
6023 Or, omitting the year:
6026 @var{month} @var{day}
6030 @node Time of day item, Time zone item, Calendar date item, Date input formats
6031 @section Time of day item
6033 @cindex time of day item
6035 A @dfn{time of day item} in date strings specifies the time on a given
6036 day. Here are some examples, all of which represent the same time:
6042 20:02-0500 # In EST (U.S. Eastern Standard Time).
6045 More generally, the time of the day may be given as
6046 @samp{@var{hour}:@var{minute}:@var{second}}, where @var{hour} is
6047 a number between 0 and 23, @var{minute} is a number between 0 and
6048 59, and @var{second} is a number between 0 and 59. Alternatively,
6049 @samp{:@var{second}} can be omitted, in which case it is taken to
6052 @findex am @r{in date strings}
6053 @findex pm @r{in date strings}
6054 @findex midnight @r{in date strings}
6055 @findex noon @r{in date strings}
6056 If the time is followed by @samp{am} or @samp{pm} (or @samp{a.m.}
6057 or @samp{p.m.}), @var{hour} is restricted to run from 1 to 12, and
6058 @samp{:@var{minute}} may be omitted (taken to be zero). @samp{am}
6059 indicates the first half of the day, @samp{pm} indicates the second
6060 half of the day. In this notation, 12 is the predecessor of 1:
6061 midnight is @samp{12am} while noon is @samp{12pm}.
6062 (This is the zero-oriented interpretation of @samp{12am} and @samp{12pm},
6063 as opposed to the old tradition derived from Latin
6064 which uses @samp{12m} for noon and @samp{12pm} for midnight.)
6066 @cindex time zone correction
6067 @cindex minutes, time zone correction by
6068 The time may be followed by a time zone correction,
6069 expressed as @samp{@var{s}@var{hh}@var{mm}}, where @var{s} is @samp{+}
6070 or @samp{-}, @var{hh} is a number of zone hours and @var{mm} is a number
6071 of zone minutes. When a time zone correction is given this way, it
6072 forces interpretation of the time in UTC, overriding any previous
6073 specification for the time zone or the local time zone. The @var{minute}
6074 part of the time of the day may not be elided when a time zone correction
6077 Either @samp{am}/@samp{pm} or a time zone correction may be specified,
6081 @node Time zone item, Day of week item, Time of day item, Date input formats
6082 @section Time zone item
6084 @cindex time zone item
6086 A @dfn{time zone item} specifies an international time zone, indicated
6087 by a small set of letters, e.g.@: @samp{UTC} for Coordinated Universal
6088 Time. Any included period is ignored. By following a non-DST time zone
6089 by the string @samp{DST} in a separate word (that is, separated by some
6090 white space), the corresponding DST time zone may be specified.
6092 Time zone items are obsolescent and are not recommended, because they
6093 are ambiguous; for example, @samp{EST} has a different meaning in
6094 Australia than in the United States. Instead, it's better to use
6095 unambiguous numeric time zone corrections like @samp{-0500}, as
6096 described in the previous section.
6098 @node Day of week item, Relative item in date strings, Time zone item, Date input formats
6099 @section Day of week item
6101 @cindex day of week item
6103 The explicit mention of a day of the week will forward the date
6104 (only if necessary) to reach that day of the week in the future.
6106 Days of the week may be spelled out in full: @samp{Sunday},
6107 @samp{Monday}, @samp{Tuesday}, @samp{Wednesday}, @samp{Thursday},
6108 @samp{Friday} or @samp{Saturday}. Days may be abbreviated to their
6109 first three letters, optionally followed by a period. The special
6110 abbreviations @samp{Tues} for @samp{Tuesday}, @samp{Wednes} for
6111 @samp{Wednesday} and @samp{Thur} or @samp{Thurs} for @samp{Thursday} are
6114 @findex next @var{day}
6115 @findex last @var{day}
6116 A number may precede a day of the week item to move forward
6117 supplementary weeks. It is best used in expression like @samp{third
6118 monday}. In this context, @samp{last @var{day}} or @samp{next
6119 @var{day}} is also acceptable; they move one week before or after
6120 the day that @var{day} by itself would represent.
6122 A comma following a day of the week item is ignored.
6125 @node Relative item in date strings, Pure numbers in date strings, Day of week item, Date input formats
6126 @section Relative item in date strings
6128 @cindex relative items in date strings
6129 @cindex displacement of dates
6131 @dfn{Relative items} adjust a date (or the current date if none) forward
6132 or backward. The effects of relative items accumulate. Here are some
6142 @findex year @r{in date strings}
6143 @findex month @r{in date strings}
6144 @findex fortnight @r{in date strings}
6145 @findex week @r{in date strings}
6146 @findex day @r{in date strings}
6147 @findex hour @r{in date strings}
6148 @findex minute @r{in date strings}
6149 The unit of time displacement may be selected by the string @samp{year}
6150 or @samp{month} for moving by whole years or months. These are fuzzy
6151 units, as years and months are not all of equal duration. More precise
6152 units are @samp{fortnight} which is worth 14 days, @samp{week} worth 7
6153 days, @samp{day} worth 24 hours, @samp{hour} worth 60 minutes,
6154 @samp{minute} or @samp{min} worth 60 seconds, and @samp{second} or
6155 @samp{sec} worth one second. An @samp{s} suffix on these units is
6156 accepted and ignored.
6158 @findex ago @r{in date strings}
6159 The unit of time may be preceded by a multiplier, given as an optionally
6160 signed number. Unsigned numbers are taken as positively signed. No
6161 number at all implies 1 for a multiplier. Following a relative item by
6162 the string @samp{ago} is equivalent to preceding the unit by a
6163 multiplier with value @math{-1}.
6165 @findex day @r{in date strings}
6166 @findex tomorrow @r{in date strings}
6167 @findex yesterday @r{in date strings}
6168 The string @samp{tomorrow} is worth one day in the future (equivalent
6169 to @samp{day}), the string @samp{yesterday} is worth
6170 one day in the past (equivalent to @samp{day ago}).
6172 @findex now @r{in date strings}
6173 @findex today @r{in date strings}
6174 @findex this @r{in date strings}
6175 The strings @samp{now} or @samp{today} are relative items corresponding
6176 to zero-valued time displacement, these strings come from the fact
6177 a zero-valued time displacement represents the current time when not
6178 otherwise change by previous items. They may be used to stress other
6179 items, like in @samp{12:00 today}. The string @samp{this} also has
6180 the meaning of a zero-valued time displacement, but is preferred in
6181 date strings like @samp{this thursday}.
6183 When a relative item makes the resulting date to cross the boundary
6184 between DST and non-DST (or vice-versa), the hour is adjusted according
6188 @node Pure numbers in date strings, Authors of getdate, Relative item in date strings, Date input formats
6189 @section Pure numbers in date strings
6191 @cindex pure numbers in date strings
6193 The precise interpretation of a pure decimal number depends on
6194 the context in the date string.
6196 If the decimal number is of the form @var{yyyy}@var{mm}@var{dd} and no
6197 other calendar date item (@pxref{Calendar date item}) appears before it
6198 in the date string, then @var{yyyy} is read as the year, @var{mm} as the
6199 month number and @var{dd} as the day of the month, for the specified
6202 If the decimal number is of the form @var{hh}@var{mm} and no other time
6203 of day item appears before it in the date string, then @var{hh} is read
6204 as the hour of the day and @var{mm} as the minute of the hour, for the
6205 specified time of the day. @var{mm} can also be omitted.
6207 If both a calendar date and a time of day appear to the left of a number
6208 in the date string, but no relative item, then the number overrides the
6212 @node Authors of getdate, , Pure numbers in date strings, Date input formats
6213 @section Authors of @code{getdate}
6215 @cindex authors of @code{getdate}
6217 @cindex Bellovin, Steven M.
6220 @cindex MacKenzie, David
6221 @cindex Meyering, Jim
6222 @code{getdate} was originally implemented by Steven M. Bellovin
6223 (@samp{smb@@research.att.com}) while at the University of North Carolina
6224 at Chapel Hill. The code was later tweaked by a couple of people on
6225 Usenet, then completely overhauled by Rich $alz (@samp{rsalz@@bbn.com})
6226 and Jim Berets (@samp{jberets@@bbn.com}) in August, 1990. Various
6227 revisions for the GNU system were made by David MacKenzie, Jim Meyering,
6232 This chapter was originally produced by Fran@,{c}ois Pinard
6233 (@samp{pinard@@iro.umontreal.ca}) from the @file{getdate.y} source code,
6234 and then edited by K.@: Berry (@samp{kb@@cs.umb.edu}).
6236 @node Formats, Media, Date input formats, Top
6237 @chapter Controlling the Archive Format
6239 @FIXME{need an intro here}
6242 * Portability:: Making @code{tar} Archives More Portable
6243 * Compression:: Using Less Space through Compression
6244 * Attributes:: Handling File Attributes
6245 * Standard:: The Standard Format
6246 * Extensions:: GNU Extensions to the Archive Format
6247 * cpio:: Comparison of @code{tar} and @code{cpio}
6250 @node Portability, Compression, Formats, Formats
6251 @section Making @code{tar} Archives More Portable
6253 Creating a @code{tar} archive on a particular system that is meant to be
6254 useful later on many other machines and with other versions of @code{tar}
6255 is more challenging than you might think. @code{tar} archive formats
6256 have been evolving since the first versions of Unix. Many such formats
6257 are around, and are not always compatible with each other. This section
6258 discusses a few problems, and gives some advice about making @code{tar}
6259 archives more portable.
6261 One golden rule is simplicity. For example, limit your @code{tar}
6262 archives to contain only regular files and directories, avoiding
6263 other kind of special files. Do not attempt to save sparse files or
6264 contiguous files as such. Let's discuss a few more problems, in turn.
6267 * Portable Names:: Portable Names
6268 * dereference:: Symbolic Links
6269 * old:: Old V7 Archives
6270 * posix:: POSIX archives
6271 * Checksumming:: Checksumming Problems
6274 @node Portable Names, dereference, Portability, Portability
6275 @subsection Portable Names
6277 Use @emph{straight} file and directory names, made up of printable
6278 ASCII characters, avoiding colons, slashes, backslashes, spaces, and
6279 other @emph{dangerous} characters. Avoid deep directory nesting.
6280 Accounting for oldish System V machines, limit your file and directory
6281 names to 14 characters or less.
6283 If you intend to have your @code{tar} archives to be read under MSDOS,
6284 you should not rely on case distinction for file names, and you might
6285 use the GNU @code{doschk} program for helping you further diagnosing
6286 illegal MSDOS names, which are even more limited than System V's.
6288 @node dereference, old, Portable Names, Portability
6289 @subsection Symbolic Links
6290 @cindex File names, using symbolic links
6291 @cindex Symbolic link as file name
6293 Normally, when @code{tar} archives a symbolic link, it writes a
6294 block to the archive naming the target of the link. In that way, the
6295 @code{tar} archive is a faithful record of the filesystem contents.
6296 @value{op-dereference} is used with @value{op-create}, and causes @code{tar}
6297 to archive the files symbolic links point to, instead of the links
6298 themselves. When this option is used, when @code{tar} encounters a
6299 symbolic link, it will archive the linked-to file, instead of simply
6300 recording the presence of a symbolic link.
6302 The name under which the file is stored in the file system is not
6303 recorded in the archive. To record both the symbolic link name and
6304 the file name in the system, archive the file under both names. If
6305 all links were recorded automatically by @code{tar}, an extracted file
6306 might be linked to a file name that no longer exists in the file
6309 If a linked-to file is encountered again by @code{tar} while creating
6310 the same archive, an entire second copy of it will be stored. (This
6311 @emph{might} be considered a bug.)
6313 So, for portable archives, do not archive symbolic links as such,
6314 and use @value{op-dereference}: many systems do not support
6315 symbolic links, and moreover, your distribution might be unusable if
6316 it contains unresolved symbolic links.
6318 @node old, posix, dereference, Portability
6319 @subsection Old V7 Archives
6320 @cindex Format, old style
6321 @cindex Old style format
6322 @cindex Old style archives
6324 Certain old versions of @code{tar} cannot handle additional
6325 information recorded by newer @code{tar} programs. To create an
6326 archive in V7 format (not ANSI), which can be read by these old
6327 versions, specify the @value{op-old-archive} option in
6328 conjunction with the @value{op-create}. @code{tar} also
6329 accepts @samp{--portability} for this option. When you specify it,
6330 @code{tar} leaves out information about directories, pipes, fifos,
6331 contiguous files, and device files, and specifies file ownership by
6332 group and user IDs instead of group and user names.
6334 When updating an archive, do not use @value{op-old-archive}
6335 unless the archive was created with using this option.
6337 In most cases, a @emph{new} format archive can be read by an @emph{old}
6338 @code{tar} program without serious trouble, so this option should
6339 seldom be needed. On the other hand, most modern @code{tar}s are
6340 able to read old format archives, so it might be safer for you to
6341 always use @value{op-old-archive} for your distributions.
6343 @node posix, Checksumming, old, Portability
6344 @subsection GNU @code{tar} and POSIX @code{tar}
6346 GNU @code{tar} was based on an early draft of the POSIX 1003.1
6347 @code{ustar} standard. GNU extensions to @code{tar}, such as the
6348 support for file names longer than 100 characters, use portions of the
6349 @code{tar} header record which were specified in that POSIX draft as
6350 unused. Subsequent changes in POSIX have allocated the same parts of
6351 the header record for other purposes. As a result, GNU @code{tar} is
6352 incompatible with the current POSIX spec, and with @code{tar} programs
6355 We plan to reimplement these GNU extensions in a new way which is
6356 upward compatible with the latest POSIX @code{tar} format, but we
6357 don't know when this will be done.
6359 In the mean time, there is simply no telling what might happen if you
6360 read a GNU @code{tar} archive, which uses the GNU extensions, using
6361 some other @code{tar} program. So if you want to read the archive
6362 with another @code{tar} program, be sure to write it using the
6363 @samp{--old-archive} option (@samp{-o}).
6365 @FIXME{is there a way to tell which flavor of tar was used to write a
6366 particular archive before you try to read it?}
6368 Traditionally, old @code{tar}s have a limit of 100 characters. GNU
6369 @code{tar} attempted two different approaches to overcome this limit,
6370 using and extending a format specified by a draft of some P1003.1.
6371 The first way was not that successful, and involved @file{@@MaNgLeD@@}
6372 file names, or such; while a second approach used @file{././@@LongLink}
6373 and other tricks, yielding better success. In theory, GNU @code{tar}
6374 should be able to handle file names of practically unlimited length.
6375 So, if GNU @code{tar} fails to dump and retrieve files having more
6376 than 100 characters, then there is a bug in GNU @code{tar}, indeed.
6378 But, being strictly POSIX, the limit was still 100 characters.
6379 For various other purposes, GNU @code{tar} used areas left unassigned
6380 in the POSIX draft. POSIX later revised P1003.1 @code{ustar} format by
6381 assigning previously unused header fields, in such a way that the upper
6382 limit for file name length was raised to 256 characters. However, the
6383 actual POSIX limit oscillates between 100 and 256, depending on the
6384 precise location of slashes in full file name (this is rather ugly).
6385 Since GNU @code{tar} use the same fields for quite other purposes,
6386 it became incompatible with the latest POSIX standards.
6388 For longer or non-fitting file names, we plan to use yet another set
6389 of GNU extensions, but this time, complying with the provisions POSIX
6390 offers for extending the format, rather than conflicting with it.
6391 Whenever an archive uses old GNU @code{tar} extension format or POSIX
6392 extensions, would it be for very long file names or other specialities,
6393 this archive becomes non-portable to other @code{tar} implementations.
6394 In fact, anything can happen. The most forgiving @code{tar}s will
6395 merely unpack the file using a wrong name, and maybe create another
6396 file named something like @file{@@LongName}, with the true file name
6397 in it. @code{tar}s not protecting themselves may segment violate!
6399 Compatibility concerns make all this thing more difficult, as we
6400 will have to support @emph{all} these things together, for a while.
6401 GNU @code{tar} should be able to produce and read true POSIX format
6402 files, while being able to detect old GNU @code{tar} formats, besides
6403 old V7 format, and process them conveniently. It would take years
6404 before this whole area stabilizes@dots{}
6406 There are plans to raise this 100 limit to 256, and yet produce POSIX
6407 conforming archives. Past 256, I do not know yet if GNU @code{tar}
6408 will go non-POSIX again, or merely refuse to archive the file.
6410 There are plans so GNU @code{tar} support more fully the latest POSIX
6411 format, while being able to read old V7 format, GNU (semi-POSIX plus
6412 extension), as well as full POSIX. One may ask if there is part of
6413 the POSIX format that we still cannot support. This simple question
6414 has a complex answer. Maybe that, on intimate look, some strong
6415 limitations will pop up, but until now, nothing sounds too difficult
6416 (but see below). I only have these few pages of POSIX telling about
6417 `Extended tar Format' (P1003.1-1990 -- section 10.1.1), and there are
6418 references to other parts of the standard I do not have, which should
6419 normally enforce limitations on stored file names (I suspect things
6420 like fixing what @kbd{/} and @kbd{@key{NUL}} means). There are also
6421 some points which the standard does not make clear, Existing practice
6422 will then drive what I should do.
6424 POSIX mandates that, when a file name cannot fit within 100 to
6425 256 characters (the variance comes from the fact a @kbd{/} is
6426 ideally needed as the 156'th character), or a link name cannot
6427 fit within 100 characters, a warning should be issued and the file
6428 @emph{not} be stored. Unless some @value{op-posix} option is given
6429 (or @code{POSIXLY_CORRECT} is set), I suspect that GNU @code{tar}
6430 should disobey this specification, and automatically switch to using
6431 GNU extensions to overcome file name or link name length limitations.
6433 There is a problem, however, which I did not intimately studied yet.
6434 Given a truly POSIX archive with names having more than 100 characters,
6435 I guess that GNU @code{tar} up to 1.11.8 will process it as if it were an
6436 old V7 archive, and be fooled by some fields which are coded differently.
6437 So, the question is to decide if the next generation of GNU @code{tar}
6438 should produce POSIX format by default, whenever possible, producing
6439 archives older versions of GNU @code{tar} might not be able to read
6440 correctly. I fear that we will have to suffer such a choice one of these
6441 days, if we want GNU @code{tar} to go closer to POSIX. We can rush it.
6442 Another possibility is to produce the current GNU @code{tar} format
6443 by default for a few years, but have GNU @code{tar} versions from some
6444 1.@var{POSIX} and up able to recognize all three formats, and let older
6445 GNU @code{tar} fade out slowly. Then, we could switch to producing POSIX
6446 format by default, with not much harm to those still having (very old at
6447 that time) GNU @code{tar} versions prior to 1.@var{POSIX}.
6449 POSIX format cannot represent very long names, volume headers,
6450 splitting of files in multi-volumes, sparse files, and incremental
6451 dumps; these would be all disallowed if @value{op-posix} or
6452 @code{POSIXLY_CORRECT}. Otherwise, if @code{tar} is given long
6453 names, or @samp{-[VMSgG]}, then it should automatically go non-POSIX.
6454 I think this is easily granted without much discussion.
6456 Another point is that only @code{mtime} is stored in POSIX
6457 archives, while GNU @code{tar} currently also store @code{atime}
6458 and @code{ctime}. If we want GNU @code{tar} to go closer to POSIX,
6459 my choice would be to drop @code{atime} and @code{ctime} support on
6460 average. On the other hand, I perceive that full dumps or incremental
6461 dumps need @code{atime} and @code{ctime} support, so for those special
6462 applications, POSIX has to be avoided altogether.
6464 A few users requested that @value{op-sparse} be always active by
6465 default, I think that before replying to them, we have to decide
6466 if we want GNU @code{tar} to go closer to POSIX on average, while
6467 producing files. My choice would be to go closer to POSIX in the
6468 long run. Besides possible double reading, I do not see any point
6469 of not trying to save files as sparse when creating archives which
6470 are neither POSIX nor old-V7, so the actual @value{op-sparse} would
6471 become selected by default when producing such archives, whatever
6472 the reason is. So, @value{op-sparse} alone might be redefined to force
6473 GNU-format archives, and recover its previous meaning from this fact.
6475 GNU-format as it exists now can easily fool other POSIX @code{tar},
6476 as it uses fields which POSIX considers to be part of the file name
6477 prefix. I wonder if it would not be a good idea, in the long run,
6478 to try changing GNU-format so any added field (like @code{ctime},
6479 @code{atime}, file offset in subsequent volumes, or sparse file
6480 descriptions) be wholly and always pushed into an extension block,
6481 instead of using space in the POSIX header block. I could manage
6482 to do that portably between future GNU @code{tar}s. So other POSIX
6483 @code{tar}s might be at least able to provide kind of correct listings
6484 for the archives produced by GNU @code{tar}, if not able to process
6487 Using these projected extensions might induce older @code{tar}s to fail.
6488 We would use the same approach as for POSIX. I'll put out a @code{tar}
6489 capable of reading POSIXier, yet extended archives, but will not produce
6490 this format by default, in GNU mode. In a few years, when newer GNU
6491 @code{tar}s will have flooded out @code{tar} 1.11.X and previous, we
6492 could switch to producing POSIXier extended archives, with no real harm
6493 to users, as almost all existing GNU @code{tar}s will be ready to read
6494 POSIXier format. In fact, I'll do both changes at the same time, in a
6495 few years, and just prepare @code{tar} for both changes, without effecting
6496 them, from 1.@var{POSIX}. (Both changes: 1---using POSIX convention for
6497 getting over 100 characters; 2---avoiding mangling POSIX headers for GNU
6498 extensions, using only POSIX mandated extension techniques).
6500 So, a future @code{tar} will have a @value{op-posix}
6501 flag forcing the usage of truly POSIX headers, and so, producing
6502 archives previous GNU @code{tar} will not be able to read.
6503 So, @emph{once} pretest will announce that feature, it would be
6504 particularly useful that users test how exchangeable will be archives
6505 between GNU @code{tar} with @value{op-posix} and other POSIX @code{tar}.
6507 In a few years, when GNU @code{tar} will produce POSIX headers by
6508 default, @value{op-posix} will have a strong meaning and will disallow
6509 GNU extensions. But in the meantime, for a long while, @value{op-posix}
6510 in GNU tar will not disallow GNU extensions like @value{op-label},
6511 @value{op-multi-volume}, @value{op-sparse}, or very long file or link names.
6512 However, @value{op-posix} with GNU extensions will use POSIX
6513 headers with reserved-for-users extensions to headers, and I will be
6514 curious to know how well or bad POSIX @code{tar}s will react to these.
6516 GNU @code{tar} prior to 1.@var{POSIX}, and after 1.@var{POSIX} without
6517 @value{op-posix}, generates and checks @samp{ustar@w{ }@w{ }}, with two
6518 suffixed spaces. This is sufficient for older GNU @code{tar} not to
6519 recognize POSIX archives, and consequently, wrongly decide those archives
6520 are in old V7 format. It is a useful bug for me, because GNU @code{tar}
6521 has other POSIX incompatibilities, and I need to segregate GNU @code{tar}
6522 semi-POSIX archives from truly POSIX archives, for GNU @code{tar} should
6523 be somewhat compatible with itself, while migrating closer to latest
6524 POSIX standards. So, I'll be very careful about how and when I will do
6527 @node Checksumming, , posix, Portability
6528 @subsection Checksumming Problems
6530 SunOS and HP-UX @code{tar} fail to accept archives created using GNU
6531 @code{tar} and containing non-ASCII file names, that is, file names
6532 having characters with the eight bit set, because they use signed
6533 checksums, while GNU @code{tar} uses unsigned checksums while creating
6534 archives, as per POSIX standards. On reading, GNU @code{tar} computes
6535 both checksums and accept any. It is somewhat worrying that a lot of
6536 people may go around doing backup of their files using faulty (or at
6537 least non-standard) software, not learning about it until it's time
6538 to restore their missing files with an incompatible file extractor,
6541 GNU @code{tar} compute checksums both ways, and accept any on read,
6542 so GNU tar can read Sun tapes even with their wrong checksums.
6543 GNU @code{tar} produces the standard checksum, however, raising
6544 incompatibilities with Sun. That is to say, GNU @code{tar} has not
6545 been modified to @emph{produce} incorrect archives to be read by buggy
6546 @code{tar}'s. I've been told that more recent Sun @code{tar} now
6547 read standard archives, so maybe Sun did a similar patch, after all?
6549 The story seems to be that when Sun first imported @code{tar}
6550 sources on their system, they recompiled it without realizing that
6551 the checksums were computed differently, because of a change in
6552 the default signing of @code{char}'s in their compiler. So they
6553 started computing checksums wrongly. When they later realized their
6554 mistake, they merely decided to stay compatible with it, and with
6555 themselves afterwards. Presumably, but I do not really know, HP-UX
6556 has chosen that their @code{tar} archives to be compatible with Sun's.
6557 The current standards do not favor Sun @code{tar} format. In any
6558 case, it now falls on the shoulders of SunOS and HP-UX users to get
6559 a @code{tar} able to read the good archives they receive.
6561 @node Compression, Attributes, Portability, Formats
6562 @section Using Less Space through Compression
6565 * gzip:: Creating and Reading Compressed Archives
6566 * sparse:: Archiving Sparse Files
6569 @node gzip, sparse, Compression, Compression
6570 @subsection Creating and Reading Compressed Archives
6571 @cindex Compressed archives
6572 @cindex Storing archives in compressed format
6579 Filter the archive through @code{gzip}.
6582 @FIXME{ach; these two bits orig from "compare" (?). where to put?} Some
6583 format parameters must be taken into consideration when modifying an
6584 archive.@FIXME{???} Compressed archives cannot be modified.
6586 You can use @samp{--gzip} and @samp{--gunzip} on physical devices
6587 (tape drives, etc.) and remote files as well as on normal files; data
6588 to or from such devices or remote files is reblocked by another copy
6589 of the @code{tar} program to enforce the specified (or default) record
6590 size. The default compression parameters are used; if you need to
6591 override them, avoid the @value{op-gzip} option and run @code{gzip}
6592 explicitly. (Or set the @samp{GZIP} environment variable.)
6594 The @value{op-gzip} option does not work with the @value{op-multi-volume}
6595 option, or with the @value{op-update}, @value{op-append},
6596 @value{op-concatenate}, or @value{op-delete} operations.
6598 It is not exact to say that GNU @code{tar} is to work in concert
6599 with @code{gzip} in a way similar to @code{zip}, say. Surely, it is
6600 possible that @code{tar} and @code{gzip} be done with a single call,
6604 $ @kbd{tar cfz archive.tar.gz subdir}
6608 to save all of @samp{subdir} into a @code{gzip}'ed archive. Later you
6612 $ @kbd{tar xfz archive.tar.gz}
6616 to explode and unpack.
6618 The difference is that the whole archive is compressed. With
6619 @code{zip}, archive members are archived individually. @code{tar}'s
6620 method yields better compression. On the other hand, one can view the
6621 contents of a @code{zip} archive without having to decompress it. As
6622 for the @code{tar} and @code{gzip} tandem, you need to decompress the
6623 archive to see its contents. However, this may be done without needing
6624 disk space, by using pipes internally:
6627 $ @kbd{tar tfz archive.tar.gz}
6630 @cindex corrupted archives
6631 About corrupted compressed archives: @code{gzip}'ed files have no
6632 redundancy, for maximum compression. The adaptive nature of the
6633 compression scheme means that the compression tables are implicitly
6634 spread all over the archive. If you lose a few blocks, the dynamic
6635 construction of the compression tables becomes unsynchronized, and there
6636 is little chance that you could recover later in the archive.
6638 There are pending suggestions for having a per-volume or per-file
6639 compression in GNU @code{tar}. This would allow for viewing the
6640 contents without decompression, and for resynchronizing decompression at
6641 every volume or file, in case of corrupted archives. Doing so, we might
6642 lose some compressibility. But this would have make recovering easier.
6643 So, there are pros and cons. We'll see!
6648 Filter the archive through @code{bzip2}. Otherwise like @value{op-gzip}.
6653 Filter the archive through @code{compress}. Otherwise like @value{op-gzip}.
6655 @item --use-compress-program=@var{prog}
6656 Filter through @var{prog} (must accept @samp{-d}).
6659 @value{op-compress} stores an archive in compressed format. This
6660 option is useful in saving time over networks and space in pipes, and
6661 when storage space is at a premium. @value{op-compress} causes
6662 @code{tar} to compress when writing the archive, or to uncompress when
6663 reading the archive.
6665 To perform compression and uncompression on the archive, @code{tar}
6666 runs the @code{compress} utility. @code{tar} uses the default
6667 compression parameters; if you need to override them, avoid the
6668 @value{op-compress} option and run the @code{compress} utility
6669 explicitly. It is useful to be able to call the @code{compress}
6670 utility from within @code{tar} because the @code{compress} utility by
6671 itself cannot access remote tape drives.
6673 The @value{op-compress} option will not work in conjunction with the
6674 @value{op-multi-volume} option or the @value{op-append}, @value{op-update},
6675 @value{op-append} and @value{op-delete} operations. @xref{Operations}, for
6676 more information on these operations.
6678 If there is no compress utility available, @code{tar} will report an error.
6679 @strong{Please note} that the @code{compress} program may be covered by
6680 a patent, and therefore we recommend you stop using it.
6682 @value{op-bzip2} acts like @value{op-compress}, except that it uses
6683 the @code{bzip2} utility.
6690 When this option is specified, @code{tar} will compress (when writing
6691 an archive), or uncompress (when reading an archive). Used in
6692 conjunction with the @value{op-create}, @value{op-extract}, @value{op-list} and
6693 @value{op-compare} operations.
6696 You can have archives be compressed by using the @value{op-gzip} option.
6697 This will arrange for @code{tar} to use the @code{gzip} program to be
6698 used to compress or uncompress the archive wren writing or reading it.
6700 To use the older, obsolete, @code{compress} program, use the
6701 @value{op-compress} option. The GNU Project recommends you not use
6702 @code{compress}, because there is a patent covering the algorithm it
6703 uses. You could be sued for patent infringement merely by running
6706 I have one question, or maybe it's a suggestion if there isn't a way
6707 to do it now. I would like to use @value{op-gzip}, but I'd also like the
6708 output to be fed through a program like GNU @code{ecc} (actually, right
6709 now that's @samp{exactly} what I'd like to use :-)), basically adding
6710 ECC protection on top of compression. It seems as if this should be
6711 quite easy to do, but I can't work out exactly how to go about it.
6712 Of course, I can pipe the standard output of @code{tar} through
6713 @code{ecc}, but then I lose (though I haven't started using it yet,
6714 I confess) the ability to have @code{tar} use @code{rmt} for it's I/O
6717 I think the most straightforward thing would be to let me specify a
6718 general set of filters outboard of compression (preferably ordered,
6719 so the order can be automatically reversed on input operations, and
6720 with the options they require specifiable), but beggars shouldn't be
6721 choosers and anything you decide on would be fine with me.
6723 By the way, I like @code{ecc} but if (as the comments say) it can't
6724 deal with loss of block sync, I'm tempted to throw some time at adding
6725 that capability. Supposing I were to actually do such a thing and
6726 get it (apparently) working, do you accept contributed changes to
6727 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
6729 Isn't that exactly the role of the @value{op-use-compress-prog} option?
6730 I never tried it myself, but I suspect you may want to write a
6731 @var{prog} script or program able to filter stdin to stdout to
6732 way you want. It should recognize the @samp{-d} option, for when
6733 extraction is needed rather than creation.
6735 It has been reported that if one writes compressed data (through the
6736 @value{op-gzip} or @value{op-compress} options) to a DLT and tries to use
6737 the DLT compression mode, the data will actually get bigger and one will
6738 end up with less space on the tape.
6740 @node sparse, , gzip, Compression
6741 @subsection Archiving Sparse Files
6742 @cindex Sparse Files
6748 Handle sparse files efficiently.
6751 This option causes all files to be put in the archive to be tested for
6752 sparseness, and handled specially if they are. The @value{op-sparse}
6753 option is useful when many @code{dbm} files, for example, are being
6754 backed up. Using this option dramatically decreases the amount of
6755 space needed to store such a file.
6757 In later versions, this option may be removed, and the testing and
6758 treatment of sparse files may be done automatically with any special
6759 GNU options. For now, it is an option needing to be specified on
6760 the command line with the creation or updating of an archive.
6762 Files in the filesystem occasionally have ``holes.'' A hole in a file
6763 is a section of the file's contents which was never written. The
6764 contents of a hole read as all zeros. On many operating systems,
6765 actual disk storage is not allocated for holes, but they are counted
6766 in the length of the file. If you archive such a file, @code{tar}
6767 could create an archive longer than the original. To have @code{tar}
6768 attempt to recognize the holes in a file, use @value{op-sparse}. When
6769 you use the @value{op-sparse} option, then, for any file using less
6770 disk space than would be expected from its length, @code{tar} searches
6771 the file for consecutive stretches of zeros. It then records in the
6772 archive for the file where the consecutive stretches of zeros are, and
6773 only archives the ``real contents'' of the file. On extraction (using
6774 @value{op-sparse} is not needed on extraction) any such files have
6775 hols created wherever the continuous stretches of zeros were found.
6776 Thus, if you use @value{op-sparse}, @code{tar} archives won't take
6777 more space than the original.
6779 A file is sparse if it contains blocks of zeros whose existence is
6780 recorded, but that have no space allocated on disk. When you specify
6781 the @value{op-sparse} option in conjunction with the @value{op-create}
6782 operation, @code{tar} tests all files for sparseness while archiving.
6783 If @code{tar} finds a file to be sparse, it uses a sparse representation of
6784 the file in the archive. @value{xref-create}, for more information
6785 about creating archives.
6787 @value{op-sparse} is useful when archiving files, such as dbm files,
6788 likely to contain many nulls. This option dramatically
6789 decreases the amount of space needed to store such an archive.
6792 @strong{Please Note:} Always use @value{op-sparse} when performing file
6793 system backups, to avoid archiving the expanded forms of files stored
6794 sparsely in the system.
6796 Even if your system has no sparse files currently, some may be
6797 created in the future. If you use @value{op-sparse} while making file
6798 system backups as a matter of course, you can be assured the archive
6799 will never take more space on the media than the files take on disk
6800 (otherwise, archiving a disk filled with sparse files might take
6801 hundreds of tapes). @FIXME-xref{incremental when node name is set.}
6804 @code{tar} ignores the @value{op-sparse} option when reading an archive.
6809 Files stored sparsely in the file system are represented sparsely in
6810 the archive. Use in conjunction with write operations.
6813 However, users should be well aware that at archive creation time, GNU
6814 @code{tar} still has to read whole disk file to locate the @dfn{holes}, and
6815 so, even if sparse files use little space on disk and in the archive, they
6816 may sometimes require inordinate amount of time for reading and examining
6817 all-zero blocks of a file. Although it works, it's painfully slow for a
6818 large (sparse) file, even though the resulting tar archive may be small.
6819 (One user reports that dumping a @file{core} file of over 400 megabytes,
6820 but with only about 3 megabytes of actual data, took about 9 minutes on
6821 a Sun Sparcstation ELC, with full CPU utilization.)
6823 This reading is required in all cases and is not related to the fact
6824 the @value{op-sparse} option is used or not, so by merely @emph{not}
6825 using the option, you are not saving time@footnote{Well! We should say
6826 the whole truth, here. When @value{op-sparse} is selected while creating
6827 an archive, the current @code{tar} algorithm requires sparse files to be
6828 read twice, not once. We hope to develop a new archive format for saving
6829 sparse files in which one pass will be sufficient.}.
6831 Programs like @code{dump} do not have to read the entire file; by examining
6832 the file system directly, they can determine in advance exactly where the
6833 holes are and thus avoid reading through them. The only data it need read
6834 are the actual allocated data blocks. GNU @code{tar} uses a more portable
6835 and straightforward archiving approach, it would be fairly difficult that
6836 it does otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals},
6840 What I did say is that you cannot tell the difference between a hole and an
6841 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
6842 best tells you how many holes there are; it doesn't tell you @emph{where}.
6843 Just as programs may, conceivably, care what @code{st_blocks} is (care
6844 to name one that does?), they may also care where the holes are (I have
6845 no examples of this one either, but it's equally imaginable).
6847 I conclude from this that good archivers are not portable. One can
6848 arguably conclude that if you want a portable program, you can in good
6849 conscience restore files with as many holes as possible, since you can't
6853 @node Attributes, Standard, Compression, Formats
6854 @section Handling File Attributes
6857 When @code{tar} reads files, this causes them to have the access times
6858 updated. To have @code{tar} attempt to set the access times back to
6859 what they were before they were read, use the @value{op-atime-preserve}
6860 option. This doesn't work for files that you don't own, unless
6861 you're root, and it doesn't interact with incremental dumps nicely
6862 (@pxref{Backups}), but it is good enough for some purposes.
6864 Handling of file attributes
6867 @item --atime-preserve
6868 Do not change access times on dumped files.
6872 Do not extract file modified time.
6874 When this option is used, @code{tar} leaves the modification times
6875 of the files it extracts as the time when the files were extracted,
6876 instead of setting it to the time recorded in the archive.
6878 This option is meaningless with @value{op-list}.
6881 Create extracted files with the same ownership they have in the
6884 This is the default behavior for the superuser,
6885 so this option is meaningful only for non-root users, when @code{tar}
6886 is executed on those systems able to give files away. This is
6887 considered as a security flaw by many people, at least because it
6888 makes quite difficult to correctly account users for the disk space
6889 they occupy. Also, the @code{suid} or @code{sgid} attributes of
6890 files are easily and silently lost when files are given away.
6892 When writing an archive, @code{tar} writes the user id and user name
6893 separately. If it can't find a user name (because the user id is not
6894 in @file{/etc/passwd}), then it does not write one. When restoring,
6895 and doing a @code{chmod} like when you use @value{op-same-permissions},
6896 @FIXME{same-owner?}it tries to look the name (if one was written)
6897 up in @file{/etc/passwd}. If it fails, then it uses the user id
6898 stored in the archive instead.
6900 @item --no-same-owner
6901 Do not attempt to restore ownership when extracting. This is the
6902 default behavior for ordinary users, so this option has an effect
6903 only for the superuser.
6905 @item --numeric-owner
6906 The @value{op-numeric-owner} option allows (ANSI) archives to be written
6907 without user/group name information or such information to be ignored
6908 when extracting. It effectively disables the generation and/or use
6909 of user/group name information. This option forces extraction using
6910 the numeric ids from the archive, ignoring the names.
6912 This is useful in certain circumstances, when restoring a backup from
6913 an emergency floppy with different passwd/group files for example.
6914 It is otherwise impossible to extract files with the right ownerships
6915 if the password file in use during the extraction does not match the
6916 one belonging to the filesystem(s) being extracted. This occurs,
6917 for example, if you are restoring your files after a major crash and
6918 had booted from an emergency floppy with no password file or put your
6919 disk into another machine to do the restore.
6921 The numeric ids are @emph{always} saved into @code{tar} archives.
6922 The identifying names are added at create time when provided by the
6923 system, unless @value{op-old-archive} is used. Numeric ids could be
6924 used when moving archives between a collection of machines using
6925 a centralized management for attribution of numeric ids to users
6926 and groups. This is often made through using the NIS capabilities.
6928 When making a @code{tar} file for distribution to other sites, it
6929 is sometimes cleaner to use a single owner for all files in the
6930 distribution, and nicer to specify the write permission bits of the
6931 files as stored in the archive independently of their actual value on
6932 the file system. The way to prepare a clean distribution is usually
6933 to have some Makefile rule creating a directory, copying all needed
6934 files in that directory, then setting ownership and permissions as
6935 wanted (there are a lot of possible schemes), and only then making a
6936 @code{tar} archive out of this directory, before cleaning everything
6937 out. Of course, we could add a lot of options to GNU @code{tar} for
6938 fine tuning permissions and ownership. This is not the good way,
6939 I think. GNU @code{tar} is already crowded with options and moreover,
6940 the approach just explained gives you a great deal of control already.
6943 @itemx --same-permissions
6944 @itemx --preserve-permissions
6945 Extract all protection information.
6947 This option causes @code{tar} to set the modes (access permissions) of
6948 extracted files exactly as recorded in the archive. If this option
6949 is not used, the current @code{umask} setting limits the permissions
6952 This option is meaningless with @value{op-list}.
6955 Same as both @value{op-same-permissions} and @value{op-same-order}.
6957 The @value{op-preserve} option has no equivalent short option name.
6958 It is equivalent to @value{op-same-permissions} plus @value{op-same-order}.
6960 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)}
6964 @node Standard, Extensions, Attributes, Formats
6965 @section The Standard Format
6968 While an archive may contain many files, the archive itself is a
6969 single ordinary file. Like any other file, an archive file can be
6970 written to a storage device such as a tape or disk, sent through a
6971 pipe or over a network, saved on the active file system, or even
6972 stored in another archive. An archive file is not easy to read or
6973 manipulate without using the @code{tar} utility or Tar mode in GNU
6976 Physically, an archive consists of a series of file entries terminated
6977 by an end-of-archive entry, which consists of 512 zero bytes. A file
6978 entry usually describes one of the files in the archive (an
6979 @dfn{archive member}), and consists of a file header and the contents
6980 of the file. File headers contain file names and statistics, checksum
6981 information which @code{tar} uses to detect file corruption, and
6982 information about file types.
6984 Archives are permitted to have more than one member with the same
6985 member name. One way this situation can occur is if more than one
6986 version of a file has been stored in the archive. For information
6987 about adding new versions of a file to an archive, see @ref{update}.
6988 @FIXME-xref{To learn more about having more than one archive member with the
6989 same name, see -backup node, when it's written.}
6991 In addition to entries describing archive members, an archive may
6992 contain entries which @code{tar} itself uses to store information.
6993 @value{xref-label}, for an example of such an archive entry.
6995 A @code{tar} archive file contains a series of blocks. Each block
6996 contains @code{BLOCKSIZE} bytes. Although this format may be thought
6997 of as being on magnetic tape, other media are often used.
6999 Each file archived is represented by a header block which describes
7000 the file, followed by zero or more blocks which give the contents
7001 of the file. At the end of the archive file there may be a block
7002 filled with binary zeros as an end-of-file marker. A reasonable system
7003 should write a block of zeros at the end, but must not assume that
7004 such a block exists when reading an archive.
7006 The blocks may be @dfn{blocked} for physical I/O operations.
7007 Each record of @var{n} blocks (where @var{n} is set by the
7008 @value{op-blocking-factor} option to @code{tar}) is written with a single
7009 @w{@samp{write ()}} operation. On magnetic tapes, the result of
7010 such a write is a single record. When writing an archive,
7011 the last record of blocks should be written at the full size, with
7012 blocks after the zero block containing all zeros. When reading
7013 an archive, a reasonable system should properly handle an archive
7014 whose last record is shorter than the rest, or which contains garbage
7015 records after a zero block.
7017 The header block is defined in C as follows. In the GNU @code{tar}
7018 distribution, this is part of file @file{src/tar.h}:
7021 @include header.texi
7024 All characters in header blocks are represented by using 8-bit
7025 characters in the local variant of ASCII. Each field within the
7026 structure is contiguous; that is, there is no padding used within
7027 the structure. Each character on the archive medium is stored
7030 Bytes representing the contents of files (after the header block
7031 of each file) are not translated in any way and are not constrained
7032 to represent characters in any character set. The @code{tar} format
7033 does not distinguish text files from binary files, and no translation
7034 of file contents is performed.
7036 The @code{name}, @code{linkname}, @code{magic}, @code{uname}, and
7037 @code{gname} are null-terminated character strings. All other fileds
7038 are zero-filled octal numbers in ASCII. Each numeric field of width
7039 @var{w} contains @var{w} minus 2 digits, a space, and a null, except
7040 @code{size}, and @code{mtime}, which do not contain the trailing null.
7042 The @code{name} field is the file name of the file, with directory names
7043 (if any) preceding the file name, separated by slashes.
7045 @FIXME{how big a name before field overflows?}
7047 The @code{mode} field provides nine bits specifying file permissions
7048 and three bits to specify the Set UID, Set GID, and Save Text
7049 (@dfn{sticky}) modes. Values for these bits are defined above.
7050 When special permissions are required to create a file with a given
7051 mode, and the user restoring files from the archive does not hold such
7052 permissions, the mode bit(s) specifying those special permissions
7053 are ignored. Modes which are not supported by the operating system
7054 restoring files from the archive will be ignored. Unsupported modes
7055 should be faked up when creating or updating an archive; e.g.@: the
7056 group permission could be copied from the @emph{other} permission.
7058 The @code{uid} and @code{gid} fields are the numeric user and group
7059 ID of the file owners, respectively. If the operating system does
7060 not support numeric user or group IDs, these fields should be ignored.
7062 The @code{size} field is the size of the file in bytes; linked files
7063 are archived with this field specified as zero. @FIXME-xref{Modifiers, in
7064 particular the @value{op-incremental} option.}
7066 The @code{mtime} field is the modification time of the file at the time
7067 it was archived. It is the ASCII representation of the octal value of
7068 the last time the file was modified, represented as an integer number of
7069 seconds since January 1, 1970, 00:00 Coordinated Universal Time.
7071 The @code{chksum} field is the ASCII representation of the octal value
7072 of the simple sum of all bytes in the header block. Each 8-bit
7073 byte in the header is added to an unsigned integer, initialized to
7074 zero, the precision of which shall be no less than seventeen bits.
7075 When calculating the checksum, the @code{chksum} field is treated as
7076 if it were all blanks.
7078 The @code{typeflag} field specifies the type of file archived. If a
7079 particular implementation does not recognize or permit the specified
7080 type, the file will be extracted as if it were a regular file. As this
7081 action occurs, @code{tar} issues a warning to the standard error.
7083 The @code{atime} and @code{ctime} fields are used in making incremental
7084 backups; they store, respectively, the particular file's access time
7085 and last inode-change time.
7087 The @code{offset} is used by the @value{op-multi-volume} option, when
7088 making a multi-volume archive. The offset is number of bytes into
7089 the file that we need to restart at to continue the file on the next
7090 tape, i.e., where we store the location that a continued file is
7093 The following fields were added to deal with sparse files. A file
7094 is @dfn{sparse} if it takes in unallocated blocks which end up being
7095 represented as zeros, i.e., no useful data. A test to see if a file
7096 is sparse is to look at the number blocks allocated for it versus the
7097 number of characters in the file; if there are fewer blocks allocated
7098 for the file than would normally be allocated for a file of that
7099 size, then the file is sparse. This is the method @code{tar} uses to
7100 detect a sparse file, and once such a file is detected, it is treated
7101 differently from non-sparse files.
7103 Sparse files are often @code{dbm} files, or other database-type files
7104 which have data at some points and emptiness in the greater part of
7105 the file. Such files can appear to be very large when an @samp{ls
7106 -l} is done on them, when in truth, there may be a very small amount
7107 of important data contained in the file. It is thus undesirable
7108 to have @code{tar} think that it must back up this entire file, as
7109 great quantities of room are wasted on empty blocks, which can lead
7110 to running out of room on a tape far earlier than is necessary.
7111 Thus, sparse files are dealt with so that these empty blocks are
7112 not written to the tape. Instead, what is written to the tape is a
7113 description, of sorts, of the sparse file: where the holes are, how
7114 big the holes are, and how much data is found at the end of the hole.
7115 This way, the file takes up potentially far less room on the tape,
7116 and when the file is extracted later on, it will look exactly the way
7117 it looked beforehand. The following is a description of the fields
7118 used to handle a sparse file:
7120 The @code{sp} is an array of @code{struct sparse}. Each @code{struct
7121 sparse} contains two 12-character strings which represent an offset
7122 into the file and a number of bytes to be written at that offset.
7123 The offset is absolute, and not relative to the offset in preceding
7126 The header can hold four of these @code{struct sparse} at the moment;
7127 if more are needed, they are not stored in the header.
7129 The @code{isextended} flag is set when an @code{extended_header}
7130 is needed to deal with a file. Note that this means that this flag
7131 can only be set when dealing with a sparse file, and it is only set
7132 in the event that the description of the file will not fit in the
7133 allotted room for sparse structures in the header. In other words,
7134 an extended_header is needed.
7136 The @code{extended_header} structure is used for sparse files which
7137 need more sparse structures than can fit in the header. The header can
7138 fit 4 such structures; if more are needed, the flag @code{isextended}
7139 gets set and the next block is an @code{extended_header}.
7141 Each @code{extended_header} structure contains an array of 21
7142 sparse structures, along with a similar @code{isextended} flag
7143 that the header had. There can be an indeterminate number of such
7144 @code{extended_header}s to describe a sparse file.
7148 @item @code{REGTYPE}
7149 @itemx @code{AREGTYPE}
7150 These flags represent a regular file. In order to be compatible
7151 with older versions of @code{tar}, a @code{typeflag} value of
7152 @code{AREGTYPE} should be silently recognized as a regular file.
7153 New archives should be created using @code{REGTYPE}. Also, for
7154 backward compatibility, @code{tar} treats a regular file whose name
7155 ends with a slash as a directory.
7157 @item @code{LNKTYPE}
7158 This flag represents a file linked to another file, of any type,
7159 previously archived. Such files are identified in Unix by each
7160 file having the same device and inode number. The linked-to name is
7161 specified in the @code{linkname} field with a trailing null.
7163 @item @code{SYMTYPE}
7164 This represents a symbolic link to another file. The linked-to name
7165 is specified in the @code{linkname} field with a trailing null.
7167 @item @code{CHRTYPE}
7168 @itemx @code{BLKTYPE}
7169 These represent character special files and block special files
7170 respectively. In this case the @code{devmajor} and @code{devminor}
7171 fields will contain the major and minor device numbers respectively.
7172 Operating systems may map the device specifications to their own
7173 local specification, or may ignore the entry.
7175 @item @code{DIRTYPE}
7176 This flag specifies a directory or sub-directory. The directory
7177 name in the @code{name} field should end with a slash. On systems where
7178 disk allocation is performed on a directory basis, the @code{size} field
7179 will contain the maximum number of bytes (which may be rounded to
7180 the nearest disk block allocation unit) which the directory may
7181 hold. A @code{size} field of zero indicates no such limiting. Systems
7182 which do not support limiting in this manner should ignore the
7185 @item @code{FIFOTYPE}
7186 This specifies a FIFO special file. Note that the archiving of a
7187 FIFO file archives the existence of this file and not its contents.
7189 @item @code{CONTTYPE}
7190 This specifies a contiguous file, which is the same as a normal
7191 file except that, in operating systems which support it, all its
7192 space is allocated contiguously on the disk. Operating systems
7193 which do not allow contiguous allocation should silently treat this
7194 type as a normal file.
7196 @item @code{A} @dots{} @code{Z}
7197 These are reserved for custom implementations. Some of these are
7198 used in the GNU modified format, as described below.
7202 Other values are reserved for specification in future revisions of
7203 the P1003 standard, and should not be used by any @code{tar} program.
7205 The @code{magic} field indicates that this archive was output in
7206 the P1003 archive format. If this field contains @code{TMAGIC},
7207 the @code{uname} and @code{gname} fields will contain the ASCII
7208 representation of the owner and group of the file respectively.
7209 If found, the user and group IDs are used rather than the values in
7210 the @code{uid} and @code{gid} fields.
7212 For references, see ISO/IEC 9945-1:1990 or IEEE Std 1003.1-1990, pages
7213 169-173 (section 10.1) for @cite{Archive/Interchange File Format}; and
7214 IEEE Std 1003.2-1992, pages 380-388 (section 4.48) and pages 936-940
7215 (section E.4.48) for @cite{pax - Portable archive interchange}.
7217 @node Extensions, cpio, Standard, Formats
7218 @section GNU Extensions to the Archive Format
7221 The GNU format uses additional file types to describe new types of
7222 files in an archive. These are listed below.
7225 @item GNUTYPE_DUMPDIR
7227 This represents a directory and a list of files created by the
7228 @value{op-incremental} option. The @code{size} field gives the total
7229 size of the associated list of files. Each file name is preceded by
7230 either a @samp{Y} (the file should be in this archive) or an @samp{N}.
7231 (The file is a directory, or is not stored in the archive.) Each file
7232 name is terminated by a null. There is an additional null after the
7235 @item GNUTYPE_MULTIVOL
7237 This represents a file continued from another volume of a multi-volume
7238 archive created with the @value{op-multi-volume} option. The original
7239 type of the file is not given here. The @code{size} field gives the
7240 maximum size of this piece of the file (assuming the volume does
7241 not end before the file is written out). The @code{offset} field
7242 gives the offset from the beginning of the file where this part of
7243 the file begins. Thus @code{size} plus @code{offset} should equal
7244 the original size of the file.
7246 @item GNUTYPE_SPARSE
7248 This flag indicates that we are dealing with a sparse file. Note
7249 that archiving a sparse file requires special operations to find
7250 holes in the file, which mark the positions of these holes, along
7251 with the number of bytes of data to be found after the hole.
7253 @item GNUTYPE_VOLHDR
7255 This file type is used to mark the volume header that was given with
7256 the @value{op-label} option when the archive was created. The @code{name}
7257 field contains the @code{name} given after the @value{op-label} option.
7258 The @code{size} field is zero. Only the first file in each volume
7259 of an archive should have this type.
7263 You may have trouble reading a GNU format archive on a non-GNU
7264 system if the options @value{op-incremental}, @value{op-multi-volume},
7265 @value{op-sparse}, or @value{op-label} were used when writing the archive.
7266 In general, if @code{tar} does not use the GNU-added fields of the
7267 header, other versions of @code{tar} should be able to read the
7268 archive. Otherwise, the @code{tar} program will give an error, the
7269 most likely one being a checksum error.
7271 @node cpio, , Extensions, Formats
7272 @section Comparison of @code{tar} and @code{cpio}
7275 @FIXME{Reorganize the following material}
7277 The @code{cpio} archive formats, like @code{tar}, do have maximum
7278 pathname lengths. The binary and old ASCII formats have a max path
7279 length of 256, and the new ASCII and CRC ASCII formats have a max
7280 path length of 1024. GNU @code{cpio} can read and write archives
7281 with arbitrary pathname lengths, but other @code{cpio} implementations
7282 may crash unexplainedly trying to read them.
7284 @code{tar} handles symbolic links in the form in which it comes in BSD;
7285 @code{cpio} doesn't handle symbolic links in the form in which it comes
7286 in System V prior to SVR4, and some vendors may have added symlinks
7287 to their system without enhancing @code{cpio} to know about them.
7288 Others may have enhanced it in a way other than the way I did it
7289 at Sun, and which was adopted by AT&T (and which is, I think, also
7290 present in the @code{cpio} that Berkeley picked up from AT&T and put
7291 into a later BSD release---I think I gave them my changes).
7293 (SVR4 does some funny stuff with @code{tar}; basically, its @code{cpio}
7294 can handle @code{tar} format input, and write it on output, and it
7295 probably handles symbolic links. They may not have bothered doing
7296 anything to enhance @code{tar} as a result.)
7298 @code{cpio} handles special files; traditional @code{tar} doesn't.
7300 @code{tar} comes with V7, System III, System V, and BSD source;
7301 @code{cpio} comes only with System III, System V, and later BSD
7302 (4.3-tahoe and later).
7304 @code{tar}'s way of handling multiple hard links to a file can handle
7305 file systems that support 32-bit inumbers (e.g., the BSD file system);
7306 @code{cpio}s way requires you to play some games (in its "binary"
7307 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
7308 they're 18 bits---it would have to play games with the "file system ID"
7309 field of the header to make sure that the file system ID/i-number pairs
7310 of different files were always different), and I don't know which
7311 @code{cpio}s, if any, play those games. Those that don't might get
7312 confused and think two files are the same file when they're not, and
7313 make hard links between them.
7315 @code{tar}s way of handling multiple hard links to a file places only
7316 one copy of the link on the tape, but the name attached to that copy
7317 is the @emph{only} one you can use to retrieve the file; @code{cpio}s
7318 way puts one copy for every link, but you can retrieve it using any
7322 What type of check sum (if any) is used, and how is this calculated.
7325 See the attached manual pages for @code{tar} and @code{cpio} format.
7326 @code{tar} uses a checksum which is the sum of all the bytes in the
7327 @code{tar} header for a file; @code{cpio} uses no checksum.
7330 If anyone knows why @code{cpio} was made when @code{tar} was present
7334 It wasn't. @code{cpio} first showed up in PWB/UNIX 1.0; no
7335 generally-available version of UNIX had @code{tar} at the time. I don't
7336 know whether any version that was generally available @emph{within AT&T}
7337 had @code{tar}, or, if so, whether the people within AT&T who did
7338 @code{cpio} knew about it.
7340 On restore, if there is a corruption on a tape @code{tar} will stop at
7341 that point, while @code{cpio} will skip over it and try to restore the
7344 The main difference is just in the command syntax and header format.
7346 @code{tar} is a little more tape-oriented in that everything is blocked
7347 to start on a record boundary.
7350 Is there any differences between the ability to recover crashed
7351 archives between the two of them. (Is there any chance of recovering
7352 crashed archives at all.)
7355 Theoretically it should be easier under @code{tar} since the blocking
7356 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
7357 However, modern @code{cpio}'s and variations have an option to just
7358 search for the next file header after an error with a reasonable chance
7359 of resyncing. However, lots of tape driver software won't allow you to
7360 continue past a media error which should be the only reason for getting
7361 out of sync unless a file changed sizes while you were writing the
7365 If anyone knows why @code{cpio} was made when @code{tar} was present
7366 at the unix scene, please tell me about this too.
7369 Probably because it is more media efficient (by not blocking everything
7370 and using only the space needed for the headers where @code{tar}
7371 always uses 512 bytes per file header) and it knows how to archive
7374 You might want to look at the freely available alternatives. The major
7375 ones are @code{afio}, GNU @code{tar}, and @code{pax}, each of which
7376 have their own extensions with some backwards compatibility.
7378 Sparse files were @code{tar}red as sparse files (which you can easily
7379 test, because the resulting archive gets smaller, and GNU @code{cpio}
7380 can no longer read it).
7382 @node Media, Index, Formats, Top
7383 @chapter Tapes and Other Archive Media
7386 A few special cases about tape handling warrant more detailed
7387 description. These special cases are discussed below.
7389 Many complexities surround the use of @code{tar} on tape drives. Since
7390 the creation and manipulation of archives located on magnetic tape was
7391 the original purpose of @code{tar}, it contains many features making
7392 such manipulation easier.
7394 Archives are usually written on dismountable media---tape cartridges,
7395 mag tapes, or floppy disks.
7397 The amount of data a tape or disk holds depends not only on its size,
7398 but also on how it is formatted. A 2400 foot long reel of mag tape
7399 holds 40 megabytes of data when formatted at 1600 bits per inch. The
7400 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
7402 Magnetic media are re-usable---once the archive on a tape is no longer
7403 needed, the archive can be erased and the tape or disk used over.
7404 Media quality does deteriorate with use, however. Most tapes or disks
7405 should be discarded when they begin to produce data errors. EXABYTE
7406 tape cartridges should be discarded when they generate an @dfn{error
7407 count} (number of non-usable bits) of more than 10k.
7409 Magnetic media are written and erased using magnetic fields, and
7410 should be protected from such fields to avoid damage to stored data.
7411 Sticking a floppy disk to a filing cabinet using a magnet is probably
7415 * Device:: Device selection and switching
7416 * Remote Tape Server::
7417 * Common Problems and Solutions::
7418 * Blocking:: Blocking
7419 * Many:: Many archives on one tape
7420 * Using Multiple Tapes:: Using Multiple Tapes
7421 * label:: Including a Label in the Archive
7423 * Write Protection::
7426 @node Device, Remote Tape Server, Media, Media
7427 @section Device Selection and Switching
7431 @item -f [@var{hostname}:]@var{file}
7432 @itemx --file=[@var{hostname}:]@var{file}
7433 Use archive file or device @var{file} on @var{hostname}.
7436 This option is used to specify the file name of the archive @code{tar}
7439 If the file name is @samp{-}, @code{tar} reads the archive from standard
7440 input (when listing or extracting), or writes it to standard output
7441 (when creating). If the @samp{-} file name is given when updating an
7442 archive, @code{tar} will read the original archive from its standard
7443 input, and will write the entire new archive to its standard output.
7445 If the file name contains a @samp{:}, it is interpreted as
7446 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
7447 sign (@kbd{@@}), it is treated as @samp{user@@hostname:file name}. In
7448 either case, @code{tar} will invoke the command @code{rsh} (or
7449 @code{remsh}) to start up an @file{/etc/rmt} on the remote machine. If
7450 you give an alternate login name, it will be given to the @code{rsh}.
7451 Naturally, the remote machine must have an executable @file{/etc/rmt}.
7452 This program is free software from the University of California, and a
7453 copy of the source code can be found with the sources for @code{tar};
7454 it's compiled and installed by default.
7456 If this option is not given, but the environment variable @code{TAPE} is
7457 set, its value is used; otherwise, old versions of @code{tar} used a default
7458 archive name (which was picked when @code{tar} was compiled). The
7459 default is normally set up to be the @dfn{first} tape drive or other
7460 transportable I/O medium on the system.
7462 Starting with version 1.11.5, GNU @code{tar} uses standard input and
7463 standard output as the default device, and I will not try anymore
7464 supporting automatic device detection at installation time. This was
7465 failing really in too many cases, it was hopeless. This is now
7466 completely left to the installer to override standard input and standard
7467 output for default device, if this seems preferable.
7468 Further, I think @emph{most} actual usages of @code{tar} are done with
7469 pipes or disks, not really tapes, cartridges or diskettes.
7471 Some users think that using standard input and output is running
7472 after trouble. This could lead to a nasty surprise on your screen if
7473 you forget to specify an output file name---especially if you are going
7474 through a network or terminal server capable of buffering large amounts
7475 of output. We had so many bug reports in that area of configuring
7476 default tapes automatically, and so many contradicting requests, that
7477 we finally consider the problem to be portably intractable. We could
7478 of course use something like @samp{/dev/tape} as a default, but this
7479 is @emph{also} running after various kind of trouble, going from hung
7480 processes to accidental destruction of real tapes. After having seen
7481 all this mess, using standard input and output as a default really
7482 sounds like the only clean choice left, and a very useful one too.
7484 GNU @code{tar} reads and writes archive in records, I suspect this is the
7485 main reason why block devices are preferred over character devices.
7486 Most probably, block devices are more efficient too. The installer
7487 could also check for @samp{DEFTAPE} in @file{<sys/mtio.h>}.
7491 Archive file is local even if it contains a colon.
7493 @item --rsh-command=@var{command}
7494 Use remote @var{command} instead of @code{rsh}. This option exists
7495 so that people who use something other than the standard @code{rsh}
7496 (e.g., a Kerberized @code{rsh}) can access a remote device.
7498 When this command is not used, the shell command found when
7499 the @code{tar} program was installed is used instead. This is
7500 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
7501 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
7502 The installer may have overridden this by defining the environment
7503 variable @code{RSH} @emph{at installation time}.
7506 Specify drive and density.
7509 @itemx --multi-volume
7510 Create/list/extract multi-volume archive.
7512 This option causes @code{tar} to write a @dfn{multi-volume} archive---one
7513 that may be larger than will fit on the medium used to hold it.
7514 @xref{Multi-Volume Archives}.
7517 @itemx --tape-length=@var{num}
7518 Change tape after writing @var{num} x 1024 bytes.
7520 This option might be useful when your tape drivers do not properly
7521 detect end of physical tapes. By being slightly conservative on the
7522 maximum tape length, you might avoid the problem entirely.
7525 @itemx --info-script=@var{file}
7526 @itemx --new-volume-script=@var{file}
7527 Execute @file{file} at end of each tape. This implies
7528 @value{op-multi-volume}.
7531 @node Remote Tape Server, Common Problems and Solutions, Device, Media
7532 @section The Remote Tape Server
7534 @cindex remote tape drive
7536 In order to access the tape drive on a remote machine, @code{tar}
7537 uses the remote tape server written at the University of California at
7538 Berkeley. The remote tape server must be installed as @file{/etc/rmt}
7539 on any machine whose tape drive you want to use. @code{tar} calls
7540 @file{/etc/rmt} by running an @code{rsh} or @code{remsh} to the remote
7541 machine, optionally using a different login name if one is supplied.
7543 A copy of the source for the remote tape server is provided. It is
7544 Copyright @copyright{} 1983 by the Regents of the University of
7545 California, but can be freely distributed. Instructions for compiling
7546 and installing it are included in the @file{Makefile}.
7548 @cindex absolute file names
7549 Unless you use the @value{op-absolute-names} option, GNU @code{tar} will
7550 not allow you to create an archive that contains absolute file names
7551 (a file name beginning with @samp{/}.) If you try, @code{tar} will
7552 automatically remove the leading @samp{/} from the file names it
7553 stores in the archive. It will also type a warning message telling
7554 you what it is doing.
7556 When reading an archive that was created with a different @code{tar}
7557 program, GNU @code{tar} automatically extracts entries in the archive
7558 which have absolute file names as if the file names were not absolute.
7559 This is an important feature. A visitor here once gave a
7560 @code{tar} tape to an operator to restore; the operator used Sun @code{tar}
7561 instead of GNU @code{tar}, and the result was that it replaced large
7562 portions of our @file{/bin} and friends with versions from the tape;
7563 needless to say, we were unhappy about having to recover the file system
7566 For example, if the archive contained a file @file{/usr/bin/computoy},
7567 GNU @code{tar} would extract the file to @file{usr/bin/computoy},
7568 relative to the current directory. If you want to extract the files in
7569 an archive to the same absolute names that they had when the archive
7570 was created, you should do a @samp{cd /} before extracting the files
7571 from the archive, or you should either use the @value{op-absolute-names}
7572 option, or use the command @samp{tar -C / @dots{}}.
7574 @cindex Ultrix 3.1 and write failure
7575 Some versions of Unix (Ultrix 3.1 is know to have this problem),
7576 can claim that a short write near the end of a tape succeeded,
7577 when it actually failed. This will result in the -M option not
7578 working correctly. The best workaround at the moment is to use a
7579 significantly larger blocking factor than the default 20.
7581 In order to update an archive, @code{tar} must be able to backspace the
7582 archive in order to reread or rewrite a record that was just read (or
7583 written). This is currently possible only on two kinds of files: normal
7584 disk files (or any other file that can be backspaced with @samp{lseek}),
7585 and industry-standard 9-track magnetic tape (or any other kind of tape
7586 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
7588 This means that the @value{op-append}, @value{op-update},
7589 @value{op-concatenate}, and @value{op-delete} commands will not work on any
7590 other kind of file. Some media simply cannot be backspaced, which
7591 means these commands and options will never be able to work on them.
7592 These non-backspacing media include pipes and cartridge tape drives.
7594 Some other media can be backspaced, and @code{tar} will work on them
7595 once @code{tar} is modified to do so.
7597 Archives created with the @value{op-multi-volume}, @value{op-label}, and
7598 @value{op-incremental} options may not be readable by other version
7599 of @code{tar}. In particular, restoring a file that was split over
7600 a volume boundary will require some careful work with @code{dd}, if
7601 it can be done at all. Other versions of @code{tar} may also create
7602 an empty file whose name is that of the volume header. Some versions
7603 of @code{tar} may create normal files instead of directories archived
7604 with the @value{op-incremental} option.
7606 @node Common Problems and Solutions, Blocking, Remote Tape Server, Media
7607 @section Some Common Problems and their Solutions
7614 no such file or directory
7617 errors from @code{tar}:
7618 directory checksum error
7621 errors from media/system:
7628 @node Blocking, Many, Common Problems and Solutions, Media
7632 @dfn{Block} and @dfn{record} terminology is rather confused, and it
7633 is also confusing to the expert reader. On the other hand, readers
7634 who are new to the field have a fresh mind, and they may safely skip
7635 the next two paragraphs, as the remainder of this manual uses those
7636 two terms in a quite consistent way.
7638 John Gilmore, the writer of the public domain @code{tar} from which
7639 GNU @code{tar} was originally derived, wrote (June 1995):
7642 The nomenclature of tape drives comes from IBM, where I believe
7643 they were invented for the IBM 650 or so. On IBM mainframes, what
7644 is recorded on tape are tape blocks. The logical organization of
7645 data is into records. There are various ways of putting records into
7646 blocks, including @code{F} (fixed sized records), @code{V} (variable
7647 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
7648 to a block), @code{VB} (variable size records, @var{n} to a block),
7649 @code{VSB} (variable spanned blocked: variable sized records that can
7650 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
7651 parameter specified this to the operating system.
7653 The Unix man page on @code{tar} was totally confused about this.
7654 When I wrote @code{PD TAR}, I used the historically correct terminology
7655 (@code{tar} writes data records, which are grouped into blocks).
7656 It appears that the bogus terminology made it into POSIX (no surprise
7657 here), and now Fran@,{c}ois has migrated that terminology back
7658 into the source code too.
7661 The term @dfn{physical block} means the basic transfer chunk from or
7662 to a device, after which reading or writing may stop without anything
7663 being lost. In this manual, the term @dfn{block} usually refers to
7664 a disk physical block, @emph{assuming} that each disk block is 512
7665 bytes in length. It is true that some disk devices have different
7666 physical blocks, but @code{tar} ignore these differences in its own
7667 format, which is meant to be portable, so a @code{tar} block is always
7668 512 bytes in length, and @dfn{block} always mean a @code{tar} block.
7669 The term @dfn{logical block} often represents the basic chunk of
7670 allocation of many disk blocks as a single entity, which the operating
7671 system treats somewhat atomically; this concept is only barely used
7674 The term @dfn{physical record} is another way to speak of a physical
7675 block, those two terms are somewhat interchangeable. In this manual,
7676 the term @dfn{record} usually refers to a tape physical block,
7677 @emph{assuming} that the @code{tar} archive is kept on magnetic tape.
7678 It is true that archives may be put on disk or used with pipes,
7679 but nevertheless, @code{tar} tries to read and write the archive one
7680 @dfn{record} at a time, whatever the medium in use. One record is made
7681 up of an integral number of blocks, and this operation of putting many
7682 disk blocks into a single tape block is called @dfn{reblocking}, or
7683 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
7684 the logical organization of many characters into something meaningful
7685 to the application. The term @dfn{unit record} describes a small set
7686 of characters which are transmitted whole to or by the application,
7687 and often refers to a line of text. Those two last terms are unrelated
7688 to what we call a @dfn{record} in GNU @code{tar}.
7690 When writing to tapes, @code{tar} writes the contents of the archive
7691 in chunks known as @dfn{records}. To change the default blocking
7692 factor, use the @value{op-blocking-factor} option. Each record will
7693 then be composed of @var{512-size} blocks. (Each @code{tar} block is
7694 512 bytes. @xref{Standard}.) Each file written to the archive uses
7695 at least one full record. As a result, using a larger record size
7696 can result in more wasted space for small files. On the other hand, a
7697 larger record size can often be read and written much more efficiently.
7699 Further complicating the problem is that some tape drives ignore the
7700 blocking entirely. For these, a larger record size can still improve
7701 performance (because the software layers above the tape drive still
7702 honor the blocking), but not as dramatically as on tape drives that
7705 When reading an archive, @code{tar} can usually figure out the record
7706 size on itself. When this is the case, and a non-standard record size
7707 was used when the archive was created, @code{tar} will print a message
7708 about a non-standard blocking factor, and then operate normally. On
7709 some tape devices, however, @code{tar} cannot figure out the record size
7710 itself. On most of those, you can specify a blocking factor (with
7711 @value{op-blocking-factor}) larger than the actual blocking factor, and then use
7712 the @value{op-read-full-records} option. (If you specify a blocking factor
7713 with @value{op-blocking-factor} and don't use the @value{op-read-full-records}
7714 option, then @code{tar} will not attempt to figure out the recording size
7715 itself.) On some devices, you must always specify the record size
7716 exactly with @value{op-blocking-factor} when reading, because @code{tar} cannot
7717 figure it out. In any case, use @value{op-list} before doing any
7718 extractions to see whether @code{tar} is reading the archive correctly.
7720 @code{tar} blocks are all fixed size (512 bytes), and its scheme for
7721 putting them into records is to put a whole number of them (one or
7722 more) into each record. @code{tar} records are all the same size;
7723 at the end of the file there's a block containing all zeros, which
7724 is how you tell that the remainder of the last record(s) are garbage.
7726 In a standard @code{tar} file (no options), the block size is 512
7727 and the record size is 10240, for a blocking factor of 20. What the
7728 @value{op-blocking-factor} option does is sets the blocking factor,
7729 changing the record size while leaving the block size at 512 bytes.
7730 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
7731 most tape drives these days prefer much bigger records in order to
7732 stream and not waste tape. When writing tapes for myself, some tend
7733 to use a factor of the order of 2048, say, giving a record size of
7734 around one megabyte.
7736 If you use a blocking factor larger than 20, older @code{tar} programs
7737 might not be able to read the archive, so we recommend this as a limit
7738 to use in practice. GNU @code{tar}, however, will support arbitrarily
7739 large record sizes, limited only by the amount of virtual memory or the
7740 physical characteristics of the tape device.
7743 * Format Variations:: Format Variations
7744 * Blocking Factor:: The Blocking Factor of an Archive
7747 @node Format Variations, Blocking Factor, Blocking, Blocking
7748 @subsection Format Variations
7749 @cindex Format Parameters
7750 @cindex Format Options
7751 @cindex Options, archive format specifying
7752 @cindex Options, format specifying
7755 Format parameters specify how an archive is written on the archive
7756 media. The best choice of format parameters will vary depending on
7757 the type and number of files being archived, and on the media used to
7760 To specify format parameters when accessing or creating an archive,
7761 you can use the options described in the following sections.
7762 If you do not specify any format parameters, @code{tar} uses
7763 default parameters. You cannot modify a compressed archive.
7764 If you create an archive with the @value{op-blocking-factor} option
7765 specified (@value{pxref-blocking-factor}), you must specify that
7766 blocking-factor when operating on the archive. @xref{Formats}, for other
7767 examples of format parameter considerations.
7769 @node Blocking Factor, , Format Variations, Blocking
7770 @subsection The Blocking Factor of an Archive
7771 @cindex Blocking Factor
7773 @cindex Number of blocks per record
7774 @cindex Number of bytes per record
7775 @cindex Bytes per record
7776 @cindex Blocks per record
7779 The data in an archive is grouped into blocks, which are 512 bytes.
7780 Blocks are read and written in whole number multiples called
7781 @dfn{records}. The number of blocks in a record (ie. the size of a
7782 record in units of 512 bytes) is called the @dfn{blocking factor}.
7783 The @value{op-blocking-factor} option specifies the blocking factor of
7784 an archive. The default blocking factor is typically 20 (ie.@:
7785 10240 bytes), but can be specified at installation. To find out
7786 the blocking factor of an existing archive, use @samp{tar --list
7787 --file=@var{archive-name}}. This may not work on some devices.
7789 Records are separated by gaps, which waste space on the archive media.
7790 If you are archiving on magnetic tape, using a larger blocking factor
7791 (and therefore larger records) provides faster throughput and allows you
7792 to fit more data on a tape (because there are fewer gaps). If you are
7793 archiving on cartridge, a very large blocking factor (say 126 or more)
7794 greatly increases performance. A smaller blocking factor, on the other
7795 hand, may be useful when archiving small files, to avoid archiving lots
7796 of nulls as @code{tar} fills out the archive to the end of the record.
7797 In general, the ideal record size depends on the size of the
7798 inter-record gaps on the tape you are using, and the average size of the
7799 files you are archiving. @xref{create}, for information on
7802 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
7804 Archives with blocking factors larger than 20 cannot be read
7805 by very old versions of @code{tar}, or by some newer versions
7806 of @code{tar} running on old machines with small address spaces.
7807 With GNU @code{tar}, the blocking factor of an archive is limited
7808 only by the maximum record size of the device containing the archive,
7809 or by the amount of available virtual memory.
7811 Also, on some systems, not using adequate blocking factors, as sometimes
7812 imposed by the device drivers, may yield unexpected diagnostics. For
7813 example, this has been reported:
7816 Cannot write to /dev/dlt: Invalid argument
7820 In such cases, it sometimes happen that the @code{tar} bundled by the
7821 system is aware of block size idiosyncrasies, while GNU @code{tar} requires
7822 an explicit specification for the block size, which it cannot guess.
7823 This yields some people to consider GNU @code{tar} is misbehaving, because
7824 by comparison, @cite{the bundle @code{tar} works OK}. Adding @w{@kbd{-b
7825 256}}, for example, might resolve the problem.
7827 If you use a non-default blocking factor when you create an archive, you
7828 must specify the same blocking factor when you modify that archive. Some
7829 archive devices will also require you to specify the blocking factor when
7830 reading that archive, however this is not typically the case. Usually, you
7831 can use @value{op-list} without specifying a blocking factor---@code{tar}
7832 reports a non-default record size and then lists the archive members as
7833 it would normally. To extract files from an archive with a non-standard
7834 blocking factor (particularly if you're not sure what the blocking factor
7835 is), you can usually use the @value{op-read-full-records} option while
7836 specifying a blocking factor larger then the blocking factor of the archive
7837 (ie. @samp{tar --extract --read-full-records --blocking-factor=300}.
7838 @xref{list}, for more information on the @value{op-list}
7839 operation. @xref{Reading}, for a more detailed explanation of that option.
7842 @item --blocking-factor=@var{number}
7843 @itemx -b @var{number}
7844 Specifies the blocking factor of an archive. Can be used with any
7845 operation, but is usually not necessary with @value{op-list}.
7851 @item -b @var{blocks}
7852 @itemx --blocking-factor=@var{blocks}
7853 Set record size to @math{@var{blocks} * 512} bytes.
7855 This option is used to specify a @dfn{blocking factor} for the archive.
7856 When reading or writing the archive, @code{tar}, will do reads and writes
7857 of the archive in records of @math{@var{block}*512} bytes. This is true
7858 even when the archive is compressed. Some devices requires that all
7859 write operations be a multiple of a certain size, and so, @code{tar}
7860 pads the archive out to the next record boundary.
7862 The default blocking factor is set when @code{tar} is compiled, and is
7863 typically 20. Blocking factors larger than 20 cannot be read by very
7864 old versions of @code{tar}, or by some newer versions of @code{tar}
7865 running on old machines with small address spaces.
7867 With a magnetic tape, larger records give faster throughput and fit
7868 more data on a tape (because there are fewer inter-record gaps).
7869 If the archive is in a disk file or a pipe, you may want to specify
7870 a smaller blocking factor, since a large one will result in a large
7871 number of null bytes at the end of the archive.
7873 When writing cartridge or other streaming tapes, a much larger
7874 blocking factor (say 126 or more) will greatly increase performance.
7875 However, you must specify the same blocking factor when reading or
7876 updating the archive.
7878 Apparently, Exabyte drives have a physical block size of 8K bytes.
7879 If we choose our blocksize as a multiple of 8k bytes, then the problem
7880 seems to dissapper. Id est, we are using block size of 112 right
7881 now, and we haven't had the problem since we switched@dots{}
7883 With GNU @code{tar} the blocking factor is limited only by the maximum
7884 record size of the device containing the archive, or by the amount of
7885 available virtual memory.
7887 However, deblocking or reblocking is virtually avoided in a special
7888 case which often occurs in practice, but which requires all the
7889 following conditions to be simultaneously true:
7892 the archive is subject to a compression option,
7894 the archive is not handled through standard input or output, nor
7895 redirected nor piped,
7897 the archive is directly handled to a local disk, instead of any special
7900 @value{op-blocking-factor} is not explicitly specified on the @code{tar}
7904 In previous versions of GNU @code{tar}, the @samp{--compress-block}
7905 option (or even older: @samp{--block-compress}) was necessary to
7906 reblock compressed archives. It is now a dummy option just asking
7907 not to be used, and otherwise ignored. If the output goes directly
7908 to a local disk, and not through stdout, then the last write is
7909 not extended to a full record size. Otherwise, reblocking occurs.
7910 Here are a few other remarks on this topic:
7915 @code{gzip} will complain about trailing garbage if asked to
7916 uncompress a compressed archive on tape, there is an option to turn
7917 the message off, but it breaks the regularity of simply having to use
7918 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
7919 silently ignoring any number of trailing zeros. I'll ask Jean-loup
7920 Gailly, by sending a copy of this message to him.
7923 @code{compress} does not show this problem, but as Jean-loup pointed
7924 out to Michael, @samp{compress -d} silently adds garbage after
7925 the result of decompression, which tar ignores because it already
7926 recognized its end-of-file indicator. So this bug may be safely
7930 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
7931 but will still return an exit status of 2 which tar reports in turn.
7932 @code{tar} might ignore the exit status returned, but I hate doing
7933 that, as it weakens the protection @code{tar} offers users against
7934 other possible problems at decompression time. If @code{gzip} was
7935 silently skipping trailing zeros @emph{and} also avoiding setting the
7936 exit status in this innocuous case, that would solve this situation.
7939 @code{tar} should become more solid at not stopping to read a pipe at
7940 the first null block encountered. This inelegantly breaks the pipe.
7941 @code{tar} should rather drain the pipe out before exiting itself.
7945 @itemx --ignore-zeros
7946 Ignore blocks of zeros in archive (means EOF).
7948 The @value{op-ignore-zeros} option causes @code{tar} to ignore blocks
7949 of zeros in the archive. Normally a block of zeros indicates the
7950 end of the archive, but when reading a damaged archive, or one which
7951 was created by @code{cat}-ing several archives together, this option
7952 allows @code{tar} to read the entire archive. This option is not on
7953 by default because many versions of @code{tar} write garbage after
7956 Note that this option causes @code{tar} to read to the end of the
7957 archive file, which may sometimes avoid problems when multiple files
7958 are stored on a single physical tape.
7961 @itemx --read-full-records
7962 Reblock as we read (for reading 4.2BSD pipes).
7964 If @value{op-read-full-records} is used, @code{tar} will not panic if an
7965 attempt to read a record from the archive does not return a full record.
7966 Instead, @code{tar} will keep reading until it has obtained a full
7969 This option is turned on by default when @code{tar} is reading
7970 an archive from standard input, or from a remote machine. This is
7971 because on BSD Unix systems, a read of a pipe will return however
7972 much happens to be in the pipe, even if it is less than @code{tar}
7973 requested. If this option was not used, @code{tar} would fail as
7974 soon as it read an incomplete record from the pipe.
7976 This option is also useful with the commands for updating an archive.
7982 @FIXME{Appropriate options should be moved here from elsewhere.}
7984 @cindex blocking factor
7985 @cindex tape blocking
7987 When handling various tapes or cartridges, you have to take care of
7988 selecting a proper blocking, that is, the number of disk blocks you
7989 put together as a single tape block on the tape, without intervening
7990 tape gaps. A @dfn{tape gap} is a small landing area on the tape
7991 with no information on it, used for decelerating the tape to a
7992 full stop, and for later regaining the reading or writing speed.
7993 When the tape driver starts reading a record, the record has to
7994 be read whole without stopping, as a tape gap is needed to stop the
7995 tape motion without loosing information.
7997 @cindex Exabyte blocking
7998 @cindex DAT blocking
7999 Using higher blocking (putting more disk blocks per tape block) will use
8000 the tape more efficiently as there will be less tape gaps. But reading
8001 such tapes may be more difficult for the system, as more memory will be
8002 required to receive at once the whole record. Further, if there is a
8003 reading error on a huge record, this is less likely that the system will
8004 succeed in recovering the information. So, blocking should not be too
8005 low, nor it should be too high. @code{tar} uses by default a blocking of
8006 20 for historical reasons, and it does not really matter when reading or
8007 writing to disk. Current tape technology would easily accommodate higher
8008 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
8009 We were told that for some DLT drives, the blocking should be a multiple
8010 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
8011 Other manufacturers may use different recommendations for the same tapes.
8012 This might also depends of the buffering techniques used inside modern
8013 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
8014 Others request blocking to be some exponent of two.
8016 So, there is no fixed rule for blocking. But blocking at read time
8017 should ideally be the same as blocking used at write time. At one place
8018 I know, with a wide variety of equipment, they found it best to use a
8019 blocking of 32 to guarantee that their tapes are fully interchangeable.
8021 I was also told that, for recycled tapes, prior erasure (by the same
8022 drive unit that will be used to create the archives) sometimes lowers
8023 the error rates observed at rewriting time.
8025 I might also use @samp{--number-blocks} instead of
8026 @samp{--block-number}, so @samp{--block} will then expand to
8027 @samp{--blocking-factor} unambiguously.
8029 @node Many, Using Multiple Tapes, Blocking, Media
8030 @section Many Archives on One Tape
8032 @FIXME{Appropriate options should be moved here from elsewhere.}
8034 @findex ntape @r{device}
8035 Most tape devices have two entries in the @file{/dev} directory, or
8036 entries that come in pairs, which differ only in the minor number for
8037 this device. Let's take for example @file{/dev/tape}, which often
8038 points to the only or usual tape device of a given system. There might
8039 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
8040 name is the @emph{rewinding} version of the device, while the name
8041 having @samp{nr} in it is the @emph{no rewinding} version of the same
8044 A rewinding tape device will bring back the tape to its beginning point
8045 automatically when this device is opened or closed. Since @code{tar}
8046 opens the archive file before using it and closes it afterwards, this
8047 means that a simple:
8050 $ @kbd{tar cf /dev/tape @var{directory}}
8054 will reposition the tape to its beginning both prior and after saving
8055 @var{directory} contents to it, thus erasing prior tape contents and
8056 making it so that any subsequent write operation will destroy what has
8059 @cindex tape positioning
8060 So, a rewinding device is normally meant to hold one and only one file.
8061 If you want to put more than one @code{tar} archive on a given tape, you
8062 will need to avoid using the rewinding version of the tape device. You
8063 will also have to pay special attention to tape positioning. Errors in
8064 positioning may overwrite the valuable data already on your tape. Many
8065 people, burnt by past experiences, will only use rewinding devices and
8066 limit themselves to one file per tape, precisely to avoid the risk of
8067 such errors. Be fully aware that writing at the wrong position on a
8068 tape loses all information past this point and most probably until the
8069 end of the tape, and this destroyed information @emph{cannot} be
8072 To save @var{directory-1} as a first archive at the beginning of a
8073 tape, and leave that tape ready for a second archive, you should use:
8076 $ @kbd{mt -f /dev/nrtape rewind}
8077 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
8081 @dfn{Tape marks} are special magnetic patterns written on the tape
8082 media, which are later recognizable by the reading hardware. These
8083 marks are used after each file, when there are many on a single tape.
8084 An empty file (that is to say, two tape marks in a row) signal the
8085 logical end of the tape, after which no file exist. Usually,
8086 non-rewinding tape device drivers will react to the close request issued
8087 by @code{tar} by first writing two tape marks after your archive, and by
8088 backspacing over one of these. So, if you remove the tape at that time
8089 from the tape drive, it is properly terminated. But if you write
8090 another file at the current position, the second tape mark will be
8091 erased by the new information, leaving only one tape mark between files.
8093 So, you may now save @var{directory-2} as a second archive after the
8094 first on the same tape by issuing the command:
8097 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
8101 and so on for all the archives you want to put on the same tape.
8103 Another usual case is that you do not write all the archives the same
8104 day, and you need to remove and store the tape between two archive
8105 sessions. In general, you must remember how many files are already
8106 saved on your tape. Suppose your tape already has 16 files on it, and
8107 that you are ready to write the 17th. You have to take care of skipping
8108 the first 16 tape marks before saving @var{directory-17}, say, by using
8112 $ @kbd{mt -f /dev/nrtape rewind}
8113 $ @kbd{mt -f /dev/nrtape fsf 16}
8114 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
8117 In all the previous examples, we put aside blocking considerations, but
8118 you should do the proper things for that as well. @xref{Blocking}.
8121 * Tape Positioning:: Tape Positions and Tape Marks
8122 * mt:: The @code{mt} Utility
8125 @node Tape Positioning, mt, Many, Many
8126 @subsection Tape Positions and Tape Marks
8129 Just as archives can store more than one file from the file system,
8130 tapes can store more than one archive file. To keep track of where
8131 archive files (or any other type of file stored on tape) begin and
8132 end, tape archive devices write magnetic @dfn{tape marks} on the
8133 archive media. Tape drives write one tape mark between files,
8134 two at the end of all the file entries.
8136 If you think of data as a series of records "rrrr"'s, and tape marks as
8137 "*"'s, a tape might look like the following:
8140 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
8143 Tape devices read and write tapes using a read/write @dfn{tape
8144 head}---a physical part of the device which can only access one
8145 point on the tape at a time. When you use @code{tar} to read or
8146 write archive data from a tape device, the device will begin reading
8147 or writing from wherever on the tape the tape head happens to be,
8148 regardless of which archive or what part of the archive the tape
8149 head is on. Before writing an archive, you should make sure that no
8150 data on the tape will be overwritten (unless it is no longer needed).
8151 Before reading an archive, you should make sure the tape head is at
8152 the beginning of the archive you want to read. (The @code{restore}
8153 script will find the archive automatically. @FIXME{There is no such
8154 restore script!}@FIXME-xref{Scripted Restoration}@xref{mt}, for
8155 an explanation of the tape moving utility.
8157 If you want to add new archive file entries to a tape, you should
8158 advance the tape to the end of the existing file entries, backspace
8159 over the last tape mark, and write the new archive file. If you were
8160 to add two archives to the example above, the tape might look like the
8164 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
8167 @node mt, , Tape Positioning, Many
8168 @subsection The @code{mt} Utility
8171 @FIXME{Is it true that this only works on non-block devices?
8172 should explain the difference, (fixed or variable).}
8173 @value{xref-blocking-factor}.
8175 You can use the @code{mt} utility to advance or rewind a tape past a
8176 specified number of archive files on the tape. This will allow you
8177 to move to the beginning of an archive before extracting or reading
8178 it, or to the end of all the archives before writing a new one.
8179 @FIXME{Why isn't there an "advance 'til you find two tape marks
8182 The syntax of the @code{mt} command is:
8185 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
8188 where @var{tapename} is the name of the tape device, @var{number} is
8189 the number of times an operation is performed (with a default of one),
8190 and @var{operation} is one of the following:
8192 @FIXME{is there any use for record operations?}
8197 Writes @var{number} tape marks at the current position on the tape.
8200 Moves tape position forward @var{number} files.
8203 Moves tape position back @var{number} files.
8206 Rewinds the tape. (Ignores @var{number}).
8210 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
8213 Prints status information about the tape unit.
8217 @FIXME{Is there a better way to frob the spacing on the list?}
8219 If you don't specify a @var{tapename}, @code{mt} uses the environment
8220 variable TAPE; if TAPE does not exist, @code{mt} uses the device
8223 @code{mt} returns a 0 exit status when the operation(s) were
8224 successful, 1 if the command was unrecognized, and 2 if an operation
8227 @FIXME{New node on how to find an archive?}
8229 If you use @value{op-extract} with the @value{op-label} option specified,
8230 @code{tar} will read an archive label (the tape head has to be positioned
8231 on it) and print an error if the archive label doesn't match the
8232 @var{archive-name} specified. @var{archive-name} can be any regular
8233 expression. If the labels match, @code{tar} extracts the archive.
8235 @FIXME-xref{Matching Format Parameters}@FIXME{fix cross
8236 references}@samp{tar --list --label} will cause @code{tar} to print the
8239 @FIXME{Program to list all the labels on a tape?}
8241 @node Using Multiple Tapes, label, Many, Media
8242 @section Using Multiple Tapes
8245 Often you might want to write a large archive, one larger than will fit
8246 on the actual tape you are using. In such a case, you can run multiple
8247 @code{tar} commands, but this can be inconvenient, particularly if you
8248 are using options like @value{op-exclude} or dumping entire filesystems.
8249 Therefore, @code{tar} supports multiple tapes automatically.
8251 Use @value{op-multi-volume} on the command line, and then @code{tar} will,
8252 when it reaches the end of the tape, prompt for another tape, and
8253 continue the archive. Each tape will have an independent archive, and
8254 can be read without needing the other. (As an exception to this, the
8255 file that @code{tar} was archiving when it ran out of tape will usually
8256 be split between the two archives; in this case you need to extract from
8257 the first archive, using @value{op-multi-volume}, and then put in the
8258 second tape when prompted, so @code{tar} can restore both halves of the
8261 GNU @code{tar} multi-volume archives do not use a truly portable format.
8262 You need GNU @code{tar} at both end to process them properly.
8264 When prompting for a new tape, @code{tar} accepts any of the following
8269 Request @code{tar} to explain possible responses
8271 Request @code{tar} to exit immediately.
8272 @item n @var{file name}
8273 Request @code{tar} to write the next volume on the file @var{file name}.
8275 Request @code{tar} to run a subshell.
8277 Request @code{tar} to begin writing the next volume.
8280 (You should only type @samp{y} after you have changed the tape;
8281 otherwise @code{tar} will write over the volume it just finished.)
8283 If you want more elaborate behavior than this, give @code{tar} the
8284 @value{op-info-script} option. The file @var{script-name} is expected
8285 to be a program (or shell script) to be run instead of the normal
8286 prompting procedure. When the program finishes, @code{tar} will
8287 immediately begin writing the next volume. The behavior of the
8288 @samp{n} response to the normal tape-change prompt is not available
8289 if you use @value{op-info-script}.
8291 The method @code{tar} uses to detect end of tape is not perfect, and
8292 fails on some operating systems or on some devices. You can use the
8293 @value{op-tape-length} option if @code{tar} can't detect the end of the
8294 tape itself. This option selects @value{op-multi-volume} automatically.
8295 The @var{size} argument should then be the usable size of the tape.
8296 But for many devices, and floppy disks in particular, this option is
8297 never required for real, as far as we know.
8299 The volume number used by @code{tar} in its tape-change prompt
8300 can be changed; if you give the @value{op-volno-file} option, then
8301 @var{file-of-number} should be an unexisting file to be created, or else,
8302 a file already containing a decimal number. That number will be used
8303 as the volume number of the first volume written. When @code{tar} is
8304 finished, it will rewrite the file with the now-current volume number.
8305 (This does not change the volume number written on a tape label, as
8306 per @value{ref-label}, it @emph{only} affects the number used in
8309 If you want @code{tar} to cycle through a series of tape drives, then
8310 you can use the @samp{n} response to the tape-change prompt. This is
8311 error prone, however, and doesn't work at all with @value{op-info-script}.
8312 Therefore, if you give @code{tar} multiple @value{op-file} options, then
8313 the specified files will be used, in sequence, as the successive volumes
8314 of the archive. Only when the first one in the sequence needs to be
8315 used again will @code{tar} prompt for a tape change (or run the info
8318 Multi-volume archives
8320 With @value{op-multi-volume}, @code{tar} will not abort when it cannot
8321 read or write any more data. Instead, it will ask you to prepare a new
8322 volume. If the archive is on a magnetic tape, you should change tapes
8323 now; if the archive is on a floppy disk, you should change disks, etc.
8325 Each volume of a multi-volume archive is an independent @code{tar}
8326 archive, complete in itself. For example, you can list or extract any
8327 volume alone; just don't specify @value{op-multi-volume}. However, if one
8328 file in the archive is split across volumes, the only way to extract
8329 it successfully is with a multi-volume extract command @samp{--extract
8330 --multi-volume} (@samp{-xM}) starting on or before the volume where
8333 For example, let's presume someone has two tape drives on a system
8334 named @file{/dev/tape0} and @file{/dev/tape1}. For having GNU
8335 @code{tar} to switch to the second drive when it needs to write the
8336 second tape, and then back to the first tape, etc., just do either of:
8339 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
8340 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
8344 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
8345 * Tape Files:: Tape Files
8348 @node Multi-Volume Archives, Tape Files, Using Multiple Tapes, Using Multiple Tapes
8349 @subsection Archives Longer than One Tape or Disk
8350 @cindex Multi-volume archives
8353 To create an archive that is larger than will fit on a single unit of
8354 the media, use the @value{op-multi-volume} option in conjunction with
8355 the @value{op-create} option (@pxref{create}). A
8356 @dfn{multi-volume} archive can be manipulated like any other archive
8357 (provided the @value{op-multi-volume} option is specified), but is
8358 stored on more than one tape or disk.
8360 When you specify @value{op-multi-volume}, @code{tar} does not report an
8361 error when it comes to the end of an archive volume (when reading), or
8362 the end of the media (when writing). Instead, it prompts you to load
8363 a new storage volume. If the archive is on a magnetic tape, you
8364 should change tapes when you see the prompt; if the archive is on a
8365 floppy disk, you should change disks; etc.
8367 You can read each individual volume of a multi-volume archive as if it
8368 were an archive by itself. For example, to list the contents of one
8369 volume, use @value{op-list}, without @value{op-multi-volume} specified.
8370 To extract an archive member from one volume (assuming it is described
8371 that volume), use @value{op-extract}, again without
8372 @value{op-multi-volume}.
8374 If an archive member is split across volumes (ie. its entry begins on
8375 one volume of the media and ends on another), you need to specify
8376 @value{op-multi-volume} to extract it successfully. In this case, you
8377 should load the volume where the archive member starts, and use
8378 @samp{tar --extract --multi-volume}---@code{tar} will prompt for later
8379 volumes as it needs them. @xref{extracting archives}, for more
8380 information about extracting archives.
8382 @value{op-info-script} is like @value{op-multi-volume}, except that
8383 @code{tar} does not prompt you directly to change media volumes when
8384 a volume is full---instead, @code{tar} runs commands you have stored
8385 in @var{script-name}. For example, this option can be used to eject
8386 cassettes, or to broadcast messages such as @samp{Someone please come
8387 change my tape} when performing unattended backups. When @var{script-name}
8388 is done, @code{tar} will assume that the media has been changed.
8390 Multi-volume archives can be modified like any other archive. To add
8391 files to a multi-volume archive, you need to only mount the last
8392 volume of the archive media (and new volumes, if needed). For all
8393 other operations, you need to use the entire archive.
8395 If a multi-volume archive was labeled using @value{op-label}
8396 (@value{pxref-label}) when it was created, @code{tar} will not
8397 automatically label volumes which are added later. To label subsequent
8398 volumes, specify @value{op-label} again in conjunction with the
8399 @value{op-append}, @value{op-update} or @value{op-concatenate} operation.
8401 @cindex Labeling multi-volume archives
8404 @FIXME{There should be a sample program here, including an exit
8405 before end. Is the exit status even checked in tar? :-(}
8408 @item --multi-volume
8410 Creates a multi-volume archive, when used in conjunction with
8411 @value{op-create}. To perform any other operation on a multi-volume
8412 archive, specify @value{op-multi-volume} in conjunction with that
8415 @item --info-script=@var{program-file}
8416 @itemx -F @var{program-file}
8417 Creates a multi-volume archive via a script. Used in conjunction with
8421 Beware that there is @emph{no} real standard about the proper way, for a
8422 @code{tar} archive, to span volume boundaries. If you have a multi-volume
8423 created by some vendor's @code{tar}, there is almost no chance you could
8424 read all the volumes with GNU @code{tar}. The converse is also true:
8425 you may not expect multi-volume archives created by GNU @code{tar} to
8426 be fully recovered by vendor's @code{tar}. Since there is little chance
8427 that, in mixed system configurations, some vendor's @code{tar} will work on
8428 another vendor's machine, and there is a great chance that GNU @code{tar}
8429 will work on most of them, your best bet is to install GNU @code{tar}
8430 on all machines between which you know exchange of files is possible.
8432 @node Tape Files, , Multi-Volume Archives, Using Multiple Tapes
8433 @subsection Tape Files
8436 To give the archive a name which will be recorded in it, use the
8437 @value{op-label} option. This will write a special block identifying
8438 @var{volume-label} as the name of the archive to the front of the archive
8439 which will be displayed when the archive is listed with @value{op-list}.
8440 If you are creating a multi-volume archive with
8441 @value{op-multi-volume}@FIXME-pxref{Using Multiple Tapes}, then the
8442 volume label will have
8443 @samp{Volume @var{nnn}} appended to the name you give, where @var{nnn} is
8444 the number of the volume of the archive. (If you use the @value{op-label}
8445 option when reading an archive, it checks to make sure the label on the
8446 tape matches the one you give. @value{xref-label}.
8448 When @code{tar} writes an archive to tape, it creates a single
8449 tape file. If multiple archives are written to the same tape, one
8450 after the other, they each get written as separate tape files. When
8451 extracting, it is necessary to position the tape at the right place
8452 before running @code{tar}. To do this, use the @code{mt} command.
8453 For more information on the @code{mt} command and on the organization
8454 of tapes into a sequence of tape files, see @ref{mt}.
8456 People seem to often do:
8459 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
8462 or such, for pushing a common date in all volumes or an archive set.
8464 @node label, verify, Using Multiple Tapes, Media
8465 @section Including a Label in the Archive
8466 @cindex Labeling an archive
8467 @cindex Labels on the archive media
8472 @itemx --label=@var{name}
8473 Create archive with volume name @var{name}.
8476 This option causes @code{tar} to write out a @dfn{volume header} at
8477 the beginning of the archive. If @value{op-multi-volume} is used, each
8478 volume of the archive will have a volume header of @samp{@var{name}
8479 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
8482 @FIXME{Should the arg to --label be a quoted string?? No.}
8484 To avoid problems caused by misplaced paper labels on the archive
8485 media, you can include a @dfn{label} entry---an archive member which
8486 contains the name of the archive---in the archive itself. Use the
8487 @value{op-label} option in conjunction with the @value{op-create} operation
8488 to include a label entry in the archive as it is being created.
8490 If you create an archive using both @value{op-label} and
8491 @value{op-multi-volume}, each volume of the archive will have an
8492 archive label of the form @samp{@var{archive-label} Volume @var{n}},
8493 where @var{n} is 1 for the first volume, 2 for the next, and so on.
8494 @FIXME-xref{Multi-Volume Archives, for information on creating multiple
8497 If you list or extract an archive using @value{op-label}, @code{tar} will
8498 print an error if the archive label doesn't match the @var{archive-label}
8499 specified, and will then not list nor extract the archive. In those cases,
8500 @var{archive-label} argument is interpreted as a globbing-style pattern
8501 which must match the actual magnetic volume label. @xref{exclude}, for
8502 a precise description of how match is attempted@footnote{Previous versions
8503 of @code{tar} used full regular expression matching, or before that, only
8504 exact string matching, instead of wildcard matchers. We decided for the
8505 sake of simplicity to use a uniform matching device through @code{tar}.}.
8506 If the switch @value{op-multi-volume} is being used, the volume label
8507 matcher will also suffix @var{archive-label} by @w{@samp{ Volume [1-9]*}}
8508 if the initial match fails, before giving up. Since the volume numbering
8509 is automatically added in labels at creation time, it sounded logical to
8510 equally help the user taking care of it when the archive is being read.
8512 The @value{op-label} was once called @samp{--volume}, but is not available
8513 under that name anymore.
8515 To find out an archive's label entry (or to find out if an archive has
8516 a label at all), use @samp{tar --list --verbose}. @code{tar} will print the
8517 label first, and then print archive member information, as in the
8521 $ @kbd{tar --verbose --list --file=iamanarchive}
8522 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
8523 -rw-rw-rw- ringo user 40 1990-05-21 13:30 iamafilename
8527 @item --label=@var{archive-label}
8528 @itemx -V @var{archive-label}
8529 Includes an @dfn{archive-label} at the beginning of the archive when
8530 the archive is being created, when used in conjunction with the
8531 @value{op-create} option. Checks to make sure the archive label
8532 matches the one specified (when used in conjunction with the
8533 @value{op-extract} option.
8536 To get a common information on all tapes of a series, use the
8537 @value{op-label} option. For having this information different in each
8538 series created through a single script used on a regular basis, just
8539 manage to get some date string as part of the label. For example:
8542 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
8543 $ @kbd{tar --create --file=/dev/tape --multi-volume \
8544 --volume="Daily backup for `date +%Y-%m-%d`"}
8547 Also note that each label has its own date and time, which corresponds
8548 to when GNU @code{tar} initially attempted to write it, often soon
8549 after the operator launches @code{tar} or types the carriage return
8550 telling that the next tape is ready. Comparing date labels does give
8551 an idea of tape throughput only if the delays for rewinding tapes
8552 and the operator switching them were negligible, which is usually
8555 @FIXME{was --volume}
8557 @node verify, Write Protection, label, Media
8558 @section Verifying Data as It is Stored
8559 @cindex Verifying a write operation
8560 @cindex Double-checking a write operation
8565 Attempt to verify the archive after writing.
8568 This option causes @code{tar} to verify the archive after writing it.
8569 Each volume is checked after it is written, and any discrepancies
8570 are recorded on the standard error output.
8572 Verification requires that the archive be on a back-space-able medium.
8573 This means pipes, some cartridge tape drives, and some other devices
8576 You can insure the accuracy of an archive by comparing files in the
8577 system with archive members. @code{tar} can compare an archive to the
8578 file system as the archive is being written, to verify a write
8579 operation, or can compare a previously written archive, to insure that
8582 To check for discrepancies in an archive immediately after it is
8583 written, use the @value{op-verify} option in conjunction with
8584 the @value{op-create} operation. When this option is
8585 specified, @code{tar} checks archive members against their counterparts
8586 in the file system, and reports discrepancies on the standard error. In
8587 multi-volume archives, each volume is verified after it is written,
8588 before the next volume is written.
8590 To verify an archive, you must be able to read it from before the end
8591 of the last written entry. This option is useful for detecting data
8592 errors on some tapes. Archives written to pipes, some cartridge tape
8593 drives, and some other devices cannot be verified.
8595 One can explicitly compare an already made archive with the file system
8596 by using the @value{op-compare} option, instead of using the more automatic
8597 @value{op-verify} option. @value{xref-compare}.
8599 Note that these two options have a slightly different intent. The
8600 @value{op-compare} option how identical are the logical contents of some
8601 archive with what is on your disks, while the @value{op-verify} option is
8602 really for checking if the physical contents agree and if the recording
8603 media itself is of dependable quality. So, for the @value{op-verify}
8604 operation, @code{tar} tries to defeat all in-memory cache pertaining to
8605 the archive, while it lets the speed optimization undisturbed for the
8606 @value{op-compare} option. If you nevertheless use @value{op-compare} for
8607 media verification, you may have to defeat the in-memory cache yourself,
8608 maybe by opening and reclosing the door latch of your recording unit,
8609 forcing some doubt in your operating system about the fact this is really
8610 the same volume as the one just written or read.
8612 The @value{op-verify} option would not be necessary if drivers were indeed
8613 able to detect dependably all write failures. This sometimes require many
8614 magnetic heads, some able to read after the writes occurred. One would
8615 not say that drivers unable to detect all cases are necessarily flawed,
8616 as long as programming is concerned.
8618 @node Write Protection, , verify, Media
8619 @section Write Protection
8621 Almost all tapes and diskettes, and in a few rare cases, even disks can
8622 be @dfn{write protected}, to protect data on them from being changed.
8623 Once an archive is written, you should write protect the media to prevent
8624 the archive from being accidentally overwritten or deleted. (This will
8625 protect the archive from being changed with a tape or floppy drive---it
8626 will not protect it from magnet fields or other physical hazards).
8628 The write protection device itself is usually an integral part of the
8629 physical media, and can be a two position (write enabled/write
8630 disabled) switch, a notch which can be popped out or covered, a ring
8631 which can be removed from the center of a tape reel, or some other
8634 @node Index, , Media, Top
8644 @c texinfo-column-for-description: 32