]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Update
[chaz/tar] / doc / tar.texi
1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename tar.info
4 @include version.texi
5 @settitle GNU tar @value{VERSION}
6 @setchapternewpage odd
7
8 @finalout
9
10 @smallbook
11 @c %**end of header
12
13 @include rendition.texi
14 @include value.texi
15
16 @c Put everything in one index (arbitrarily chosen to be the concept index).
17 @syncodeindex fn cp
18 @syncodeindex ky cp
19 @syncodeindex pg cp
20 @syncodeindex vr cp
21
22 @defindex op
23
24 @copying
25
26 This manual is for @acronym{GNU} @command{tar} (version
27 @value{VERSION}, @value{UPDATED}), which creates and extracts files
28 from archives.
29
30 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
31 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
32
33 @quotation
34 Permission is granted to copy, distribute and/or modify this document
35 under the terms of the GNU Free Documentation License, Version 1.1 or
36 any later version published by the Free Software Foundation; with no
37 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
38 and with the Back-Cover Texts as in (a) below. A copy of the license
39 is included in the section entitled "GNU Free Documentation License".
40
41 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
42 this GNU Manual. Buying copies from GNU Press supports the FSF in
43 developing GNU and promoting software freedom.''
44 @end quotation
45 @end copying
46
47 @dircategory Archiving
48 @direntry
49 * Tar: (tar). Making tape (or disk) archives.
50 @end direntry
51
52 @dircategory Individual utilities
53 @direntry
54 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
55 @end direntry
56
57 @shorttitlepage @acronym{GNU} @command{tar}
58
59 @titlepage
60 @title @acronym{GNU} tar: an archiver tool
61 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
62 @author John Gilmore, Jay Fenlason et al.
63
64 @page
65 @vskip 0pt plus 1filll
66 @insertcopying
67 @end titlepage
68
69 @ifnottex
70 @node Top
71 @top @acronym{GNU} tar: an archiver tool
72
73 @insertcopying
74
75 @cindex file archival
76 @cindex archiving files
77
78 The first part of this master menu lists the major nodes in this Info
79 document. The rest of the menu lists all the lower level nodes.
80 @end ifnottex
81
82 @c The master menu, created with texinfo-master-menu, goes here.
83 @c (However, getdate.texi's menu is interpolated by hand.)
84
85 @menu
86 * Introduction::
87 * Tutorial::
88 * tar invocation::
89 * operations::
90 * Backups::
91 * Choosing::
92 * Date input formats::
93 * Formats::
94 * Media::
95
96 Appendices
97
98 * Changes::
99 * Configuring Help Summary::
100 * Genfile::
101 * Snapshot Files::
102 * Free Software Needs Free Documentation::
103 * Copying This Manual::
104 * Index of Command Line Options::
105 * Index::
106
107 @detailmenu
108 --- The Detailed Node Listing ---
109
110 Introduction
111
112 * Book Contents:: What this Book Contains
113 * Definitions:: Some Definitions
114 * What tar Does:: What @command{tar} Does
115 * Naming tar Archives:: How @command{tar} Archives are Named
116 * Authors:: @GNUTAR{} Authors
117 * Reports:: Reporting bugs or suggestions
118
119 Tutorial Introduction to @command{tar}
120
121 * assumptions::
122 * stylistic conventions::
123 * basic tar options:: Basic @command{tar} Operations and Options
124 * frequent operations::
125 * Two Frequent Options::
126 * create:: How to Create Archives
127 * list:: How to List Archives
128 * extract:: How to Extract Members from an Archive
129 * going further::
130
131 Two Frequently Used Options
132
133 * file tutorial::
134 * verbose tutorial::
135 * help tutorial::
136
137 How to Create Archives
138
139 * prepare for examples::
140 * Creating the archive::
141 * create verbose::
142 * short create::
143 * create dir::
144
145 How to List Archives
146
147 * list dir::
148
149 How to Extract Members from an Archive
150
151 * extracting archives::
152 * extracting files::
153 * extract dir::
154 * failing commands::
155
156 Invoking @GNUTAR{}
157
158 * Synopsis::
159 * using tar options::
160 * Styles::
161 * All Options::
162 * help::
163 * defaults::
164 * verbose::
165 * interactive::
166
167 The Three Option Styles
168
169 * Mnemonic Options:: Mnemonic Option Style
170 * Short Options:: Short Option Style
171 * Old Options:: Old Option Style
172 * Mixing:: Mixing Option Styles
173
174 All @command{tar} Options
175
176 * Operation Summary::
177 * Option Summary::
178 * Short Option Summary::
179
180 @GNUTAR{} Operations
181
182 * Basic tar::
183 * Advanced tar::
184 * create options::
185 * extract options::
186 * backup::
187 * Applications::
188 * looking ahead::
189
190 Advanced @GNUTAR{} Operations
191
192 * Operations::
193 * append::
194 * update::
195 * concatenate::
196 * delete::
197 * compare::
198 * quoting styles::
199
200 How to Add Files to Existing Archives: @option{--append}
201
202 * appending files:: Appending Files to an Archive
203 * multiple::
204
205 Updating an Archive
206
207 * how to update::
208
209 Options Used by @option{--create}
210
211 * Ignore Failed Read::
212
213 Options Used by @option{--extract}
214
215 * Reading:: Options to Help Read Archives
216 * Writing:: Changing How @command{tar} Writes Files
217 * Scarce:: Coping with Scarce Resources
218
219 Options to Help Read Archives
220
221 * read full records::
222 * Ignore Zeros::
223
224 Changing How @command{tar} Writes Files
225
226 * Dealing with Old Files::
227 * Overwrite Old Files::
228 * Keep Old Files::
229 * Keep Newer Files::
230 * Unlink First::
231 * Recursive Unlink::
232 * Data Modification Times::
233 * Setting Access Permissions::
234 * Writing to Standard Output::
235 * remove files::
236
237 Coping with Scarce Resources
238
239 * Starting File::
240 * Same Order::
241
242 Performing Backups and Restoring Files
243
244 * Full Dumps:: Using @command{tar} to Perform Full Dumps
245 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
246 * Backup Levels:: Levels of Backups
247 * Backup Parameters:: Setting Parameters for Backups and Restoration
248 * Scripted Backups:: Using the Backup Scripts
249 * Scripted Restoration:: Using the Restore Script
250
251 Setting Parameters for Backups and Restoration
252
253 * General-Purpose Variables::
254 * Magnetic Tape Control::
255 * User Hooks::
256 * backup-specs example:: An Example Text of @file{Backup-specs}
257
258 Choosing Files and Names for @command{tar}
259
260 * file:: Choosing the Archive's Name
261 * Selecting Archive Members::
262 * files:: Reading Names from a File
263 * exclude:: Excluding Some Files
264 * Wildcards:: Wildcards Patterns and Matching
265 * after:: Operating Only on New Files
266 * recurse:: Descending into Directories
267 * one:: Crossing File System Boundaries
268
269 Reading Names from a File
270
271 * nul::
272
273 Excluding Some Files
274
275 * problems with exclude::
276
277 Crossing File System Boundaries
278
279 * directory:: Changing Directory
280 * absolute:: Absolute File Names
281
282 Date input formats
283
284 * General date syntax:: Common rules.
285 * Calendar date items:: 19 Dec 1994.
286 * Time of day items:: 9:20pm.
287 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}, ...
288 * Day of week items:: Monday and others.
289 * Relative items in date strings:: next tuesday, 2 years ago.
290 * Pure numbers in date strings:: 19931219, 1440.
291 * Seconds since the Epoch:: @@1078100502.
292 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
293
294 Controlling the Archive Format
295
296 * Portability:: Making @command{tar} Archives More Portable
297 * Compression:: Using Less Space through Compression
298 * Attributes:: Handling File Attributes
299 * Standard:: The Standard Format
300 * Extensions:: @acronym{GNU} Extensions to the Archive Format
301 * cpio:: Comparison of @command{tar} and @command{cpio}
302
303 Making @command{tar} Archives More Portable
304
305 * Portable Names:: Portable Names
306 * dereference:: Symbolic Links
307 * old:: Old V7 Archives
308 * posix:: @acronym{POSIX} archives
309 * Checksumming:: Checksumming Problems
310 * Large or Negative Values:: Large files, negative time stamps, etc.
311
312 Using Less Space through Compression
313
314 * gzip:: Creating and Reading Compressed Archives
315 * sparse:: Archiving Sparse Files
316
317 Tapes and Other Archive Media
318
319 * Device:: Device selection and switching
320 * Remote Tape Server::
321 * Common Problems and Solutions::
322 * Blocking:: Blocking
323 * Many:: Many archives on one tape
324 * Using Multiple Tapes:: Using Multiple Tapes
325 * label:: Including a Label in the Archive
326 * verify::
327 * Write Protection::
328
329 Blocking
330
331 * Format Variations:: Format Variations
332 * Blocking Factor:: The Blocking Factor of an Archive
333
334 Many Archives on One Tape
335
336 * Tape Positioning:: Tape Positions and Tape Marks
337 * mt:: The @command{mt} Utility
338
339 Using Multiple Tapes
340
341 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
342 * Tape Files:: Tape Files
343 * Tarcat:: Concatenate Volumes into a Single Archive
344
345 GNU tar internals and development
346
347 * Genfile::
348 * Snapshot Files::
349
350 Copying This Manual
351
352 * Free Software Needs Free Documentation::
353 * GNU Free Documentation License:: License for copying this manual
354
355 @end detailmenu
356 @end menu
357
358 @node Introduction
359 @chapter Introduction
360
361 @GNUTAR{} creates
362 and manipulates @dfn{archives} which are actually collections of
363 many other files; the program provides users with an organized and
364 systematic method for controlling a large amount of data.
365 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
366 archives need not (and these days, typically do not) reside on tapes.
367
368 @menu
369 * Book Contents:: What this Book Contains
370 * Definitions:: Some Definitions
371 * What tar Does:: What @command{tar} Does
372 * Naming tar Archives:: How @command{tar} Archives are Named
373 * Authors:: @GNUTAR{} Authors
374 * Reports:: Reporting bugs or suggestions
375 @end menu
376
377 @node Book Contents
378 @section What this Book Contains
379
380 The first part of this chapter introduces you to various terms that will
381 recur throughout the book. It also tells you who has worked on @GNUTAR{}
382 and its documentation, and where you should send bug reports
383 or comments.
384
385 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
386 gentle introduction for people who are new to using @command{tar}. It is
387 meant to be self contained, not requiring any reading from subsequent
388 chapters to make sense. It moves from topic to topic in a logical,
389 progressive order, building on information already explained.
390
391 Although the tutorial is paced and structured to allow beginners to
392 learn how to use @command{tar}, it is not intended solely for beginners.
393 The tutorial explains how to use the three most frequently used
394 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
395 two frequently used options (@samp{file} and @samp{verbose}). The other
396 chapters do not refer to the tutorial frequently; however, if a section
397 discusses something which is a complex variant of a basic concept, there
398 may be a cross reference to that basic concept. (The entire book,
399 including the tutorial, assumes that the reader understands some basic
400 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
401
402 The third chapter presents the remaining five operations, and
403 information about using @command{tar} options and option syntax.
404
405 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
406 than the reality. should think about whether this makes sense to say
407 here, or not.} The other chapters are meant to be used as a
408 reference. Each chapter presents everything that needs to be said
409 about a specific topic.
410
411 One of the chapters (@pxref{Date input formats}) exists in its
412 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
413 In addition, one section of this manual (@pxref{Standard}) contains a
414 big quote which is taken directly from @command{tar} sources.
415
416 In general, we give both long and short (abbreviated) option names
417 at least once in each section where the relevant option is covered, so
418 that novice readers will become familiar with both styles. (A few
419 options have no short versions, and the relevant sections will
420 indicate this.)
421
422 @node Definitions
423 @section Some Definitions
424
425 @cindex archive
426 @cindex tar archive
427 The @command{tar} program is used to create and manipulate @command{tar}
428 archives. An @dfn{archive} is a single file which contains the contents
429 of many files, while still identifying the names of the files, their
430 owner(s), and so forth. (In addition, archives record access
431 permissions, user and group, size in bytes, and data modification time.
432 Some archives also record the file names in each archived directory, as
433 well as other file and directory information.) You can use @command{tar}
434 to @dfn{create} a new archive in a specified directory.
435
436 @cindex member
437 @cindex archive member
438 @cindex file name
439 @cindex member name
440 The files inside an archive are called @dfn{members}. Within this
441 manual, we use the term @dfn{file} to refer only to files accessible in
442 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
443 @dfn{member} to refer only to the members of an archive. Similarly, a
444 @dfn{file name} is the name of a file, as it resides in the file system,
445 and a @dfn{member name} is the name of an archive member within the
446 archive.
447
448 @cindex extraction
449 @cindex unpacking
450 The term @dfn{extraction} refers to the process of copying an archive
451 member (or multiple members) into a file in the file system. Extracting
452 all the members of an archive is often called @dfn{extracting the
453 archive}. The term @dfn{unpack} can also be used to refer to the
454 extraction of many or all the members of an archive. Extracting an
455 archive does not destroy the archive's structure, just as creating an
456 archive does not destroy the copies of the files that exist outside of
457 the archive. You may also @dfn{list} the members in a given archive
458 (this is often thought of as ``printing'' them to the standard output,
459 or the command line), or @dfn{append} members to a pre-existing archive.
460 All of these operations can be performed using @command{tar}.
461
462 @node What tar Does
463 @section What @command{tar} Does
464
465 @cindex tar
466 The @command{tar} program provides the ability to create @command{tar}
467 archives, as well as various other kinds of manipulation. For example,
468 you can use @command{tar} on previously created archives to extract files,
469 to store additional files, or to update or list files which were already
470 stored.
471
472 Initially, @command{tar} archives were used to store files conveniently on
473 magnetic tape. The name @command{tar} comes from this use; it stands for
474 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
475 direct its output to available devices, files, or other programs (using
476 pipes). @command{tar} may even access remote devices or files (as archives).
477
478 You can use @command{tar} archives in many ways. We want to stress a few
479 of them: storage, backup, and transportation.
480
481 @FIXME{the following table entries need a bit of work..}
482 @table @asis
483 @item Storage
484 Often, @command{tar} archives are used to store related files for
485 convenient file transfer over a network. For example, the
486 @acronym{GNU} Project distributes its software bundled into
487 @command{tar} archives, so that all the files relating to a particular
488 program (or set of related programs) can be transferred as a single
489 unit.
490
491 A magnetic tape can store several files in sequence. However, the tape
492 has no names for these files; it only knows their relative position on
493 the tape. One way to store several files on one tape and retain their
494 names is by creating a @command{tar} archive. Even when the basic transfer
495 mechanism can keep track of names, as FTP can, the nuisance of handling
496 multiple files, directories, and multiple links makes @command{tar}
497 archives useful.
498
499 Archive files are also used for long-term storage. You can think of
500 this as transportation from the present into the future. (It is a
501 science-fiction idiom that you can move through time as well as in
502 space; the idea here is that @command{tar} can be used to move archives in
503 all dimensions, even time!)
504
505 @item Backup
506 Because the archive created by @command{tar} is capable of preserving
507 file information and directory structure, @command{tar} is commonly
508 used for performing full and incremental backups of disks. A backup
509 puts a collection of files (possibly pertaining to many users and
510 projects) together on a disk or a tape. This guards against
511 accidental destruction of the information in those files.
512 @GNUTAR{} has special features that allow it to be
513 used to make incremental and full dumps of all the files in a
514 file system.
515
516 @item Transportation
517 You can create an archive on one system, transfer it to another system,
518 and extract the contents there. This allows you to transport a group of
519 files from one system to another.
520 @end table
521
522 @node Naming tar Archives
523 @section How @command{tar} Archives are Named
524
525 Conventionally, @command{tar} archives are given names ending with
526 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
527 but this manual follows that convention in order to accustom readers to
528 it and to make examples more clear.
529
530 @cindex tar file
531 @cindex entry
532 @cindex tar entry
533 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
534 archive members as ``files'' or ``entries''. For people familiar with
535 the operation of @command{tar}, this causes no difficulty. However, in
536 this manual, we consistently refer to ``archives'' and ``archive
537 members'' to make learning to use @command{tar} easier for novice users.
538
539 @node Authors
540 @section @GNUTAR{} Authors
541
542 @GNUTAR{} was originally written by John Gilmore,
543 and modified by many people. The @acronym{GNU} enhancements were
544 written by Jay Fenlason, then Joy Kendall, and the whole package has
545 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
546 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
547 numerous and kind users.
548
549 We wish to stress that @command{tar} is a collective work, and owes much to
550 all those people who reported problems, offered solutions and other
551 insights, or shared their thoughts and suggestions. An impressive, yet
552 partial list of those contributors can be found in the @file{THANKS}
553 file from the @GNUTAR{} distribution.
554
555 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
556 sure i want to spell out the history in this detail, at least not for
557 the printed book. i'm just not sure it needs to be said this way.
558 i'll think about it.}
559
560 @FIXME{History is more important, and surely more interesting, than
561 actual names. Quoting names without history would be meaningless. FP}
562
563 Jay Fenlason put together a draft of a @GNUTAR{}
564 manual, borrowing notes from the original man page from John Gilmore.
565 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
566 Gorin worked on a tutorial and manual for @GNUTAR{}.
567 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
568 taking information from all these sources and merging them. Melissa
569 Weisshaus finally edited and redesigned the book to create version
570 1.12. @FIXME{update version number as necessary; i'm being
571 optimistic!} @FIXME{Someone [maybe karl berry? maybe bob chassell?
572 maybe melissa? maybe julie sussman?] needs to properly index the
573 thing.}
574
575 For version 1.12, Daniel Hagerty contributed a great deal of technical
576 consulting. In particular, he is the primary author of @ref{Backups}.
577
578 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
579 (see @url{http://savannah.gnu.org/projects/tar}), and
580 active development and maintenance work has started
581 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
582 Poznyakoff and Jeff Bailey.
583
584 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
585
586 @node Reports
587 @section Reporting bugs or suggestions
588
589 @cindex bug reports
590 @cindex reporting bugs
591 If you find problems or have suggestions about this program or manual,
592 please report them to @file{bug-tar@@gnu.org}.
593
594 When reporting a bug, please be sure to include as much detail as
595 possible, in order to reproduce it. @FIXME{Be more specific, I'd
596 like to make this node as detailed as 'Bug reporting' node in Emacs
597 manual}.
598
599 @node Tutorial
600 @chapter Tutorial Introduction to @command{tar}
601
602 This chapter guides you through some basic examples of three @command{tar}
603 operations: @option{--create}, @option{--list}, and @option{--extract}. If
604 you already know how to use some other version of @command{tar}, then you
605 may not need to read this chapter. This chapter omits most complicated
606 details about how @command{tar} works.
607
608 @menu
609 * assumptions::
610 * stylistic conventions::
611 * basic tar options:: Basic @command{tar} Operations and Options
612 * frequent operations::
613 * Two Frequent Options::
614 * create:: How to Create Archives
615 * list:: How to List Archives
616 * extract:: How to Extract Members from an Archive
617 * going further::
618 @end menu
619
620 @node assumptions
621 @section Assumptions this Tutorial Makes
622
623 This chapter is paced to allow beginners to learn about @command{tar}
624 slowly. At the same time, we will try to cover all the basic aspects of
625 these three operations. In order to accomplish both of these tasks, we
626 have made certain assumptions about your knowledge before reading this
627 manual, and the hardware you will be using:
628
629 @itemize @bullet
630 @item
631 Before you start to work through this tutorial, you should understand
632 what the terms ``archive'' and ``archive member'' mean
633 (@pxref{Definitions}). In addition, you should understand something
634 about how Unix-type operating systems work, and you should know how to
635 use some basic utilities. For example, you should know how to create,
636 list, copy, rename, edit, and delete files and directories; how to
637 change between directories; and how to figure out where you are in the
638 file system. You should have some basic understanding of directory
639 structure and how files are named according to which directory they are
640 in. You should understand concepts such as standard output and standard
641 input, what various definitions of the term ``argument'' mean, and the
642 differences between relative and absolute path names. @FIXME{and what
643 else?}
644
645 @item
646 This manual assumes that you are working from your own home directory
647 (unless we state otherwise). In this tutorial, you will create a
648 directory to practice @command{tar} commands in. When we show path names,
649 we will assume that those paths are relative to your home directory.
650 For example, my home directory path is @file{/home/fsf/melissa}. All of
651 my examples are in a subdirectory of the directory named by that path
652 name; the subdirectory is called @file{practice}.
653
654 @item
655 In general, we show examples of archives which exist on (or can be
656 written to, or worked with from) a directory on a hard disk. In most
657 cases, you could write those archives to, or work with them on any other
658 device, such as a tape drive. However, some of the later examples in
659 the tutorial and next chapter will not work on tape drives.
660 Additionally, working with tapes is much more complicated than working
661 with hard disks. For these reasons, the tutorial does not cover working
662 with tape drives. @xref{Media}, for complete information on using
663 @command{tar} archives with tape drives.
664
665 @FIXME{this is a cop out. need to add some simple tape drive info.}
666 @end itemize
667
668 @node stylistic conventions
669 @section Stylistic Conventions
670
671 In the examples, @samp{$} represents a typical shell prompt. It
672 precedes lines you should type; to make this more clear, those lines are
673 shown in @kbd{this font}, as opposed to lines which represent the
674 computer's response; those lines are shown in @code{this font}, or
675 sometimes @samp{like this}.
676
677 @c When we have lines which are too long to be
678 @c displayed in any other way, we will show them like this:
679
680 @node basic tar options
681 @section Basic @command{tar} Operations and Options
682
683 @command{tar} can take a wide variety of arguments which specify and define
684 the actions it will have on the particular set of files or the archive.
685 The main types of arguments to @command{tar} fall into one of two classes:
686 operations, and options.
687
688 Some arguments fall into a class called @dfn{operations}; exactly one of
689 these is both allowed and required for any instance of using @command{tar};
690 you may @emph{not} specify more than one. People sometimes speak of
691 @dfn{operating modes}. You are in a particular operating mode when you
692 have specified the operation which specifies it; there are eight
693 operations in total, and thus there are eight operating modes.
694
695 The other arguments fall into the class known as @dfn{options}. You are
696 not required to specify any options, and you are allowed to specify more
697 than one at a time (depending on the way you are using @command{tar} at
698 that time). Some options are used so frequently, and are so useful for
699 helping you type commands more carefully that they are effectively
700 ``required''. We will discuss them in this chapter.
701
702 You can write most of the @command{tar} operations and options in any
703 of three forms: long (mnemonic) form, short form, and old style. Some
704 of the operations and options have no short or ``old'' forms; however,
705 the operations and options which we will cover in this tutorial have
706 corresponding abbreviations. @FIXME{make sure this is still the case,
707 at the end}We will indicate those abbreviations appropriately to get
708 you used to seeing them. (Note that the ``old style'' option forms
709 exist in @GNUTAR{} for compatibility with Unix
710 @command{tar}. In this book we present a full discussion of this way
711 of writing options and operations (@pxref{Old Options}), and we discuss
712 the other two styles of writing options (@xref{Mnemonic Options}, and
713 @pxref{Short Options}).
714
715 In the examples and in the text of this tutorial, we usually use the
716 long forms of operations and options; but the ``short'' forms produce
717 the same result and can make typing long @command{tar} commands easier.
718 For example, instead of typing
719
720 @smallexample
721 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
722 @end smallexample
723
724 @noindent
725 you can type
726 @smallexample
727 @kbd{tar -c -v -f afiles.tar apple angst aspic}
728 @end smallexample
729
730 @noindent
731 or even
732 @smallexample
733 @kbd{tar -cvf afiles.tar apple angst aspic}
734 @end smallexample
735
736 @noindent
737 For more information on option syntax, see @ref{Advanced tar}. In
738 discussions in the text, when we name an option by its long form, we
739 also give the corresponding short option in parentheses.
740
741 The term, ``option'', can be confusing at times, since ``operations''
742 are often lumped in with the actual, @emph{optional} ``options'' in certain
743 general class statements. For example, we just talked about ``short and
744 long forms of options and operations''. However, experienced @command{tar}
745 users often refer to these by shorthand terms such as, ``short and long
746 options''. This term assumes that the ``operations'' are included, also.
747 Context will help you determine which definition of ``options'' to use.
748
749 Similarly, the term ``command'' can be confusing, as it is often used in
750 two different ways. People sometimes refer to @command{tar} ``commands''.
751 A @command{tar} @dfn{command} is the entire command line of user input
752 which tells @command{tar} what to do --- including the operation, options,
753 and any arguments (file names, pipes, other commands, etc). However,
754 you will also sometimes hear the term ``the @command{tar} command''. When
755 the word ``command'' is used specifically like this, a person is usually
756 referring to the @command{tar} @emph{operation}, not the whole line.
757 Again, use context to figure out which of the meanings the speaker
758 intends.
759
760 @node frequent operations
761 @section The Three Most Frequently Used Operations
762
763 Here are the three most frequently used operations (both short and long
764 forms), as well as a brief description of their meanings. The rest of
765 this chapter will cover how to use these operations in detail. We will
766 present the rest of the operations in the next chapter.
767
768 @table @option
769 @item --create
770 @itemx -c
771 Create a new @command{tar} archive.
772 @item --list
773 @itemx -t
774 List the contents of an archive.
775 @item --extract
776 @itemx -x
777 Extract one or more members from an archive.
778 @end table
779
780 @node Two Frequent Options
781 @section Two Frequently Used Options
782
783 To understand how to run @command{tar} in the three operating modes listed
784 previously, you also need to understand how to use two of the options to
785 @command{tar}: @option{--file} (which takes an archive file as an argument)
786 and @option{--verbose}. (You are usually not @emph{required} to specify
787 either of these options when you run @command{tar}, but they can be very
788 useful in making things more clear and helping you avoid errors.)
789
790 @menu
791 * file tutorial::
792 * verbose tutorial::
793 * help tutorial::
794 @end menu
795
796 @node file tutorial
797 @unnumberedsubsec The @option{--file} Option
798
799 @table @option
800 @opindex file, tutorial
801 @item --file=@var{archive-name}
802 @itemx -f @var{archive-name}
803 Specify the name of an archive file.
804 @end table
805
806 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
807 use @command{tar}; this option determines the name of the archive file
808 that @command{tar} will work on.
809
810 @vrindex TAPE
811 If you don't specify this argument, then @command{tar} will examine
812 the environment variable @env{TAPE}. If it is set, its value will be
813 used as the archive name. Otherwise, @command{tar} will use the
814 default archive, determined at the compile time. Usually it is
815 standard output or some physical tape drive attached to your machine
816 (you can verify what the default is by running @kbd{tar
817 --show-defaults}, @pxref{defaults}). If there is no tape drive
818 attached, or the default is not meaningful, then @command{tar} will
819 print an error message. The error message might look roughly like one
820 of the following:
821
822 @smallexample
823 tar: can't open /dev/rmt8 : No such device or address
824 tar: can't open /dev/rsmt0 : I/O error
825 @end smallexample
826
827 @noindent
828 To avoid confusion, we recommend that you always specify an archive file
829 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
830 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
831 @ref{file}.
832
833 @node verbose tutorial
834 @unnumberedsubsec The @option{--verbose} Option
835
836 @table @option
837 @opindex verbose, introduced
838 @item --verbose
839 @itemx -v
840 Show the files being worked on as @command{tar} is running.
841 @end table
842
843 @option{--verbose} (@option{-v}) shows details about the results of running
844 @command{tar}. This can be especially useful when the results might not be
845 obvious. For example, if you want to see the progress of @command{tar} as
846 it writes files into the archive, you can use the @option{--verbose}
847 option. In the beginning, you may find it useful to use
848 @option{--verbose} at all times; when you are more accustomed to
849 @command{tar}, you will likely want to use it at certain times but not at
850 others. We will use @option{--verbose} at times to help make something
851 clear, and we will give many examples both using and not using
852 @option{--verbose} to show the differences.
853
854 Sometimes, a single instance of @option{--verbose} on the command line
855 will show a full, @samp{ls} style listing of an archive or files,
856 giving sizes, owners, and similar information. @FIXME{Describe the
857 exact output format, e.g., how hard links are displayed.}
858 Other times, @option{--verbose} will only show files or members that the particular
859 operation is operating on at the time. In the latter case, you can
860 use @option{--verbose} twice in a command to get a listing such as that
861 in the former case. For example, instead of saying
862
863 @smallexample
864 @kbd{tar -cvf afiles.tar apple angst aspic}
865 @end smallexample
866
867 @noindent
868 above, you might say
869
870 @smallexample
871 @kbd{tar -cvvf afiles.tar apple angst aspic}
872 @end smallexample
873
874 @noindent
875 This works equally well using short or long forms of options. Using
876 long forms, you would simply write out the mnemonic form of the option
877 twice, like this:
878
879 @smallexample
880 $ @kbd{tar --create --verbose --verbose @dots{}}
881 @end smallexample
882
883 @noindent
884 Note that you must double the hyphens properly each time.
885
886 Later in the tutorial, we will give examples using @w{@option{--verbose
887 --verbose}}.
888
889 @node help tutorial
890 @unnumberedsubsec Getting Help: Using the @option{--help} Option
891
892 @table @option
893 @opindex help
894 @item --help
895
896 The @option{--help} option to @command{tar} prints out a very brief list of
897 all operations and option available for the current version of
898 @command{tar} available on your system.
899 @end table
900
901 @node create
902 @section How to Create Archives
903 @UNREVISED
904
905 @cindex Creation of the archive
906 @cindex Archive, creation of
907 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
908 you use to create a @command{tar} archive. We will explain
909 @option{--create} first because, in order to learn about the other
910 operations, you will find it useful to have an archive available to
911 practice on.
912
913 To make this easier, in this section you will first create a directory
914 containing three files. Then, we will show you how to create an
915 @emph{archive} (inside the new directory). Both the directory, and
916 the archive are specifically for you to practice on. The rest of this
917 chapter and the next chapter will show many examples using this
918 directory and the files you will create: some of those files may be
919 other directories and other archives.
920
921 The three files you will archive in this example are called
922 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
923 @file{collection.tar}.
924
925 This section will proceed slowly, detailing how to use @option{--create}
926 in @code{verbose} mode, and showing examples using both short and long
927 forms. In the rest of the tutorial, and in the examples in the next
928 chapter, we will proceed at a slightly quicker pace. This section
929 moves more slowly to allow beginning users to understand how
930 @command{tar} works.
931
932 @menu
933 * prepare for examples::
934 * Creating the archive::
935 * create verbose::
936 * short create::
937 * create dir::
938 @end menu
939
940 @node prepare for examples
941 @subsection Preparing a Practice Directory for Examples
942
943 To follow along with this and future examples, create a new directory
944 called @file{practice} containing files called @file{blues}, @file{folk}
945 and @file{jazz}. The files can contain any information you like:
946 ideally, they should contain information which relates to their names,
947 and be of different lengths. Our examples assume that @file{practice}
948 is a subdirectory of your home directory.
949
950 Now @command{cd} to the directory named @file{practice}; @file{practice}
951 is now your @dfn{working directory}. (@emph{Please note}: Although
952 the full path name of this directory is
953 @file{/@var{homedir}/practice}, in our examples we will refer to
954 this directory as @file{practice}; the @var{homedir} is presumed.
955
956 In general, you should check that the files to be archived exist where
957 you think they do (in the working directory) by running @command{ls}.
958 Because you just created the directory and the files and have changed to
959 that directory, you probably don't need to do that this time.
960
961 It is very important to make sure there isn't already a file in the
962 working directory with the archive name you intend to use (in this case,
963 @samp{collection.tar}), or that you don't care about its contents.
964 Whenever you use @samp{create}, @command{tar} will erase the current
965 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
966 will not tell you if you are about to overwrite an archive unless you
967 specify an option which does this (@pxref{backup}, for the
968 information on how to do so). To add files to an existing archive,
969 you need to use a different option, such as @option{--append} (@option{-r}); see
970 @ref{append} for information on how to do this.
971
972 @node Creating the archive
973 @subsection Creating the Archive
974
975 @opindex create, introduced
976 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
977 archive named @file{collection.tar}, use the following command:
978
979 @smallexample
980 $ @kbd{tar --create --file=collection.tar blues folk jazz}
981 @end smallexample
982
983 The order of the arguments is not very important, @emph{when using long
984 option forms}. You could also say:
985
986 @smallexample
987 $ @kbd{tar blues --create folk --file=collection.tar jazz}
988 @end smallexample
989
990 @noindent
991 However, you can see that this order is harder to understand; this is
992 why we will list the arguments in the order that makes the commands
993 easiest to understand (and we encourage you to do the same when you use
994 @command{tar}, to avoid errors).
995
996 Note that the part of the command which says,
997 @w{@option{--file=collection.tar}} is considered to be @emph{one} argument.
998 If you substituted any other string of characters for
999 @kbd{collection.tar}, then that string would become the name of the
1000 archive file you create.
1001
1002 The order of the options becomes more important when you begin to use
1003 short forms. With short forms, if you type commands in the wrong order
1004 (even if you type them correctly in all other ways), you may end up with
1005 results you don't expect. For this reason, it is a good idea to get
1006 into the habit of typing options in the order that makes inherent sense.
1007 @xref{short create}, for more information on this.
1008
1009 In this example, you type the command as shown above: @option{--create}
1010 is the operation which creates the new archive
1011 (@file{collection.tar}), and @option{--file} is the option which lets
1012 you give it the name you chose. The files, @file{blues}, @file{folk},
1013 and @file{jazz}, are now members of the archive, @file{collection.tar}
1014 (they are @dfn{file name arguments} to the @option{--create} operation).
1015 @FIXME{xref here to the discussion of file name args?}Now that they are
1016 in the archive, they are called @emph{archive members}, not files.
1017 (@pxref{Definitions,members}).
1018
1019 When you create an archive, you @emph{must} specify which files you
1020 want placed in the archive. If you do not specify any archive
1021 members, @GNUTAR{} will complain.
1022
1023 If you now list the contents of the working directory (@command{ls}), you will
1024 find the archive file listed as well as the files you saw previously:
1025
1026 @smallexample
1027 blues folk jazz collection.tar
1028 @end smallexample
1029
1030 @noindent
1031 Creating the archive @samp{collection.tar} did not destroy the copies of
1032 the files in the directory.
1033
1034 Keep in mind that if you don't indicate an operation, @command{tar} will not
1035 run and will prompt you for one. If you don't name any files, @command{tar}
1036 will complain. You must have write access to the working directory,
1037 or else you will not be able to create an archive in that directory.
1038
1039 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1040 an existing archive; it will delete the archive and write a new one.
1041 Use @option{--append} (@option{-r}) instead. @xref{append}.
1042
1043 @node create verbose
1044 @subsection Running @option{--create} with @option{--verbose}
1045
1046 @opindex create, using with @option{--verbose}
1047 @opindex verbose, using with @option{--create}
1048 If you include the @option{--verbose} (@option{-v}) option on the command line,
1049 @command{tar} will list the files it is acting on as it is working. In
1050 verbose mode, the @code{create} example above would appear as:
1051
1052 @smallexample
1053 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1054 blues
1055 folk
1056 jazz
1057 @end smallexample
1058
1059 This example is just like the example we showed which did not use
1060 @option{--verbose}, except that @command{tar} generated the remaining lines
1061 @iftex
1062 (note the different font styles).
1063 @end iftex
1064 @ifinfo
1065 .
1066 @end ifinfo
1067
1068 In the rest of the examples in this chapter, we will frequently use
1069 @code{verbose} mode so we can show actions or @command{tar} responses that
1070 you would otherwise not see, and which are important for you to
1071 understand.
1072
1073 @node short create
1074 @subsection Short Forms with @samp{create}
1075
1076 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1077 basic uses of @command{tar}, and you will use it countless times.
1078 Eventually, you will probably want to use abbreviated (or ``short'')
1079 forms of options. A full discussion of the three different forms that
1080 options can take appears in @ref{Styles}; for now, here is what the
1081 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1082 using short option forms:
1083
1084 @smallexample
1085 $ @kbd{tar -cvf collection.tar blues folk jazz}
1086 blues
1087 folk
1088 jazz
1089 @end smallexample
1090
1091 @noindent
1092 As you can see, the system responds the same no matter whether you use
1093 long or short option forms.
1094
1095 @FIXME{i don't like how this is worded:} One difference between using
1096 short and long option forms is that, although the exact placement of
1097 arguments following options is no more specific when using short forms,
1098 it is easier to become confused and make a mistake when using short
1099 forms. For example, suppose you attempted the above example in the
1100 following way:
1101
1102 @smallexample
1103 $ @kbd{tar -cfv collection.tar blues folk jazz}
1104 @end smallexample
1105
1106 @noindent
1107 In this case, @command{tar} will make an archive file called @file{v},
1108 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1109 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1110 is thus taken to be the chosen archive file name. @command{tar} will try
1111 to add a file called @file{collection.tar} to the @file{v} archive file;
1112 if the file @file{collection.tar} did not already exist, @command{tar} will
1113 report an error indicating that this file does not exist. If the file
1114 @file{collection.tar} does already exist (e.g., from a previous command
1115 you may have run), then @command{tar} will add this file to the archive.
1116 Because the @option{-v} option did not get registered, @command{tar} will not
1117 run under @samp{verbose} mode, and will not report its progress.
1118
1119 The end result is that you may be quite confused about what happened,
1120 and possibly overwrite a file. To illustrate this further, we will show
1121 you how an example we showed previously would look using short forms.
1122
1123 This example,
1124
1125 @smallexample
1126 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1127 @end smallexample
1128
1129 @noindent
1130 is confusing as it is. When shown using short forms, however, it
1131 becomes much more so:
1132
1133 @smallexample
1134 $ @kbd{tar blues -c folk -f collection.tar jazz}
1135 @end smallexample
1136
1137 @noindent
1138 It would be very easy to put the wrong string of characters
1139 immediately following the @option{-f}, but doing that could sacrifice
1140 valuable data.
1141
1142 For this reason, we recommend that you pay very careful attention to
1143 the order of options and placement of file and archive names,
1144 especially when using short option forms. Not having the option name
1145 written out mnemonically can affect how well you remember which option
1146 does what, and therefore where different names have to be placed.
1147
1148 @node create dir
1149 @subsection Archiving Directories
1150
1151 @cindex Archiving Directories
1152 @cindex Directories, Archiving
1153 You can archive a directory by specifying its directory name as a
1154 file name argument to @command{tar}. The files in the directory will be
1155 archived relative to the working directory, and the directory will be
1156 re-created along with its contents when the archive is extracted.
1157
1158 To archive a directory, first move to its superior directory. If you
1159 have followed the previous instructions in this tutorial, you should
1160 type:
1161
1162 @smallexample
1163 $ @kbd{cd ..}
1164 $
1165 @end smallexample
1166
1167 @noindent
1168 This will put you into the directory which contains @file{practice},
1169 i.e., your home directory. Once in the superior directory, you can
1170 specify the subdirectory, @file{practice}, as a file name argument. To
1171 store @file{practice} in the new archive file @file{music.tar}, type:
1172
1173 @smallexample
1174 $ @kbd{tar --create --verbose --file=music.tar practice}
1175 @end smallexample
1176
1177 @noindent
1178 @command{tar} should output:
1179
1180 @smallexample
1181 practice/
1182 practice/blues
1183 practice/folk
1184 practice/jazz
1185 practice/collection.tar
1186 @end smallexample
1187
1188 Note that the archive thus created is not in the subdirectory
1189 @file{practice}, but rather in the current working directory---the
1190 directory from which @command{tar} was invoked. Before trying to archive a
1191 directory from its superior directory, you should make sure you have
1192 write access to the superior directory itself, not only the directory
1193 you are trying archive with @command{tar}. For example, you will probably
1194 not be able to store your home directory in an archive by invoking
1195 @command{tar} from the root directory; @xref{absolute}. (Note
1196 also that @file{collection.tar}, the original archive file, has itself
1197 been archived. @command{tar} will accept any file as a file to be
1198 archived, regardless of its content. When @file{music.tar} is
1199 extracted, the archive file @file{collection.tar} will be re-written
1200 into the file system).
1201
1202 If you give @command{tar} a command such as
1203
1204 @smallexample
1205 $ @kbd{tar --create --file=foo.tar .}
1206 @end smallexample
1207
1208 @noindent
1209 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1210 dumped}. This happens because @command{tar} creates the archive
1211 @file{foo.tar} in the current directory before putting any files into
1212 it. Then, when @command{tar} attempts to add all the files in the
1213 directory @file{.} to the archive, it notices that the file
1214 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1215 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1216 will continue in this case, and create the archive
1217 normally, except for the exclusion of that one file. (@emph{Please
1218 note:} Other implementations of @command{tar} may not be so clever;
1219 they will enter an infinite loop when this happens, so you should not
1220 depend on this behavior unless you are certain you are running
1221 @GNUTAR{}. In general, it is wise to always place the archive outside
1222 of the directory being dumped.
1223
1224 @node list
1225 @section How to List Archives
1226
1227 @opindex list
1228 Frequently, you will find yourself wanting to determine exactly what a
1229 particular archive contains. You can use the @option{--list} (@option{-t}) operation
1230 to get the member names as they currently appear in the archive, as well
1231 as various attributes of the files at the time they were archived. For
1232 example, you can examine the archive @file{collection.tar} that you
1233 created in the last section with the command,
1234
1235 @smallexample
1236 $ @kbd{tar --list --file=collection.tar}
1237 @end smallexample
1238
1239 @noindent
1240 The output of @command{tar} would then be:
1241
1242 @smallexample
1243 blues
1244 folk
1245 jazz
1246 @end smallexample
1247
1248 @noindent
1249 The archive @file{bfiles.tar} would list as follows:
1250
1251 @smallexample
1252 ./birds
1253 baboon
1254 ./box
1255 @end smallexample
1256
1257 @noindent
1258 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1259 @var{archive-name}}) option just as with @option{--create}
1260 (@option{-c}) to specify the name of the archive.
1261
1262 @opindex list, using with @option{--verbose}
1263 @opindex verbose, using with @option{--list}
1264 If you use the @option{--verbose} (@option{-v}) option with
1265 @option{--list}, then @command{tar} will print out a listing
1266 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so forth.
1267
1268 If you had used @option{--verbose} (@option{-v}) mode, the example
1269 above would look like:
1270
1271 @smallexample
1272 $ @kbd{tar --list --verbose --file=collection.tar folk}
1273 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1274 @end smallexample
1275
1276 @cindex listing member and file names
1277 @anchor{listing member and file names}
1278 It is important to notice that the output of @kbd{tar --list
1279 --verbose} does not necessarily match that produced by @kbd{tar
1280 --create --verbose} while creating the archive. It is because
1281 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1282 prefixes from file names before storing them in the archive
1283 (@xref{absolute}, for more information). In other
1284 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1285 an archive and @dfn{member names} when listing it. Consider this
1286 example:
1287
1288 @smallexample
1289 @group
1290 $ @kbd{tar cfv archive /etc/mail}
1291 tar: Removing leading `/' from member names
1292 /etc/mail/
1293 /etc/mail/sendmail.cf
1294 /etc/mail/aliases
1295 $ @kbd{tar tf archive}
1296 etc/mail/
1297 etc/mail/sendmail.cf
1298 etc/mail/aliases
1299 @end group
1300 @end smallexample
1301
1302 @opindex show-stored-names
1303 This default behavior can sometimes be inconvenient. You can force
1304 @GNUTAR{} show member names when creating archive by supplying
1305 @option{--show-stored-names} option.
1306
1307 @table @option
1308 @item --show-stored-names
1309 Print member (as opposed to @emph{file}) names when creating the archive.
1310 @end table
1311
1312 @cindex File name arguments, using @option{--list} with
1313 @opindex list, using with file name arguments
1314 You can specify one or more individual member names as arguments when
1315 using @samp{list}. In this case, @command{tar} will only list the
1316 names of members you identify. For example, @w{@kbd{tar --list
1317 --file=afiles.tar apple}} would only print @file{apple}.
1318
1319 Because @command{tar} preserves paths, file names must be specified as
1320 they appear in the archive (ie., relative to the directory from which
1321 the archive was created). Therefore, it is essential when specifying
1322 member names to @command{tar} that you give the exact member names.
1323 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1324 error message something like @samp{tar: birds: Not found in archive},
1325 because there is no member named @file{birds}, only one named
1326 @file{./birds}. While the names @file{birds} and @file{./birds} name
1327 the same file, @emph{member} names by default are compared verbatim.
1328
1329 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1330 with @file{baboon}, because this exact member name is in the archive file
1331 @file{bfiles.tar}. If you are not sure of the exact file name,
1332 use @dfn{globbing patterns}, for example:
1333
1334 @smallexample
1335 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1336 @end smallexample
1337
1338 @noindent
1339 will list all members whose name contains @samp{b}. @xref{Wildcards},
1340 for a detailed discussion of globbing patterns and related
1341 @command{tar} command line options.
1342
1343 @menu
1344 * list dir::
1345 @end menu
1346
1347 @node list dir
1348 @unnumberedsubsec Listing the Contents of a Stored Directory
1349
1350 To get information about the contents of an archived directory,
1351 use the directory name as a file name argument in conjunction with
1352 @option{--list} (@option{-t}). To find out file attributes, include the
1353 @option{--verbose} (@option{-v}) option.
1354
1355 For example, to find out about files in the directory @file{practice}, in
1356 the archive file @file{music.tar}, type:
1357
1358 @smallexample
1359 $ @kbd{tar --list --verbose --file=music.tar practice}
1360 @end smallexample
1361
1362 @command{tar} responds:
1363
1364 @smallexample
1365 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1366 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1367 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1368 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1369 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1370 @end smallexample
1371
1372 When you use a directory name as a file name argument, @command{tar} acts on
1373 all the files (including sub-directories) in that directory.
1374
1375 @node extract
1376 @section How to Extract Members from an Archive
1377 @UNREVISED
1378 @cindex Extraction
1379 @cindex Retrieving files from an archive
1380 @cindex Resurrecting files from an archive
1381
1382 @opindex extract
1383 Creating an archive is only half the job---there is no point in storing
1384 files in an archive if you can't retrieve them. The act of retrieving
1385 members from an archive so they can be used and manipulated as
1386 unarchived files again is called @dfn{extraction}. To extract files
1387 from an archive, use the @option{--extract} (@option{--get} or
1388 @option{-x}) operation. As with @option{--create}, specify the name
1389 of the archive with @option{--file} (@option{-f}) option. Extracting
1390 an archive does not modify the archive in any way; you can extract it
1391 multiple times if you want or need to.
1392
1393 Using @option{--extract}, you can extract an entire archive, or specific
1394 files. The files can be directories containing other files, or not. As
1395 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1396 long form of the operation without affecting the performance.
1397
1398 @menu
1399 * extracting archives::
1400 * extracting files::
1401 * extract dir::
1402 * extracting untrusted archives::
1403 * failing commands::
1404 @end menu
1405
1406 @node extracting archives
1407 @subsection Extracting an Entire Archive
1408
1409 To extract an entire archive, specify the archive file name only, with
1410 no individual file names as arguments. For example,
1411
1412 @smallexample
1413 $ @kbd{tar -xvf collection.tar}
1414 @end smallexample
1415
1416 @noindent
1417 produces this:
1418
1419 @smallexample
1420 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1421 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1422 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1423 @end smallexample
1424
1425 @node extracting files
1426 @subsection Extracting Specific Files
1427
1428 To extract specific archive members, give their exact member names as
1429 arguments, as printed by @option{--list} (@option{-t}). If you had
1430 mistakenly deleted one of the files you had placed in the archive
1431 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1432 from the archive without changing the archive's structure. Its
1433 contents will be identical to the original file @file{blues} that you
1434 deleted.
1435
1436 First, make sure you are in the @file{practice} directory, and list the
1437 files in the directory. Now, delete the file, @samp{blues}, and list
1438 the files in the directory again.
1439
1440 You can now extract the member @file{blues} from the archive file
1441 @file{collection.tar} like this:
1442
1443 @smallexample
1444 $ @kbd{tar --extract --file=collection.tar blues}
1445 @end smallexample
1446
1447 @noindent
1448 If you list the files in the directory again, you will see that the file
1449 @file{blues} has been restored, with its original permissions, data
1450 modification times, and owner.@footnote{This is only accidentally
1451 true, but not in general. Whereas modification times are always
1452 restored, in most cases, one has to be root for restoring the owner,
1453 and use a special option for restoring permissions. Here, it just
1454 happens that the restoring user is also the owner of the archived
1455 members, and that the current @code{umask} is compatible with original
1456 permissions.} (These parameters will be identical to those which
1457 the file had when you originally placed it in the archive; any changes
1458 you may have made before deleting the file from the file system,
1459 however, will @emph{not} have been made to the archive member.) The
1460 archive file, @samp{collection.tar}, is the same as it was before you
1461 extracted @samp{blues}. You can confirm this by running @command{tar} with
1462 @option{--list} (@option{-t}).
1463
1464 Remember that as with other operations, specifying the exact member
1465 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1466 will fail, because there is no member named @file{birds}. To extract
1467 the member named @file{./birds}, you must specify @w{@kbd{tar
1468 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1469 exact member names, use @option{--list} (@option{-t}) option
1470 (@pxref{list}). You can also extract those members that match a
1471 specific @dfn{globbing pattern}. For example, to extract from
1472 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1473 directory prefix, you could type:
1474
1475 @smallexample
1476 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1477 @end smallexample
1478
1479 @noindent
1480 Here, @option{--wildcards} instructs @command{tar} to treat
1481 command line arguments as globbing patterns and @option{--no-anchored}
1482 informs it that the patterns apply to member names after any @samp{/}
1483 delimiter. The use of globbing patterns is discussed in detail in
1484 @xref{Wildcards}.
1485
1486 You can extract a file to standard output by combining the above options
1487 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1488 Output}).
1489
1490 If you give the @option{--verbose} option, then @option{--extract}
1491 will print the names of the archive members as it extracts them.
1492
1493 @node extract dir
1494 @subsection Extracting Files that are Directories
1495
1496 Extracting directories which are members of an archive is similar to
1497 extracting other files. The main difference to be aware of is that if
1498 the extracted directory has the same name as any directory already in
1499 the working directory, then files in the extracted directory will be
1500 placed into the directory of the same name. Likewise, if there are
1501 files in the pre-existing directory with the same names as the members
1502 which you extract, the files from the extracted archive will replace
1503 the files already in the working directory (and possible
1504 subdirectories). This will happen regardless of whether or not the
1505 files in the working directory were more recent than those extracted
1506 (there exist, however, special options that alter this behavior
1507 @pxref{Writing}).
1508
1509 However, if a file was stored with a directory name as part of its file
1510 name, and that directory does not exist under the working directory when
1511 the file is extracted, @command{tar} will create the directory.
1512
1513 We can demonstrate how to use @option{--extract} to extract a directory
1514 file with an example. Change to the @file{practice} directory if you
1515 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1516 go back to the parent directory and extract the archive
1517 @file{music.tar}. You may either extract the entire archive, or you may
1518 extract only the files you just deleted. To extract the entire archive,
1519 don't give any file names as arguments after the archive name
1520 @file{music.tar}. To extract only the files you deleted, use the
1521 following command:
1522
1523 @smallexample
1524 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1525 practice/folk
1526 practice/jazz
1527 @end smallexample
1528
1529 @noindent
1530 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1531 would have displayed more detail about the extracted files, as shown
1532 in the example below:
1533
1534 @smallexample
1535 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1536 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1537 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1538 @end smallexample
1539
1540 @noindent
1541 Because you created the directory with @file{practice} as part of the
1542 file names of each of the files by archiving the @file{practice}
1543 directory as @file{practice}, you must give @file{practice} as part
1544 of the file names when you extract those files from the archive.
1545
1546 @node extracting untrusted archives
1547 @subsection Extracting Archives from Untrusted Sources
1548
1549 Extracting files from archives can overwrite files that already exist.
1550 If you receive an archive from an untrusted source, you should make a
1551 new directory and extract into that directory, so that you don't have
1552 to worry about the extraction overwriting one of your existing files.
1553 For example, if @file{untrusted.tar} came from somewhere else on the
1554 Internet, and you don't necessarily trust its contents, you can
1555 extract it as follows:
1556
1557 @smallexample
1558 $ @kbd{mkdir newdir}
1559 $ @kbd{cd newdir}
1560 $ @kbd{tar -xvf ../untrusted.tar}
1561 @end smallexample
1562
1563 It is also a good practice to examine contents of the archive
1564 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1565 with @option{--verbose} (@option{-v}).
1566
1567 @node failing commands
1568 @subsection Commands That Will Fail
1569
1570 Here are some sample commands you might try which will not work, and why
1571 they won't work.
1572
1573 If you try to use this command,
1574
1575 @smallexample
1576 $ @kbd{tar -xvf music.tar folk jazz}
1577 @end smallexample
1578
1579 @noindent
1580 you will get the following response:
1581
1582 @smallexample
1583 tar: folk: Not found in archive
1584 tar: jazz: Not found in archive
1585 $
1586 @end smallexample
1587
1588 @noindent
1589 This is because these files were not originally @emph{in} the parent
1590 directory @file{..}, where the archive is located; they were in the
1591 @file{practice} directory, and their file names reflect this:
1592
1593 @smallexample
1594 $ @kbd{tar -tvf music.tar}
1595 practice/folk
1596 practice/jazz
1597 practice/rock
1598 @end smallexample
1599
1600 @FIXME{make sure the above works when going through the examples in
1601 order...}
1602
1603 @noindent
1604 Likewise, if you try to use this command,
1605
1606 @smallexample
1607 $ @kbd{tar -tvf music.tar folk jazz}
1608 @end smallexample
1609
1610 @noindent
1611 you would get a similar response. Members with those names are not in the
1612 archive. You must use the correct member names, or wildcards, in order
1613 to extract the files from the archive.
1614
1615 If you have forgotten the correct names of the files in the archive,
1616 use @w{@kbd{tar --list --verbose}} to list them correctly.
1617
1618 @FIXME{more examples, here? hag thinks it's a good idea.}
1619
1620 @node going further
1621 @section Going Further Ahead in this Manual
1622
1623 @FIXME{need to write up a node here about the things that are going to
1624 be in the rest of the manual.}
1625
1626 @node tar invocation
1627 @chapter Invoking @GNUTAR{}
1628 @UNREVISED
1629
1630 This chapter is about how one invokes the @GNUTAR{}
1631 command, from the command synopsis (@pxref{Synopsis}). There are
1632 numerous options, and many styles for writing them. One mandatory
1633 option specifies the operation @command{tar} should perform
1634 (@pxref{Operation Summary}), other options are meant to detail how
1635 this operation should be performed (@pxref{Option Summary}).
1636 Non-option arguments are not always interpreted the same way,
1637 depending on what the operation is.
1638
1639 You will find in this chapter everything about option styles and rules for
1640 writing them (@pxref{Styles}). On the other hand, operations and options
1641 are fully described elsewhere, in other chapters. Here, you will find
1642 only synthetic descriptions for operations and options, together with
1643 pointers to other parts of the @command{tar} manual.
1644
1645 Some options are so special they are fully described right in this
1646 chapter. They have the effect of inhibiting the normal operation of
1647 @command{tar} or else, they globally alter the amount of feedback the user
1648 receives about what is going on. These are the @option{--help} and
1649 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1650 and @option{--interactive} options (@pxref{interactive}).
1651
1652 @menu
1653 * Synopsis::
1654 * using tar options::
1655 * Styles::
1656 * All Options::
1657 * help::
1658 * defaults::
1659 * verbose::
1660 * interactive::
1661 @end menu
1662
1663 @node Synopsis
1664 @section General Synopsis of @command{tar}
1665
1666 The @GNUTAR{} program is invoked as either one of:
1667
1668 @smallexample
1669 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1670 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1671 @end smallexample
1672
1673 The second form is for when old options are being used.
1674
1675 You can use @command{tar} to store files in an archive, to extract them from
1676 an archive, and to do other types of archive manipulation. The primary
1677 argument to @command{tar}, which is called the @dfn{operation}, specifies
1678 which action to take. The other arguments to @command{tar} are either
1679 @dfn{options}, which change the way @command{tar} performs an operation,
1680 or file names or archive members, which specify the files or members
1681 @command{tar} is to act on.
1682
1683 You can actually type in arguments in any order, even if in this manual
1684 the options always precede the other arguments, to make examples easier
1685 to understand. Further, the option stating the main operation mode
1686 (the @command{tar} main command) is usually given first.
1687
1688 Each @var{name} in the synopsis above is interpreted as an archive member
1689 name when the main command is one of @option{--compare}
1690 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1691 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1692 @option{--update} (@option{-u}). When naming archive members, you
1693 must give the exact name of the member in the archive, as it is
1694 printed by @option{--list}. For @option{--append} (@option{-r}) and
1695 @option{--create} (@option{-c}), these @var{name} arguments specify
1696 the names of either files or directory hierarchies to place in the archive.
1697 These files or hierarchies should already exist in the file system,
1698 prior to the execution of the @command{tar} command.
1699
1700 @command{tar} interprets relative file names as being relative to the
1701 working directory. @command{tar} will make all file names relative
1702 (by removing leading slashes when archiving or restoring files),
1703 unless you specify otherwise (using the @option{--absolute-names}
1704 option). @xref{absolute}, for more information about
1705 @option{--absolute-names}.
1706
1707 If you give the name of a directory as either a file name or a member
1708 name, then @command{tar} acts recursively on all the files and directories
1709 beneath that directory. For example, the name @file{/} identifies all
1710 the files in the file system to @command{tar}.
1711
1712 The distinction between file names and archive member names is especially
1713 important when shell globbing is used, and sometimes a source of confusion
1714 for newcomers. @xref{Wildcards}, for more information about globbing.
1715 The problem is that shells may only glob using existing files in the
1716 file system. Only @command{tar} itself may glob on archive members, so when
1717 needed, you must ensure that wildcard characters reach @command{tar} without
1718 being interpreted by the shell first. Using a backslash before @samp{*}
1719 or @samp{?}, or putting the whole argument between quotes, is usually
1720 sufficient for this.
1721
1722 Even if @var{name}s are often specified on the command line, they
1723 can also be read from a text file in the file system, using the
1724 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1725
1726 If you don't use any file name arguments, @option{--append} (@option{-r}),
1727 @option{--delete} and @option{--concatenate} (@option{--catenate},
1728 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1729 will usually yield a diagnostic and inhibit @command{tar} execution.
1730 The other operations of @command{tar} (@option{--list},
1731 @option{--extract}, @option{--compare}, and @option{--update})
1732 will act on the entire contents of the archive.
1733
1734 @cindex exit status
1735 @cindex return status
1736 Besides successful exits, @GNUTAR{} may fail for
1737 many reasons. Some reasons correspond to bad usage, that is, when the
1738 @command{tar} command is improperly written. Errors may be
1739 encountered later, while encountering an error processing the archive
1740 or the files. Some errors are recoverable, in which case the failure
1741 is delayed until @command{tar} has completed all its work. Some
1742 errors are such that it would not meaningful, or at least risky, to
1743 continue processing: @command{tar} then aborts processing immediately.
1744 All abnormal exits, whether immediate or delayed, should always be
1745 clearly diagnosed on @code{stderr}, after a line stating the nature of
1746 the error.
1747
1748 @GNUTAR{} returns only a few exit statuses. I'm really
1749 aiming simplicity in that area, for now. If you are not using the
1750 @option{--compare} @option{--diff}, @option{-d}) option, zero means
1751 that everything went well, besides maybe innocuous warnings. Nonzero
1752 means that something went wrong. Right now, as of today, ``nonzero''
1753 is almost always 2, except for remote operations, where it may be
1754 128.
1755
1756 @node using tar options
1757 @section Using @command{tar} Options
1758
1759 @GNUTAR{} has a total of eight operating modes which
1760 allow you to perform a variety of tasks. You are required to choose
1761 one operating mode each time you employ the @command{tar} program by
1762 specifying one, and only one operation as an argument to the
1763 @command{tar} command (two lists of four operations each may be found
1764 at @ref{frequent operations} and @ref{Operations}). Depending on
1765 circumstances, you may also wish to customize how the chosen operating
1766 mode behaves. For example, you may wish to change the way the output
1767 looks, or the format of the files that you wish to archive may require
1768 you to do something special in order to make the archive look right.
1769
1770 You can customize and control @command{tar}'s performance by running
1771 @command{tar} with one or more options (such as @option{--verbose}
1772 (@option{-v}), which we used in the tutorial). As we said in the
1773 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1774 their name suggests) optional. Depending on the operating mode, you
1775 may specify one or more options. Different options will have different
1776 effects, but in general they all change details of the operation, such
1777 as archive format, archive name, or level of user interaction. Some
1778 options make sense with all operating modes, while others are
1779 meaningful only with particular modes. You will likely use some
1780 options frequently, while you will only use others infrequently, or
1781 not at all. (A full list of options is available in @pxref{All Options}.)
1782
1783 @vrindex TAR_OPTIONS, environment variable
1784 @anchor{TAR_OPTIONS}
1785 The @env{TAR_OPTIONS} environment variable specifies default options to
1786 be placed in front of any explicit options. For example, if
1787 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1788 if the two options @option{-v} and @option{--unlink-first} had been
1789 specified before any explicit options. Option specifications are
1790 separated by whitespace. A backslash escapes the next character, so it
1791 can be used to specify an option containing whitespace or a backslash.
1792
1793 Note that @command{tar} options are case sensitive. For example, the
1794 options @option{-T} and @option{-t} are different; the first requires an
1795 argument for stating the name of a file providing a list of @var{name}s,
1796 while the second does not require an argument and is another way to
1797 write @option{--list} (@option{-t}).
1798
1799 In addition to the eight operations, there are many options to
1800 @command{tar}, and three different styles for writing both: long (mnemonic)
1801 form, short form, and old style. These styles are discussed below.
1802 Both the options and the operations can be written in any of these three
1803 styles.
1804
1805 @FIXME{menu at end of this node. need to think of an actual outline
1806 for this chapter; probably do that after stuff from chapter 4 is
1807 incorporated.}
1808
1809 @node Styles
1810 @section The Three Option Styles
1811
1812 There are three styles for writing operations and options to the command
1813 line invoking @command{tar}. The different styles were developed at
1814 different times during the history of @command{tar}. These styles will be
1815 presented below, from the most recent to the oldest.
1816
1817 Some options must take an argument. (For example, @option{--file}
1818 (@option{-f})) takes the name of an archive file as an argument. If
1819 you do not supply an archive file name, @command{tar} will use a
1820 default, but this can be confusing; thus, we recommend that you always
1821 supply a specific archive file name.) Where you @emph{place} the
1822 arguments generally depends on which style of options you choose. We
1823 will detail specific information relevant to each option style in the
1824 sections on the different option styles, below. The differences are
1825 subtle, yet can often be very important; incorrect option placement
1826 can cause you to overwrite a number of important files. We urge you
1827 to note these differences, and only use the option style(s) which
1828 makes the most sense to you until you feel comfortable with the others.
1829
1830 Some options @emph{may} take an argument (currently, there are
1831 two such options: @option{--backup} and @option{--occurrence}). Such
1832 options may have at most long and short forms, they do not have old style
1833 equivalent. The rules for specifying an argument for such options
1834 are stricter than those for specifying mandatory arguments. Please,
1835 pay special attention to them.
1836
1837 @menu
1838 * Mnemonic Options:: Mnemonic Option Style
1839 * Short Options:: Short Option Style
1840 * Old Options:: Old Option Style
1841 * Mixing:: Mixing Option Styles
1842 @end menu
1843
1844 @node Mnemonic Options
1845 @subsection Mnemonic Option Style
1846
1847 @FIXME{have to decide whether or not to replace other occurrences of
1848 "mnemonic" with "long", or *ugh* vice versa.}
1849
1850 Each option has at least one long (or mnemonic) name starting with two
1851 dashes in a row, e.g., @option{--list}. The long names are more clear than
1852 their corresponding short or old names. It sometimes happens that a
1853 single mnemonic option has many different different names which are
1854 synonymous, such as @option{--compare} and @option{--diff}. In addition,
1855 long option names can be given unique abbreviations. For example,
1856 @option{--cre} can be used in place of @option{--create} because there is no
1857 other mnemonic option which begins with @samp{cre}. (One way to find
1858 this out is by trying it and seeing what happens; if a particular
1859 abbreviation could represent more than one option, @command{tar} will tell
1860 you that that abbreviation is ambiguous and you'll know that that
1861 abbreviation won't work. You may also choose to run @samp{tar --help}
1862 to see a list of options. Be aware that if you run @command{tar} with a
1863 unique abbreviation for the long name of an option you didn't want to
1864 use, you are stuck; @command{tar} will perform the command as ordered.)
1865
1866 Mnemonic options are meant to be obvious and easy to remember, and their
1867 meanings are generally easier to discern than those of their
1868 corresponding short options (see below). For example:
1869
1870 @smallexample
1871 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
1872 @end smallexample
1873
1874 @noindent
1875 gives a fairly good set of hints about what the command does, even
1876 for those not fully acquainted with @command{tar}.
1877
1878 Mnemonic options which require arguments take those arguments
1879 immediately following the option name. There are two ways of
1880 specifying a mandatory argument. It can be separated from the
1881 option name either by an equal sign, or by any amount of
1882 white space characters. For example, the @option{--file} option (which
1883 tells the name of the @command{tar} archive) is given a file such as
1884 @file{archive.tar} as argument by using any of the following notations:
1885 @option{--file=archive.tar} or @option{--file archive.tar}.
1886
1887 In contrast, optional arguments must always be introduced using
1888 an equal sign. For example, the @option{--backup} option takes
1889 an optional argument specifying backup type. It must be used
1890 as @option{--backup=@var{backup-type}}.
1891
1892 @node Short Options
1893 @subsection Short Option Style
1894
1895 Most options also have a short option name. Short options start with
1896 a single dash, and are followed by a single character, e.g., @option{-t}
1897 (which is equivalent to @option{--list}). The forms are absolutely
1898 identical in function; they are interchangeable.
1899
1900 The short option names are faster to type than long option names.
1901
1902 Short options which require arguments take their arguments immediately
1903 following the option, usually separated by white space. It is also
1904 possible to stick the argument right after the short option name, using
1905 no intervening space. For example, you might write @w{@option{-f
1906 archive.tar}} or @option{-farchive.tar} instead of using
1907 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
1908 @w{@option{-f @var{archive-name}}} denote the option which indicates a
1909 specific archive, here named @file{archive.tar}.
1910
1911 Short options which take optional arguments take their arguments
1912 immediately following the option letter, @emph{without any intervening
1913 white space characters}.
1914
1915 Short options' letters may be clumped together, but you are not
1916 required to do this (as compared to old options; see below). When
1917 short options are clumped as a set, use one (single) dash for them
1918 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
1919 such a set is allowed to have an argument@footnote{Clustering many
1920 options, the last of which has an argument, is a rather opaque way to
1921 write options. Some wonder if @acronym{GNU} @code{getopt} should not
1922 even be made helpful enough for considering such usages as invalid.}.
1923
1924 When the options are separated, the argument for each option which requires
1925 an argument directly follows that option, as is usual for Unix programs.
1926 For example:
1927
1928 @smallexample
1929 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
1930 @end smallexample
1931
1932 If you reorder short options' locations, be sure to move any arguments
1933 that belong to them. If you do not move the arguments properly, you may
1934 end up overwriting files.
1935
1936 @node Old Options
1937 @subsection Old Option Style
1938 @UNREVISED
1939
1940 Like short options, old options are single letters. However, old options
1941 must be written together as a single clumped set, without spaces separating
1942 them or dashes preceding them@footnote{Beware that if you precede options
1943 with a dash, you are announcing the short option style instead of the
1944 old option style; short options are decoded differently.}. This set
1945 of letters must be the first to appear on the command line, after the
1946 @command{tar} program name and some white space; old options cannot appear
1947 anywhere else. The letter of an old option is exactly the same letter as
1948 the corresponding short option. For example, the old option @samp{t} is
1949 the same as the short option @option{-t}, and consequently, the same as the
1950 mnemonic option @option{--list}. So for example, the command @w{@samp{tar
1951 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
1952
1953 When options that need arguments are given together with the command,
1954 all the associated arguments follow, in the same order as the options.
1955 Thus, the example given previously could also be written in the old
1956 style as follows:
1957
1958 @smallexample
1959 $ @kbd{tar cvbf 20 /dev/rmt0}
1960 @end smallexample
1961
1962 @noindent
1963 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
1964 the argument of @option{-f}.
1965
1966 On the other hand, this old style syntax makes it difficult to match
1967 option letters with their corresponding arguments, and is often
1968 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
1969 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
1970 argument for @option{-f}, and @option{-v} does not have a corresponding
1971 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
1972 /dev/rmt0}} is clearer, putting all arguments next to the option they
1973 pertain to.
1974
1975 If you want to reorder the letters in the old option argument, be
1976 sure to reorder any corresponding argument appropriately.
1977
1978 This old way of writing @command{tar} options can surprise even experienced
1979 users. For example, the two commands:
1980
1981 @smallexample
1982 @kbd{tar cfz archive.tar.gz file}
1983 @kbd{tar -cfz archive.tar.gz file}
1984 @end smallexample
1985
1986 @noindent
1987 are quite different. The first example uses @file{archive.tar.gz} as
1988 the value for option @samp{f} and recognizes the option @samp{z}. The
1989 second example, however, uses @file{z} as the value for option
1990 @samp{f} --- probably not what was intended.
1991
1992 Old options are kept for compatibility with old versions of @command{tar}.
1993
1994 This second example could be corrected in many ways, among which the
1995 following are equivalent:
1996
1997 @smallexample
1998 @kbd{tar -czf archive.tar.gz file}
1999 @kbd{tar -cf archive.tar.gz -z file}
2000 @kbd{tar cf archive.tar.gz -z file}
2001 @end smallexample
2002
2003 @cindex option syntax, traditional
2004 As far as we know, all @command{tar} programs, @acronym{GNU} and
2005 non-@acronym{GNU}, support old options. @GNUTAR{}
2006 supports them not only for historical reasons, but also because many
2007 people are used to them. For compatibility with Unix @command{tar},
2008 the first argument is always treated as containing command and option
2009 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2010 equivalent to @w{@samp{tar -c}:} both of them specify the
2011 @option{--create} (@option{-c}) command to create an archive.
2012
2013 @node Mixing
2014 @subsection Mixing Option Styles
2015
2016 All three styles may be intermixed in a single @command{tar} command,
2017 so long as the rules for each style are fully
2018 respected@footnote{Before @GNUTAR{} version 1.11.6,
2019 a bug prevented intermixing old style options with mnemonic options in
2020 some cases.}. Old style options and either of the modern styles of
2021 options may be mixed within a single @command{tar} command. However,
2022 old style options must be introduced as the first arguments only,
2023 following the rule for old options (old options must appear directly
2024 after the @command{tar} command and some white space). Modern options
2025 may be given only after all arguments to the old options have been
2026 collected. If this rule is not respected, a modern option might be
2027 falsely interpreted as the value of the argument to one of the old
2028 style options.
2029
2030 For example, all the following commands are wholly equivalent, and
2031 illustrate the many combinations and orderings of option styles.
2032
2033 @smallexample
2034 @kbd{tar --create --file=archive.tar}
2035 @kbd{tar --create -f archive.tar}
2036 @kbd{tar --create -farchive.tar}
2037 @kbd{tar --file=archive.tar --create}
2038 @kbd{tar --file=archive.tar -c}
2039 @kbd{tar -c --file=archive.tar}
2040 @kbd{tar -c -f archive.tar}
2041 @kbd{tar -c -farchive.tar}
2042 @kbd{tar -cf archive.tar}
2043 @kbd{tar -cfarchive.tar}
2044 @kbd{tar -f archive.tar --create}
2045 @kbd{tar -f archive.tar -c}
2046 @kbd{tar -farchive.tar --create}
2047 @kbd{tar -farchive.tar -c}
2048 @kbd{tar c --file=archive.tar}
2049 @kbd{tar c -f archive.tar}
2050 @kbd{tar c -farchive.tar}
2051 @kbd{tar cf archive.tar}
2052 @kbd{tar f archive.tar --create}
2053 @kbd{tar f archive.tar -c}
2054 @kbd{tar fc archive.tar}
2055 @end smallexample
2056
2057 On the other hand, the following commands are @emph{not} equivalent to
2058 the previous set:
2059
2060 @smallexample
2061 @kbd{tar -f -c archive.tar}
2062 @kbd{tar -fc archive.tar}
2063 @kbd{tar -fcarchive.tar}
2064 @kbd{tar -farchive.tarc}
2065 @kbd{tar cfarchive.tar}
2066 @end smallexample
2067
2068 @noindent
2069 These last examples mean something completely different from what the
2070 user intended (judging based on the example in the previous set which
2071 uses long options, whose intent is therefore very clear). The first
2072 four specify that the @command{tar} archive would be a file named
2073 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2074 respectively. The first two examples also specify a single non-option,
2075 @var{name} argument having the value @samp{archive.tar}. The last
2076 example contains only old style option letters (repeating option
2077 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2078 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2079 the first sentence of this paragraph..}
2080
2081 @node All Options
2082 @section All @command{tar} Options
2083
2084 The coming manual sections contain an alphabetical listing of all
2085 @command{tar} operations and options, with brief descriptions and cross
2086 references to more in-depth explanations in the body of the manual.
2087 They also contain an alphabetically arranged table of the short option
2088 forms with their corresponding long option. You can use this table as
2089 a reference for deciphering @command{tar} commands in scripts.
2090
2091 @menu
2092 * Operation Summary::
2093 * Option Summary::
2094 * Short Option Summary::
2095 @end menu
2096
2097 @node Operation Summary
2098 @subsection Operations
2099
2100 @table @option
2101
2102 @opindex append, summary
2103 @item --append
2104 @itemx -r
2105
2106 Appends files to the end of the archive. @xref{append}.
2107
2108 @opindex catenate, summary
2109 @item --catenate
2110 @itemx -A
2111
2112 Same as @option{--concatenate}. @xref{concatenate}.
2113
2114 @opindex compare, summary
2115 @item --compare
2116 @itemx -d
2117
2118 Compares archive members with their counterparts in the file
2119 system, and reports differences in file size, mode, owner,
2120 modification date and contents. @xref{compare}.
2121
2122 @opindex concatenate, summary
2123 @item --concatenate
2124 @itemx -A
2125
2126 Appends other @command{tar} archives to the end of the archive.
2127 @xref{concatenate}.
2128
2129 @opindex create, summary
2130 @item --create
2131 @itemx -c
2132
2133 Creates a new @command{tar} archive. @xref{create}.
2134
2135 @opindex delete, summary
2136 @item --delete
2137
2138 Deletes members from the archive. Don't try this on a archive on a
2139 tape! @xref{delete}.
2140
2141 @opindex diff, summary
2142 @item --diff
2143 @itemx -d
2144
2145 Same @option{--compare}. @xref{compare}.
2146
2147 @opindex extract, summary
2148 @item --extract
2149 @itemx -x
2150
2151 Extracts members from the archive into the file system. @xref{extract}.
2152
2153 @opindex get, summary
2154 @item --get
2155 @itemx -x
2156
2157 Same as @option{--extract}. @xref{extract}.
2158
2159 @opindex list, summary
2160 @item --list
2161 @itemx -t
2162
2163 Lists the members in an archive. @xref{list}.
2164
2165 @opindex update, summary
2166 @item --update
2167 @itemx -u
2168
2169 Adds files to the end of the archive, but only if they are newer than
2170 their counterparts already in the archive, or if they do not already
2171 exist in the archive. @xref{update}.
2172
2173 @end table
2174
2175 @node Option Summary
2176 @subsection @command{tar} Options
2177
2178 @table @option
2179
2180 @opindex absolute-names, summary
2181 @item --absolute-names
2182 @itemx -P
2183
2184 Normally when creating an archive, @command{tar} strips an initial
2185 @samp{/} from member names. This option disables that behavior.
2186 @xref{absolute}.
2187
2188 @opindex after-date, summary
2189 @item --after-date
2190
2191 (See @option{--newer}, @pxref{after})
2192
2193 @opindex anchored, summary
2194 @item --anchored
2195 A pattern must match an initial subsequence of the name's components.
2196 @xref{controlling pattern-matching}.
2197
2198 @opindex atime-preserve, summary
2199 @item --atime-preserve
2200 @itemx --atime-preserve=replace
2201 @itemx --atime-preserve=system
2202
2203 Attempt to preserve the access time of files when reading them. This
2204 option currently is effective only on files that you own, unless you
2205 have superuser privileges.
2206
2207 @option{--atime-preserve=replace} remembers the access time of a file
2208 before reading it, and then restores the access time afterwards. This
2209 may cause problems if other programs are reading the file at the same
2210 time, as the times of their accesses will be lost. On most platforms
2211 restoring the access time also requires @command{tar} to restore the
2212 data modification time too, so this option may also cause problems if
2213 other programs are writing the file at the same time. (Tar attempts
2214 to detect this situation, but cannot do so reliably due to race
2215 conditions.) Worse, on most platforms restoring the access time also
2216 updates the status change time, which means that this option is
2217 incompatible with incremental backups.
2218
2219 @option{--atime-preserve=system} avoids changing time stamps on files,
2220 without interfering with time stamp updates
2221 caused by other programs, so it works better with incremental backups.
2222 However, it requires a special @code{O_NOATIME} option from the
2223 underlying operating and file system implementation, and it also requires
2224 that searching directories does not update their access times. As of
2225 this writing (November 2005) this works only with Linux, and only with
2226 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2227 way to know whether this feature actually works. Sometimes
2228 @command{tar} knows that it does not work, and if you use
2229 @option{--atime-preserve=system} then @command{tar} complains and
2230 exits right away. But other times @command{tar} might think that the
2231 option works when it actually does not.
2232
2233 Currently @option{--atime-preserve} with no operand defaults to
2234 @option{--atime-preserve=replace}, but this may change in the future
2235 as support for @option{--atime-preserve=system} improves.
2236
2237 If your operating system does not support
2238 @option{--atime-preserve=system}, you might be able to preserve access
2239 times reliably by by using the @command{mount} command. For example,
2240 you can mount the file system read-only, or access the file system via
2241 a read-only loopback mount, or use the @samp{noatime} mount option
2242 available on some systems. However, mounting typically requires
2243 superuser privileges and can be a pain to manage.
2244
2245 @opindex backup, summary
2246 @item --backup=@var{backup-type}
2247
2248 Rather than deleting files from the file system, @command{tar} will
2249 back them up using simple or numbered backups, depending upon
2250 @var{backup-type}. @xref{backup}.
2251
2252 @opindex block-number, summary
2253 @item --block-number
2254 @itemx -R
2255
2256 With this option present, @command{tar} prints error messages for read errors
2257 with the block number in the archive file. @xref{block-number}.
2258
2259 @opindex blocking-factor, summary
2260 @item --blocking-factor=@var{blocking}
2261 @itemx -b @var{blocking}
2262
2263 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2264 record. @xref{Blocking Factor}.
2265
2266 @opindex bzip2, summary
2267 @item --bzip2
2268 @itemx -j
2269
2270 This option tells @command{tar} to read or write archives through
2271 @code{bzip2}. @xref{gzip}.
2272
2273 @opindex checkpoint, summary
2274 @item --checkpoint
2275
2276 This option directs @command{tar} to print periodic checkpoint messages as it
2277 reads through the archive. It is intended for when you want a visual
2278 indication that @command{tar} is still running, but don't want to see
2279 @option{--verbose} output. @FIXME-xref{}
2280
2281 @opindex check-links, summary
2282 @item --check-links
2283 @itemx -l
2284 If this option was given, @command{tar} will check the number of links
2285 dumped for each processed file. If this number does not match the
2286 total number of hard links for the file, a warning message will be
2287 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2288 synonym for @option{--one-file-system}. The current semantics, wich
2289 complies to UNIX98, was introduced with version
2290 1.15.91. @xref{Changes}, for more information.}.
2291
2292 @opindex compress, summary
2293 @opindex uncompress, summary
2294 @item --compress
2295 @itemx --uncompress
2296 @itemx -Z
2297
2298 @command{tar} will use the @command{compress} program when reading or
2299 writing the archive. This allows you to directly act on archives
2300 while saving space. @xref{gzip}.
2301
2302 @opindex confirmation, summary
2303 @item --confirmation
2304
2305 (See @option{--interactive}.) @xref{interactive}.
2306
2307 @opindex delay-directory-restore, summary
2308 @item --delay-directory-restore
2309
2310 Delay setting modification times and permissions of extracted
2311 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2312
2313 @opindex dereference, summary
2314 @item --dereference
2315 @itemx -h
2316
2317 When creating a @command{tar} archive, @command{tar} will archive the
2318 file that a symbolic link points to, rather than archiving the
2319 symlink. @xref{dereference}.
2320
2321 @opindex directory, summary
2322 @item --directory=@var{dir}
2323 @itemx -C @var{dir}
2324
2325 When this option is specified, @command{tar} will change its current directory
2326 to @var{dir} before performing any operations. When this option is used
2327 during archive creation, it is order sensitive. @xref{directory}.
2328
2329 @opindex exclude, summary
2330 @item --exclude=@var{pattern}
2331
2332 When performing operations, @command{tar} will skip files that match
2333 @var{pattern}. @xref{exclude}.
2334
2335 @opindex exclude-from, summary
2336 @item --exclude-from=@var{file}
2337 @itemx -X @var{file}
2338
2339 Similar to @option{--exclude}, except @command{tar} will use the list of
2340 patterns in the file @var{file}. @xref{exclude}.
2341
2342 @opindex exclude-caches, summary
2343 @item --exclude-caches
2344
2345 Automatically excludes all directories
2346 containing a cache directory tag. @xref{exclude}.
2347
2348 @opindex file, summary
2349 @item --file=@var{archive}
2350 @itemx -f @var{archive}
2351
2352 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2353 performs operations on, rather than @command{tar}'s compilation dependent
2354 default. @xref{file tutorial}.
2355
2356 @opindex files-from, summary
2357 @item --files-from=@var{file}
2358 @itemx -T @var{file}
2359
2360 @command{tar} will use the contents of @var{file} as a list of archive members
2361 or files to operate on, in addition to those specified on the
2362 command-line. @xref{files}.
2363
2364 @opindex force-local, summary
2365 @item --force-local
2366
2367 Forces @command{tar} to interpret the filename given to @option{--file}
2368 as a local file, even if it looks like a remote tape drive name.
2369 @xref{local and remote archives}.
2370
2371 @opindex format, summary
2372 @item --format=@var{format}
2373
2374 Selects output archive format. @var{Format} may be one of the
2375 following:
2376
2377 @table @samp
2378 @item v7
2379 Creates an archive that is compatible with Unix V7 @command{tar}.
2380
2381 @item oldgnu
2382 Creates an archive that is compatible with GNU @command{tar} version
2383 1.12 or earlier.
2384
2385 @item gnu
2386 Creates archive in GNU tar 1.13 format. Basically it is the same as
2387 @samp{oldgnu} with the only difference in the way it handles long
2388 numeric fields.
2389
2390 @item ustar
2391 Creates a @acronym{POSIX.1-1988} compatible archive.
2392
2393 @item posix
2394 Creates a @acronym{POSIX.1-2001 archive}.
2395
2396 @end table
2397
2398 @xref{Formats}, for a detailed discussion of these formats.
2399
2400 @opindex group, summary
2401 @item --group=@var{group}
2402
2403 Files added to the @command{tar} archive will have a group id of @var{group},
2404 rather than the group from the source file. @var{group} is first decoded
2405 as a group symbolic name, but if this interpretation fails, it has to be
2406 a decimal numeric group ID. @FIXME-xref{}
2407
2408 Also see the comments for the @option{--owner=@var{user}} option.
2409
2410 @opindex gzip, summary
2411 @opindex gunzip, summary
2412 @opindex ungzip, summary
2413 @item --gzip
2414 @itemx --gunzip
2415 @itemx --ungzip
2416 @itemx -z
2417
2418 This option tells @command{tar} to read or write archives through
2419 @command{gzip}, allowing @command{tar} to directly operate on several
2420 kinds of compressed archives transparently. @xref{gzip}.
2421
2422 @opindex help, summary
2423 @item --help
2424
2425 @command{tar} will print out a short message summarizing the operations and
2426 options to @command{tar} and exit. @xref{help}.
2427
2428 @opindex ignore-case, summary
2429 @item --ignore-case
2430 Ignore case when matching member or file names with
2431 patterns. @xref{controlling pattern-matching}.
2432
2433 @opindex ignore-command-error, summary
2434 @item --ignore-command-error
2435 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2436
2437 @opindex ignore-failed-read, summary
2438 @item --ignore-failed-read
2439
2440 Do not exit unsuccessfully merely because an unreadable file was encountered.
2441 @xref{Reading}.
2442
2443 @opindex ignore-zeros, summary
2444 @item --ignore-zeros
2445 @itemx -i
2446
2447 With this option, @command{tar} will ignore zeroed blocks in the
2448 archive, which normally signals EOF. @xref{Reading}.
2449
2450 @opindex incremental, summary
2451 @item --incremental
2452 @itemx -G
2453
2454 Used to inform @command{tar} that it is working with an old
2455 @acronym{GNU}-format incremental backup archive. It is intended
2456 primarily for backwards compatibility only. @xref{Incremental Dumps},
2457 for a detailed discussion of incremental archives.
2458
2459 @opindex index-file, summary
2460 @item --index-file=@var{file}
2461
2462 Send verbose output to @var{file} instead of to standard output.
2463
2464 @opindex info-script, summary
2465 @opindex new-volume-script, summary
2466 @item --info-script=@var{script-file}
2467 @itemx --new-volume-script=@var{script-file}
2468 @itemx -F @var{script-file}
2469
2470 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2471 at the end of each tape. If @var{script-file} exits with nonzero status,
2472 @command{tar} fails immediately. @xref{info-script}, for a detailed
2473 discussion of @var{script-file}.
2474
2475 @opindex interactive, summary
2476 @item --interactive
2477 @itemx --confirmation
2478 @itemx -w
2479
2480 Specifies that @command{tar} should ask the user for confirmation before
2481 performing potentially destructive options, such as overwriting files.
2482 @xref{interactive}.
2483
2484 @opindex keep-newer-files, summary
2485 @item --keep-newer-files
2486
2487 Do not replace existing files that are newer than their archive copies
2488 when extracting files from an archive.
2489
2490 @opindex keep-old-files, summary
2491 @item --keep-old-files
2492 @itemx -k
2493
2494 Do not overwrite existing files when extracting files from an archive.
2495 @xref{Keep Old Files}.
2496
2497 @opindex label, summary
2498 @item --label=@var{name}
2499 @itemx -V @var{name}
2500
2501 When creating an archive, instructs @command{tar} to write @var{name}
2502 as a name record in the archive. When extracting or listing archives,
2503 @command{tar} will only operate on archives that have a label matching
2504 the pattern specified in @var{name}. @xref{Tape Files}.
2505
2506 @opindex listed-incremental, summary
2507 @item --listed-incremental=@var{snapshot-file}
2508 @itemx -g @var{snapshot-file}
2509
2510 During a @option{--create} operation, specifies that the archive that
2511 @command{tar} creates is a new @acronym{GNU}-format incremental
2512 backup, using @var{snapshot-file} to determine which files to backup.
2513 With other operations, informs @command{tar} that the archive is in
2514 incremental format. @xref{Incremental Dumps}.
2515
2516 @opindex mode, summary
2517 @item --mode=@var{permissions}
2518
2519 When adding files to an archive, @command{tar} will use
2520 @var{permissions} for the archive members, rather than the permissions
2521 from the files. The program @command{chmod} and this @command{tar}
2522 option share the same syntax for what @var{permissions} might be.
2523 @xref{File permissions, Permissions, File permissions, fileutils,
2524 @acronym{GNU} file utilities}. This reference also has useful
2525 information for those not being overly familiar with the Unix
2526 permission system.
2527
2528 Of course, @var{permissions} might be plainly specified as an octal number.
2529 However, by using generic symbolic modifications to mode bits, this allows
2530 more flexibility. For example, the value @samp{a+rw} adds read and write
2531 permissions for everybody, while retaining executable bits on directories
2532 or on any other file already marked as executable.
2533
2534 @opindex multi-volume, summary
2535 @item --multi-volume
2536 @itemx -M
2537
2538 Informs @command{tar} that it should create or otherwise operate on a
2539 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2540
2541 @opindex new-volume-script, summary
2542 @item --new-volume-script
2543
2544 (see --info-script)
2545
2546 @opindex seek, summary
2547 @item --seek
2548 @itemx -n
2549
2550 Assume that the archive media supports seeks to arbitrary
2551 locations. Usually @command{tar} determines automatically whether
2552 the archive can be seeked or not. This option is intended for use
2553 in cases when such recognition fails.
2554
2555 @opindex newer, summary
2556 @item --newer=@var{date}
2557 @itemx --after-date=@var{date}
2558 @itemx -N
2559
2560 When creating an archive, @command{tar} will only add files that have changed
2561 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2562 is taken to be the name of a file whose data modification time specifies
2563 the date. @xref{after}.
2564
2565 @opindex newer-mtime, summary
2566 @item --newer-mtime=@var{date}
2567
2568 Like @option{--newer}, but add only files whose
2569 contents have changed (as opposed to just @option{--newer}, which will
2570 also back up files for which any status information has changed).
2571
2572 @opindex no-anchored, summary
2573 @item --no-anchored
2574 An exclude pattern can match any subsequence of the name's components.
2575 @xref{controlling pattern-matching}.
2576
2577 @opindex no-delay-directory-restore, summary
2578 @item --no-delay-directory-restore
2579
2580 Setting modification times and permissions of extracted
2581 directories when all files from this directory has been
2582 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2583
2584 @opindex no-ignore-case, summary
2585 @item --no-ignore-case
2586 Use case-sensitive matching.
2587 @xref{controlling pattern-matching}.
2588
2589 @opindex no-ignore-command-error, summary
2590 @item --no-ignore-command-error
2591 Print warnings about subprocesses terminated with a non-zero exit
2592 code. @xref{Writing to an External Program}.
2593
2594 @opindex no-quote-chars, summary
2595 @item --no-quote-chars=@var{string}
2596 Remove characters listed in @var{string} from the list of quoted
2597 characters set by the previous @option{--quote-chars} option
2598 (@pxref{quoting styles}).
2599
2600 @opindex no-recursion, summary
2601 @item --no-recursion
2602
2603 With this option, @command{tar} will not recurse into directories.
2604 @xref{recurse}.
2605
2606 @opindex no-same-owner, summary
2607 @item --no-same-owner
2608 @itemx -o
2609
2610 When extracting an archive, do not attempt to preserve the owner
2611 specified in the @command{tar} archive. This the default behavior
2612 for ordinary users.
2613
2614 @opindex no-same-permissions, summary
2615 @item --no-same-permissions
2616
2617 When extracting an archive, subtract the user's umask from files from
2618 the permissions specified in the archive. This is the default behavior
2619 for ordinary users.
2620
2621 @opindex no-wildcards, summary
2622 @item --no-wildcards
2623 Do not use wildcards.
2624 @xref{controlling pattern-matching}.
2625
2626 @opindex no-wildcards-match-slash, summary
2627 @item --no-wildcards-match-slash
2628 Wildcards do not match @samp{/}.
2629 @xref{controlling pattern-matching}.
2630
2631 @opindex null, summary
2632 @item --null
2633
2634 When @command{tar} is using the @option{--files-from} option, this option
2635 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2636 @command{tar} can correctly work with file names that contain newlines.
2637 @xref{nul}.
2638
2639 @opindex numeric-owner, summary
2640 @item --numeric-owner
2641
2642 This option will notify @command{tar} that it should use numeric user
2643 and group IDs when creating a @command{tar} file, rather than names.
2644 @xref{Attributes}.
2645
2646 @item -o
2647 When extracting files, this option is a synonym for
2648 @option{--no-same-owner}, i.e. it prevents @command{tar} from
2649 restoring ownership of files being extracted.
2650
2651 When creating an archive, @option{-o} is a synonym for
2652 @option{--old-archive}. This behavior is for compatibility
2653 with previous versions of @GNUTAR{}, and will be
2654 removed in the future releases.
2655
2656 @xref{Changes}, for more information.
2657
2658 @opindex occurrence, summary
2659 @item --occurrence[=@var{number}]
2660
2661 This option can be used in conjunction with one of the subcommands
2662 @option{--delete}, @option{--diff}, @option{--extract} or
2663 @option{--list} when a list of files is given either on the command
2664 line or via @option{-T} option.
2665
2666 This option instructs @command{tar} to process only the @var{number}th
2667 occurrence of each named file. @var{Number} defaults to 1, so
2668
2669 @smallexample
2670 tar -x -f archive.tar --occurrence filename
2671 @end smallexample
2672
2673 @noindent
2674 will extract the first occurrence of @file{filename} from @file{archive.tar}
2675 and will terminate without scanning to the end of the archive.
2676
2677 @opindex old-archive, summary
2678 @item --old-archive
2679 Synonym for @option{--format=v7}.
2680
2681 @opindex one-file-system, summary
2682 @item --one-file-system
2683 Used when creating an archive. Prevents @command{tar} from recursing into
2684 directories that are on different file systems from the current
2685 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2686 synonym for @option{--one-file-system}. This has changed in version
2687 1.15.91. @xref{Changes}, for more information.}.
2688
2689 @opindex overwrite, summary
2690 @item --overwrite
2691
2692 Overwrite existing files and directory metadata when extracting files
2693 from an archive. @xref{Overwrite Old Files}.
2694
2695 @opindex overwrite-dir, summary
2696 @item --overwrite-dir
2697
2698 Overwrite the metadata of existing directories when extracting files
2699 from an archive. @xref{Overwrite Old Files}.
2700
2701 @opindex owner, summary
2702 @item --owner=@var{user}
2703
2704 Specifies that @command{tar} should use @var{user} as the owner of members
2705 when creating archives, instead of the user associated with the source
2706 file. @var{user} is first decoded as a user symbolic name, but if
2707 this interpretation fails, it has to be a decimal numeric user ID.
2708 @FIXME-xref{}
2709
2710 There is no value indicating a missing number, and @samp{0} usually means
2711 @code{root}. Some people like to force @samp{0} as the value to offer in
2712 their distributions for the owner of files, because the @code{root} user is
2713 anonymous anyway, so that might as well be the owner of anonymous archives.
2714
2715 This option does not affect extraction from archives.
2716
2717 @opindex transform, summary
2718 @item --transform=@var{sed-expr}
2719
2720 Transform file or member names using @command{sed} replacement expression
2721 @var{sed-expr}. For example,
2722
2723 @smallexample
2724 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2725 @end smallexample
2726
2727 @noindent
2728 will add to @file{archive} files from the current working directory,
2729 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2730 discussion, see @FIXME-xref{transform}
2731
2732 To see transformed member names in verbose listings, use
2733 @option{--show-transformed-names} option
2734 (@FIXME-pxref{show-transformed-names}).
2735
2736 @opindex quote-chars, summary
2737 @item --quote-chars=@var{string}
2738 Always quote characters from @var{string}, even if the selected
2739 quoting style would not quote them (@pxref{quoting styles}).
2740
2741 @opindex quoting-style, summary
2742 @item --quoting-style=@var{style}
2743 Set quoting style to use when printing member and file names
2744 (@pxref{quoting styles}). Valid @var{style} values are:
2745 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2746 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2747 style is @code{escape}, unless overridden while configuring the
2748 package.
2749
2750 @opindex pax-option, summary
2751 @item --pax-option=@var{keyword-list}
2752 @FIXME{Such a detailed description does not belong there, move it elsewhere.}
2753 This option is meaningful only with @acronym{POSIX.1-2001} archives
2754 (@pxref{posix}). It modifies the way @command{tar} handles the
2755 extended header keywords. @var{Keyword-list} is a comma-separated
2756 list of keyword options, each keyword option taking one of
2757 the following forms:
2758
2759 @table @asis
2760 @item delete=@var{pattern}
2761 When used with one of archive-creation commands,
2762 this option instructs @command{tar} to omit from extended header records
2763 that it produces any keywords matching the string @var{pattern}.
2764
2765 When used in extract or list mode, this option instructs tar
2766 to ignore any keywords matching the given @var{pattern} in the extended
2767 header records. In both cases, matching is performed using the pattern
2768 matching notation described in @acronym{POSIX 1003.2}, 3.13
2769 (See @cite{glob(7)}). For example:
2770
2771 @smallexample
2772 --pax-option delete=security.*
2773 @end smallexample
2774
2775 would suppress security-related information.
2776
2777 @item exthdr.name=@var{string}
2778
2779 This keyword allows user control over the name that is written into the
2780 ustar header blocks for the extended headers. The name is obtained
2781 from @var{string} after making the following substitutions:
2782
2783 @multitable @columnfractions .30 .70
2784 @headitem Meta-character @tab Replaced By
2785 @item %d @tab The directory name of the file, equivalent to the
2786 result of the @command{dirname} utility on the translated pathname.
2787 @item %f @tab The filename of the file, equivalent to the result
2788 of the @command{basename} utility on the translated pathname.
2789 @item %p @tab The process ID of the @command{tar} process.
2790 @item %% @tab A @samp{%} character.
2791 @end multitable
2792
2793 Any other @samp{%} characters in @var{string} produce undefined
2794 results.
2795
2796 If no option @samp{exthdr.name=string} is specified, @command{tar}
2797 will use the following default value:
2798
2799 @smallexample
2800 %d/PaxHeaders.%p/%f
2801 @end smallexample
2802
2803 @item globexthdr.name=@var{string}
2804 This keyword allows user control over the name that is written into
2805 the ustar header blocks for global extended header records. The name
2806 is obtained from the contents of @var{string}, after making
2807 the following substitutions:
2808
2809 @multitable @columnfractions .30 .70
2810 @headitem Meta-character @tab Replaced By
2811 @item %n @tab An integer that represents the
2812 sequence number of the global extended header record in the archive,
2813 starting at 1.
2814 @item %p @tab The process ID of the @command{tar} process.
2815 @item %% @tab A @samp{%} character.
2816 @end multitable
2817
2818 Any other @samp{%} characters in @var{string} produce undefined results.
2819
2820 If no option @samp{globexthdr.name=string} is specified, @command{tar}
2821 will use the following default value:
2822
2823 @smallexample
2824 $TMPDIR/GlobalHead.%p.%n
2825 @end smallexample
2826
2827 @noindent
2828 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
2829 environment variable. If @var{TMPDIR} is not set, @command{tar}
2830 uses @samp{/tmp}.
2831
2832 @item @var{keyword}=@var{value}
2833 When used with one of archive-creation commands, these keyword/value pairs
2834 will be included at the beginning of the archive in a global extended
2835 header record. When used with one of archive-reading commands,
2836 @command{tar} will behave as if it has encountered these keyword/value
2837 pairs at the beginning of the archive in a global extended header
2838 record.
2839
2840 @item @var{keyword}:=@var{value}
2841 When used with one of archive-creation commands, these keyword/value pairs
2842 will be included as records at the beginning of an extended header for
2843 each file. This is effectively equivalent to @var{keyword}=@var{value}
2844 form except that it creates no global extended header records.
2845
2846 When used with one of archive-reading commands, @command{tar} will
2847 behave as if these keyword/value pairs were included as records at the
2848 end of each extended header; thus, they will override any global or
2849 file-specific extended header record keywords of the same names.
2850 For example, in the command:
2851
2852 @smallexample
2853 tar --format=posix --create \
2854 --file archive --pax-option gname:=user .
2855 @end smallexample
2856
2857 the group name will be forced to a new value for all files
2858 stored in the archive.
2859 @end table
2860
2861 @opindex portability, summary
2862 @item --portability
2863 @itemx --old-archive
2864 Synonym for @option{--format=v7}.
2865
2866 @opindex posix, summary
2867 @item --posix
2868 Same as @option{--format=posix}.
2869
2870 @opindex preserve, summary
2871 @item --preserve
2872
2873 Synonymous with specifying both @option{--preserve-permissions} and
2874 @option{--same-order}. @xref{Setting Access Permissions}.
2875
2876 @opindex preserve-order, summary
2877 @item --preserve-order
2878
2879 (See @option{--same-order}; @pxref{Reading}.)
2880
2881 @opindex preserve-permissions, summary
2882 @opindex same-permissions, summary
2883 @item --preserve-permissions
2884 @itemx --same-permissions
2885 @itemx -p
2886
2887 When @command{tar} is extracting an archive, it normally subtracts the
2888 users' umask from the permissions specified in the archive and uses
2889 that number as the permissions to create the destination file.
2890 Specifying this option instructs @command{tar} that it should use the
2891 permissions directly from the archive. @xref{Setting Access Permissions}.
2892
2893 @opindex read-full-records, summary
2894 @item --read-full-records
2895 @itemx -B
2896
2897 Specifies that @command{tar} should reblock its input, for reading
2898 from pipes on systems with buggy implementations. @xref{Reading}.
2899
2900 @opindex record-size, summary
2901 @item --record-size=@var{size}
2902
2903 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2904 archive. @xref{Blocking Factor}.
2905
2906 @opindex recursion, summary
2907 @item --recursion
2908
2909 With this option, @command{tar} recurses into directories.
2910 @xref{recurse}.
2911
2912 @opindex recursive-unlink, summary
2913 @item --recursive-unlink
2914
2915 Remove existing
2916 directory hierarchies before extracting directories of the same name
2917 from the archive. @xref{Recursive Unlink}.
2918
2919 @opindex remove-files, summary
2920 @item --remove-files
2921
2922 Directs @command{tar} to remove the source file from the file system after
2923 appending it to an archive. @xref{remove files}.
2924
2925 @opindex restrict, summary
2926 @item --restrict
2927
2928 Disable use of some potentially harmful @command{tar} options.
2929 Currently this option disables shell invocaton from multi-volume menu
2930 (@pxref{Using Multiple Tapes}).
2931
2932 @opindex rmt-command, summary
2933 @item --rmt-command=@var{cmd}
2934
2935 Notifies @command{tar} that it should use @var{cmd} instead of
2936 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
2937
2938 @opindex rsh-command, summary
2939 @item --rsh-command=@var{cmd}
2940
2941 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
2942 devices. @xref{Device}.
2943
2944 @opindex same-order, summary
2945 @item --same-order
2946 @itemx --preserve-order
2947 @itemx -s
2948
2949 This option is an optimization for @command{tar} when running on machines with
2950 small amounts of memory. It informs @command{tar} that the list of file
2951 arguments has already been sorted to match the order of files in the
2952 archive. @xref{Reading}.
2953
2954 @opindex same-owner, summary
2955 @item --same-owner
2956
2957 When extracting an archive, @command{tar} will attempt to preserve the owner
2958 specified in the @command{tar} archive with this option present.
2959 This is the default behavior for the superuser; this option has an
2960 effect only for ordinary users. @xref{Attributes}.
2961
2962 @opindex same-permissions, summary
2963 @item --same-permissions
2964
2965 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
2966
2967 @opindex show-defaults, summary
2968 @item --show-defaults
2969
2970 Displays the default options used by @command{tar} and exits
2971 successfully. This option is intended for use in shell scripts.
2972 Here is an example of what you can see using this option:
2973
2974 @smallexample
2975 $ tar --show-defaults
2976 --format=gnu -f- -b20 --quoting-style=escape \
2977 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
2978 @end smallexample
2979
2980 @opindex show-omitted-dirs, summary
2981 @item --show-omitted-dirs
2982
2983 Instructs @command{tar} to mention directories its skipping over when
2984 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
2985
2986 @opindex show-transformed-names, summary
2987 @opindex show-stored-names, summary
2988 @item --show-transformed-names
2989 @itemx --show-stored-names
2990
2991 Display file or member names after applying any transformations
2992 (@FIXME-pxref{}). In particular, when used in conjunction with one of
2993 archive creation operations it instructs tar to list the member names
2994 stored in the archive, as opposed to the actual file
2995 names. @xref{listing member and file names}.
2996
2997 @opindex sparse, summary
2998 @item --sparse
2999 @itemx -S
3000
3001 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3002 sparse files efficiently. @xref{sparse}.
3003
3004 @opindex starting-file, summary
3005 @item --starting-file=@var{name}
3006 @itemx -K @var{name}
3007
3008 This option affects extraction only; @command{tar} will skip extracting
3009 files in the archive until it finds one that matches @var{name}.
3010 @xref{Scarce}.
3011
3012 @opindex strip-components, summary
3013 @item --strip-components=@var{number}
3014 Strip given @var{number} of leading components from file names before
3015 extraction.@footnote{This option was called @option{--strip-path} in
3016 version 1.14.} For example, if archive @file{archive.tar} contained
3017 @file{/some/file/name}, then running
3018
3019 @smallexample
3020 tar --extract --file archive.tar --strip-components=2
3021 @end smallexample
3022
3023 @noindent
3024 would extracted this file to file @file{name}.
3025
3026 @opindex suffix, summary
3027 @item --suffix=@var{suffix}
3028
3029 Alters the suffix @command{tar} uses when backing up files from the default
3030 @samp{~}. @xref{backup}.
3031
3032 @opindex tape-length, summary
3033 @item --tape-length=@var{num}
3034 @itemx -L @var{num}
3035
3036 Specifies the length of tapes that @command{tar} is writing as being
3037 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3038
3039 @opindex test-label, summary
3040 @item --test-label
3041
3042 Reads the volume label. If an argument is specified, test whether it
3043 matches the volume label. @xref{--test-label option}.
3044
3045 @opindex to-command, summary
3046 @item --to-command=@var{command}
3047
3048 During extraction @command{tar} will pipe extracted files to the
3049 standard input of @var{command}. @xref{Writing to an External Program}.
3050
3051 @opindex to-stdout, summary
3052 @item --to-stdout
3053 @itemx -O
3054
3055 During extraction, @command{tar} will extract files to stdout rather
3056 than to the file system. @xref{Writing to Standard Output}.
3057
3058 @opindex totals, summary
3059 @item --totals
3060
3061 Displays the total number of bytes written after creating an archive.
3062 @xref{verbose}.
3063
3064 @opindex touch, summary
3065 @item --touch
3066 @itemx -m
3067
3068 Sets the data modification time of extracted files to the extraction time,
3069 rather than the data modification time stored in the archive.
3070 @xref{Data Modification Times}.
3071
3072 @opindex uncompress, summary
3073 @item --uncompress
3074
3075 (See @option{--compress}. @pxref{gzip})
3076
3077 @opindex ungzip, summary
3078 @item --ungzip
3079
3080 (See @option{--gzip}. @pxref{gzip})
3081
3082 @opindex unlink-first, summary
3083 @item --unlink-first
3084 @itemx -U
3085
3086 Directs @command{tar} to remove the corresponding file from the file
3087 system before extracting it from the archive. @xref{Unlink First}.
3088
3089 @opindex use-compress-program, summary
3090 @item --use-compress-program=@var{prog}
3091
3092 Instructs @command{tar} to access the archive through @var{prog}, which is
3093 presumed to be a compression program of some sort. @xref{gzip}.
3094
3095 @opindex utc, summary
3096 @item --utc
3097
3098 Display file modification dates in @acronym{UTC}. This option implies
3099 @option{--verbose}.
3100
3101 @opindex verbose, summary
3102 @item --verbose
3103 @itemx -v
3104
3105 Specifies that @command{tar} should be more verbose about the operations its
3106 performing. This option can be specified multiple times for some
3107 operations to increase the amount of information displayed.
3108 @xref{verbose}.
3109
3110 @opindex verify, summary
3111 @item --verify
3112 @itemx -W
3113
3114 Verifies that the archive was correctly written when creating an
3115 archive. @xref{verify}.
3116
3117 @opindex version, summary
3118 @item --version
3119
3120 Print information about the program's name, version, origin and legal
3121 status, all on standard output, and then exit successfully.
3122 @xref{help}.
3123
3124 @opindex volno-file, summary
3125 @item --volno-file=@var{file}
3126
3127 Used in conjunction with @option{--multi-volume}. @command{tar} will keep track
3128 of which volume of a multi-volume archive its working in @var{file}.
3129 @xref{volno-file}.
3130
3131 @opindex wildcards, summary
3132 @item --wildcards
3133 Use wildcards when matching member names with patterns.
3134 @xref{controlling pattern-matching}.
3135
3136 @opindex wildcards-match-slash, summary
3137 @item --wildcards-match-slash
3138 Wildcards match @samp{/}.
3139 @xref{controlling pattern-matching}.
3140 @end table
3141
3142 @node Short Option Summary
3143 @subsection Short Options Cross Reference
3144
3145 Here is an alphabetized list of all of the short option forms, matching
3146 them with the equivalent long option.
3147
3148 @table @option
3149
3150 @item -A
3151
3152 @option{--concatenate}
3153
3154 @item -B
3155
3156 @option{--read-full-records}
3157
3158 @item -C
3159
3160 @option{--directory}
3161
3162 @item -F
3163
3164 @option{--info-script}
3165
3166 @item -G
3167
3168 @option{--incremental}
3169
3170 @item -K
3171
3172 @option{--starting-file}
3173
3174 @item -L
3175
3176 @option{--tape-length}
3177
3178 @item -M
3179
3180 @option{--multi-volume}
3181
3182 @item -N
3183
3184 @option{--newer}
3185
3186 @item -O
3187
3188 @option{--to-stdout}
3189
3190 @item -P
3191
3192 @option{--absolute-names}
3193
3194 @item -R
3195
3196 @option{--block-number}
3197
3198 @item -S
3199
3200 @option{--sparse}
3201
3202 @item -T
3203
3204 @option{--files-from}
3205
3206 @item -U
3207
3208 @option{--unlink-first}
3209
3210 @item -V
3211
3212 @option{--label}
3213
3214 @item -W
3215
3216 @option{--verify}
3217
3218 @item -X
3219
3220 @option{--exclude-from}
3221
3222 @item -Z
3223
3224 @option{--compress}
3225
3226 @item -b
3227
3228 @option{--blocking-factor}
3229
3230 @item -c
3231
3232 @option{--create}
3233
3234 @item -d
3235
3236 @option{--compare}
3237
3238 @item -f
3239
3240 @option{--file}
3241
3242 @item -g
3243
3244 @option{--listed-incremental}
3245
3246 @item -h
3247
3248 @option{--dereference}
3249
3250 @item -i
3251
3252 @option{--ignore-zeros}
3253
3254 @item -j
3255
3256 @option{--bzip2}
3257
3258 @item -k
3259
3260 @option{--keep-old-files}
3261
3262 @item -l
3263
3264 @option{--one-file-system}. Use of this short option is deprecated. It
3265 is retained for compatibility with the earlier versions of GNU
3266 @command{tar}, and will be changed in future releases.
3267
3268 @xref{Changes}, for more information.
3269
3270 @item -m
3271
3272 @option{--touch}
3273
3274 @item -o
3275
3276 When creating --- @option{--no-same-owner}, when extracting ---
3277 @option{--portability}.
3278
3279 The later usage is deprecated. It is retained for compatibility with
3280 the earlier versions of @GNUTAR{}. In the future releases
3281 @option{-o} will be equivalent to @option{--no-same-owner} only.
3282
3283 @item -p
3284
3285 @option{--preserve-permissions}
3286
3287 @item -r
3288
3289 @option{--append}
3290
3291 @item -s
3292
3293 @option{--same-order}
3294
3295 @item -t
3296
3297 @option{--list}
3298
3299 @item -u
3300
3301 @option{--update}
3302
3303 @item -v
3304
3305 @option{--verbose}
3306
3307 @item -w
3308
3309 @option{--interactive}
3310
3311 @item -x
3312
3313 @option{--extract}
3314
3315 @item -z
3316
3317 @option{--gzip}
3318
3319 @end table
3320
3321 @node help
3322 @section @GNUTAR{} documentation
3323
3324 @cindex Getting program version number
3325 @opindex version
3326 @cindex Version of the @command{tar} program
3327 Being careful, the first thing is really checking that you are using
3328 @GNUTAR{}, indeed. The @option{--version} option
3329 causes @command{tar} to print information about its name, version,
3330 origin and legal status, all on standard output, and then exit
3331 successfully. For example, @w{@samp{tar --version}} might print:
3332
3333 @smallexample
3334 tar (GNU tar) 1.15.2
3335 Copyright (C) 2006 Free Software Foundation, Inc.
3336 This is free software. You may redistribute copies of it under the terms of
3337 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3338 There is NO WARRANTY, to the extent permitted by law.
3339
3340 Written by John Gilmore and Jay Fenlason.
3341 @end smallexample
3342
3343 @noindent
3344 The first occurrence of @samp{tar} in the result above is the program
3345 name in the package (for example, @command{rmt} is another program),
3346 while the second occurrence of @samp{tar} is the name of the package
3347 itself, containing possibly many programs. The package is currently
3348 named @samp{tar}, after the name of the main program it
3349 contains@footnote{There are plans to merge the @command{cpio} and
3350 @command{tar} packages into a single one which would be called
3351 @code{paxutils}. So, who knows if, one of this days, the
3352 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3353 paxutils) 3.2}}}.
3354
3355 @cindex Obtaining help
3356 @cindex Listing all @command{tar} options
3357 @opindex help, introduction
3358 Another thing you might want to do is checking the spelling or meaning
3359 of some particular @command{tar} option, without resorting to this
3360 manual, for once you have carefully read it. @GNUTAR{}
3361 has a short help feature, triggerable through the
3362 @option{--help} option. By using this option, @command{tar} will
3363 print a usage message listing all available options on standard
3364 output, then exit successfully, without doing anything else and
3365 ignoring all other options. Even if this is only a brief summary, it
3366 may be several screens long. So, if you are not using some kind of
3367 scrollable window, you might prefer to use something like:
3368
3369 @smallexample
3370 $ @kbd{tar --help | less}
3371 @end smallexample
3372
3373 @noindent
3374 presuming, here, that you like using @command{less} for a pager. Other
3375 popular pagers are @command{more} and @command{pg}. If you know about some
3376 @var{keyword} which interests you and do not want to read all the
3377 @option{--help} output, another common idiom is doing:
3378
3379 @smallexample
3380 tar --help | grep @var{keyword}
3381 @end smallexample
3382
3383 @noindent
3384 for getting only the pertinent lines. Notice, however, that some
3385 @command{tar} options have long description lines and the above
3386 command will list only the first of them.
3387
3388 The exact look of the option summary displayed by @kbd{tar --help} is
3389 configurable. @xref{Configuring Help Summary}, for a detailed description.
3390
3391 @opindex usage
3392 If you only wish to check the spelling of an option, running @kbd{tar
3393 --usage} may be a better choice. This will display a terse list of
3394 @command{tar} option without accompanying explanations.
3395
3396 The short help output is quite succinct, and you might have to get
3397 back to the full documentation for precise points. If you are reading
3398 this paragraph, you already have the @command{tar} manual in some
3399 form. This manual is available in a variety of forms from
3400 @url{http://www.gnu.org/software/tar/manual}. It may printed out of the @GNUTAR{}
3401 distribution, provided you have @TeX{} already installed somewhere,
3402 and a laser printer around. Just configure the distribution, execute
3403 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3404 usual way (contact your local guru to know how). If @GNUTAR{}
3405 has been conveniently installed at your place, this
3406 manual is also available in interactive, hypertextual form as an Info
3407 file. Just call @w{@samp{info tar}} or, if you do not have the
3408 @command{info} program handy, use the Info reader provided within
3409 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3410
3411 There is currently no @code{man} page for @GNUTAR{}.
3412 If you observe such a @code{man} page on the system you are running,
3413 either it does not belong to @GNUTAR{}, or it has not
3414 been produced by @acronym{GNU}. Some package maintainers convert
3415 @kbd{tar --help} output to a man page, using @command{help2man}. In
3416 any case, please bear in mind that the authoritative source of
3417 information about @GNUTAR{} is this Texinfo documentation.
3418
3419 @node defaults
3420 @section Obtaining @GNUTAR{} default values
3421
3422 @opindex show-defaults
3423 @GNUTAR{} has some predefined defaults that are used when you do not
3424 explicitely specify another values. To obtain a list of such
3425 defaults, use @option{--show-defaults} option. This will output the
3426 values in the form of @command{tar} command line options:
3427
3428 @smallexample
3429 @group
3430 @kbd{tar --show-defaults}
3431 --format=gnu -f- -b20 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3432 @end group
3433 @end smallexample
3434
3435 @noindent
3436 The above output shows that this version of @GNUTAR{} defaults to
3437 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3438 output as the archive, if no @option{--file} option has been given
3439 (@pxref{file tutorial}), the default blocking factor is 20
3440 (@pxref{Blocking Factor}). It also shows the default locations where
3441 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3442
3443 @node verbose
3444 @section Checking @command{tar} progress
3445
3446 Typically, @command{tar} performs most operations without reporting any
3447 information to the user except error messages. When using @command{tar}
3448 with many options, particularly ones with complicated or
3449 difficult-to-predict behavior, it is possible to make serious mistakes.
3450 @command{tar} provides several options that make observing @command{tar}
3451 easier. These options cause @command{tar} to print information as it
3452 progresses in its job, and you might want to use them just for being
3453 more careful about what is going on, or merely for entertaining
3454 yourself. If you have encountered a problem when operating on an
3455 archive, however, you may need more information than just an error
3456 message in order to solve the problem. The following options can be
3457 helpful diagnostic tools.
3458
3459 @cindex Verbose operation
3460 @opindex verbose
3461 Normally, the @option{--list} (@option{-t}) command to list an archive
3462 prints just the file names (one per line) and the other commands are
3463 silent. When used with most operations, the @option{--verbose}
3464 (@option{-v}) option causes @command{tar} to print the name of each
3465 file or archive member as it is processed. This and the other options
3466 which make @command{tar} print status information can be useful in
3467 monitoring @command{tar}.
3468
3469 With @option{--create} or @option{--extract}, @option{--verbose} used
3470 once just prints the names of the files or members as they are processed.
3471 Using it twice causes @command{tar} to print a longer listing
3472 (reminiscent of @samp{ls -l}) for each member. Since @option{--list}
3473 already prints the names of the members, @option{--verbose} used once
3474 with @option{--list} causes @command{tar} to print an @samp{ls -l}
3475 type listing of the files in the archive. The following examples both
3476 extract members with long list output:
3477
3478 @smallexample
3479 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3480 $ @kbd{tar xvvf archive.tar}
3481 @end smallexample
3482
3483 Verbose output appears on the standard output except when an archive is
3484 being written to the standard output, as with @samp{tar --create
3485 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3486 installer let standard output be the default archive). In that case
3487 @command{tar} writes verbose output to the standard error stream.
3488
3489 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3490 verbose output to @var{file} rather than to standard output or standard
3491 error.
3492
3493 @cindex Obtaining total status information
3494 @opindex totals
3495 The @option{--totals} option---which is only meaningful when used with
3496 @option{--create} (@option{-c})---causes @command{tar} to print the total
3497 amount written to the archive, after it has been fully created.
3498
3499 @cindex Progress information
3500 @opindex checkpoint
3501 The @option{--checkpoint} option prints an occasional message
3502 as @command{tar} reads or writes the archive. In fact, it prints
3503 a message each 10 records read or written. It is designed for
3504 those who don't need the more detailed (and voluminous) output of
3505 @option{--block-number} (@option{-R}), but do want visual confirmation
3506 that @command{tar} is actually making forward progress.
3507
3508 @FIXME{There is some confusion here. It seems that -R once wrote a
3509 message at @samp{every} record read or written.}
3510
3511 @opindex show-omitted-dirs
3512 @anchor{show-omitted-dirs}
3513 The @option{--show-omitted-dirs} option, when reading an archive---with
3514 @option{--list} or @option{--extract}, for example---causes a message
3515 to be printed for each directory in the archive which is skipped.
3516 This happens regardless of the reason for skipping: the directory might
3517 not have been named on the command line (implicitly or explicitly),
3518 it might be excluded by the use of the @option{--exclude=@var{pattern}} option, or
3519 some other reason.
3520
3521 @opindex block-number
3522 @cindex Block number where error occurred
3523 @anchor{block-number}
3524 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3525 every message it would normally produce, the block number within the
3526 archive where the message was triggered. Also, supplementary messages
3527 are triggered when reading blocks full of NULs, or when hitting end of
3528 file on the archive. As of now, if the archive if properly terminated
3529 with a NUL block, the reading of the file may stop before end of file
3530 is met, so the position of end of file will not usually show when
3531 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3532 drains the archive before exiting when reading the
3533 archive from a pipe.
3534
3535 @cindex Error message, block number of
3536 This option is especially useful when reading damaged archives, since
3537 it helps pinpoint the damaged sections. It can also be used with
3538 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3539 choose among several backup tapes when retrieving a file later, in
3540 favor of the tape where the file appears earliest (closest to the
3541 front of the tape). @xref{backup}.
3542
3543 @node interactive
3544 @section Asking for Confirmation During Operations
3545 @cindex Interactive operation
3546
3547 Typically, @command{tar} carries out a command without stopping for
3548 further instructions. In some situations however, you may want to
3549 exclude some files and archive members from the operation (for instance
3550 if disk or storage space is tight). You can do this by excluding
3551 certain files automatically (@pxref{Choosing}), or by performing
3552 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3553 @command{tar} also accepts @option{--confirmation} for this option.
3554
3555 @opindex interactive
3556 When the @option{--interactive} (@option{-w}) option is specified, before
3557 reading, writing, or deleting files, @command{tar} first prints a message
3558 for each such file, telling what operation it intends to take, then asks
3559 for confirmation on the terminal. The actions which require
3560 confirmation include adding a file to the archive, extracting a file
3561 from the archive, deleting a file from the archive, and deleting a file
3562 from disk. To confirm the action, you must type a line of input
3563 beginning with @samp{y}. If your input line begins with anything other
3564 than @samp{y}, @command{tar} skips that file.
3565
3566 If @command{tar} is reading the archive from the standard input,
3567 @command{tar} opens the file @file{/dev/tty} to support the interactive
3568 communications.
3569
3570 Verbose output is normally sent to standard output, separate from
3571 other error messages. However, if the archive is produced directly
3572 on standard output, then verbose output is mixed with errors on
3573 @code{stderr}. Producing the archive on standard output may be used
3574 as a way to avoid using disk space, when the archive is soon to be
3575 consumed by another process reading it, say. Some people felt the need
3576 of producing an archive on stdout, still willing to segregate between
3577 verbose output and error output. A possible approach would be using a
3578 named pipe to receive the archive, and having the consumer process to
3579 read from that named pipe. This has the advantage of letting standard
3580 output free to receive verbose output, all separate from errors.
3581
3582 @node operations
3583 @chapter @GNUTAR{} Operations
3584
3585 @menu
3586 * Basic tar::
3587 * Advanced tar::
3588 * create options::
3589 * extract options::
3590 * backup::
3591 * Applications::
3592 * looking ahead::
3593 @end menu
3594
3595 @node Basic tar
3596 @section Basic @GNUTAR{} Operations
3597
3598 The basic @command{tar} operations, @option{--create} (@option{-c}),
3599 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3600 @option{-x}), are currently presented and described in the tutorial
3601 chapter of this manual. This section provides some complementary notes
3602 for these operations.
3603
3604 @table @option
3605 @opindex create, complementary notes
3606 @item --create
3607 @itemx -c
3608
3609 Creating an empty archive would have some kind of elegance. One can
3610 initialize an empty archive and later use @option{--append}
3611 (@option{-r}) for adding all members. Some applications would not
3612 welcome making an exception in the way of adding the first archive
3613 member. On the other hand, many people reported that it is
3614 dangerously too easy for @command{tar} to destroy a magnetic tape with
3615 an empty archive@footnote{This is well described in @cite{Unix-haters
3616 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3617 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3618
3619 @enumerate
3620 @item
3621 Mistakingly using @code{create} instead of @code{extract}, when the
3622 intent was to extract the full contents of an archive. This error
3623 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3624 the QWERTY keyboard. Instead of being unpacked, the archive then
3625 gets wholly destroyed. When users speak about @dfn{exploding} an
3626 archive, they usually mean something else :-).
3627
3628 @item
3629 Forgetting the argument to @code{file}, when the intent was to create
3630 an archive with a single file in it. This error is likely because a
3631 tired user can easily add the @kbd{f} key to the cluster of option
3632 letters, by the mere force of habit, without realizing the full
3633 consequence of doing so. The usual consequence is that the single
3634 file, which was meant to be saved, is rather destroyed.
3635 @end enumerate
3636
3637 So, recognizing the likelihood and the catastrophical nature of these
3638 errors, @GNUTAR{} now takes some distance from elegance, and
3639 cowardly refuses to create an archive when @option{--create} option is
3640 given, there are no arguments besides options, and
3641 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3642 around the cautiousness of @GNUTAR{} and nevertheless create an
3643 archive with nothing in it, one may still use, as the value for the
3644 @option{--files-from} option, a file with no names in it, as shown in
3645 the following commands:
3646
3647 @smallexample
3648 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3649 @kbd{tar cfT empty-archive.tar /dev/null}
3650 @end smallexample
3651
3652 @opindex extract, complementary notes
3653 @item --extract
3654 @itemx --get
3655 @itemx -x
3656
3657 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3658
3659 @item @option{--list} (@option{-t})
3660
3661 @GNUTAR{} now shows dates as @samp{1996-08-30},
3662 while it used to show them as @samp{Aug 30 1996}. Preferably,
3663 people should get used to ISO 8601 dates. Local American dates should
3664 be made available again with full date localization support, once
3665 ready. In the meantime, programs not being localizable for dates
3666 should prefer international dates, that's really the way to go.
3667
3668 Look up @url{http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html} if you
3669 are curious, it contains a detailed explanation of the ISO 8601 standard.
3670
3671 @end table
3672
3673 @node Advanced tar
3674 @section Advanced @GNUTAR{} Operations
3675
3676 Now that you have learned the basics of using @GNUTAR{}, you may want
3677 to learn about further ways in which @command{tar} can help you.
3678
3679 This chapter presents five, more advanced operations which you probably
3680 won't use on a daily basis, but which serve more specialized functions.
3681 We also explain the different styles of options and why you might want
3682 to use one or another, or a combination of them in your @command{tar}
3683 commands. Additionally, this chapter includes options which allow you to
3684 define the output from @command{tar} more carefully, and provide help and
3685 error correction in special circumstances.
3686
3687 @FIXME{check this after the chapter is actually revised to make sure
3688 it still introduces the info in the chapter correctly : ).}
3689
3690 @menu
3691 * Operations::
3692 * append::
3693 * update::
3694 * concatenate::
3695 * delete::
3696 * compare::
3697 * quoting styles::
3698 @end menu
3699
3700 @node Operations
3701 @subsection The Five Advanced @command{tar} Operations
3702 @UNREVISED
3703
3704 In the last chapter, you learned about the first three operations to
3705 @command{tar}. This chapter presents the remaining five operations to
3706 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3707 @option{--delete}, and @option{--compare}.
3708
3709 You are not likely to use these operations as frequently as those
3710 covered in the last chapter; however, since they perform specialized
3711 functions, they are quite useful when you do need to use them. We
3712 will give examples using the same directory and files that you created
3713 in the last chapter. As you may recall, the directory is called
3714 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3715 @samp{rock}, and the two archive files you created are
3716 @samp{collection.tar} and @samp{music.tar}.
3717
3718 We will also use the archive files @samp{afiles.tar} and
3719 @samp{bfiles.tar}. @samp{afiles.tar} contains the members @samp{apple},
3720 @samp{angst}, and @samp{aspic}. @samp{bfiles.tar} contains the members
3721 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3722
3723 Unless we state otherwise, all practicing you do and examples you follow
3724 in this chapter will take place in the @file{practice} directory that
3725 you created in the previous chapter; see @ref{prepare for examples}.
3726 (Below in this section, we will remind you of the state of the examples
3727 where the last chapter left them.)
3728
3729 The five operations that we will cover in this chapter are:
3730
3731 @table @option
3732 @item --append
3733 @itemx -r
3734 Add new entries to an archive that already exists.
3735 @item --update
3736 @itemx -r
3737 Add more recent copies of archive members to the end of an archive, if
3738 they exist.
3739 @item --concatenate
3740 @itemx --catenate
3741 @itemx -A
3742 Add one or more pre-existing archives to the end of another archive.
3743 @item --delete
3744 Delete items from an archive (does not work on tapes).
3745 @item --compare
3746 @itemx --diff
3747 @itemx -d
3748 Compare archive members to their counterparts in the file system.
3749 @end table
3750
3751 @node append
3752 @subsection How to Add Files to Existing Archives: @option{--append}
3753 @UNREVISED
3754
3755 @opindex append
3756 If you want to add files to an existing archive, you don't need to
3757 create a new archive; you can use @option{--append} (@option{-r}).
3758 The archive must already exist in order to use @option{--append}. (A
3759 related operation is the @option{--update} operation; you can use this
3760 to add newer versions of archive members to an existing archive. To learn how to
3761 do this with @option{--update}, @pxref{update}.)
3762
3763 If you use @option{--append} to add a file that has the same name as an
3764 archive member to an archive containing that archive member, then the
3765 old member is not deleted. What does happen, however, is somewhat
3766 complex. @command{tar} @emph{allows} you to have infinite number of files
3767 with the same name. Some operations treat these same-named members no
3768 differently than any other set of archive members: for example, if you
3769 view an archive with @option{--list} (@option{-t}), you will see all
3770 of those members listed, with their data modification times, owners, etc.
3771
3772 Other operations don't deal with these members as perfectly as you might
3773 prefer; if you were to use @option{--extract} to extract the archive,
3774 only the most recently added copy of a member with the same name as four
3775 other members would end up in the working directory. This is because
3776 @option{--extract} extracts an archive in the order the members appeared
3777 in the archive; the most recently archived members will be extracted
3778 last. Additionally, an extracted member will @emph{replace} a file of
3779 the same name which existed in the directory already, and @command{tar}
3780 will not prompt you about this@footnote{Unless you give it
3781 @option{--keep-old-files} option, or the disk copy is newer than the
3782 the one in the archive and you invoke @command{tar} with
3783 @option{--keep-newer-files} option}. Thus, only the most recently archived
3784 member will end up being extracted, as it will replace the one
3785 extracted before it, and so on.
3786
3787 There exists a special option that allows you to get around this
3788 behavior and extract (or list) only a particular copy of the file.
3789 This is @option{--occurrence} option. If you run @command{tar} with
3790 this option, it will extract only the first copy of the file. You
3791 may also give this option an argument specifying the number of
3792 copy to be extracted. Thus, for example if the archive
3793 @file{archive.tar} contained three copies of file @file{myfile}, then
3794 the command
3795
3796 @smallexample
3797 tar --extract --file archive.tar --occurrence=2 myfile
3798 @end smallexample
3799
3800 @noindent
3801 would extract only the second copy. @xref{Option
3802 Summary,---occurrence}, for the description of @option{--occurrence}
3803 option.
3804
3805 @FIXME{ hag -- you might want to incorporate some of the above into the
3806 MMwtSN node; not sure. i didn't know how to make it simpler...
3807
3808 There are a few ways to get around this. (maybe xref Multiple Members
3809 with the Same Name.}
3810
3811 @cindex Members, replacing with other members
3812 @cindex Replacing members with other members
3813 If you want to replace an archive member, use @option{--delete} to
3814 delete the member you want to remove from the archive, , and then use
3815 @option{--append} to add the member you want to be in the archive. Note
3816 that you can not change the order of the archive; the most recently
3817 added member will still appear last. In this sense, you cannot truly
3818 ``replace'' one member with another. (Replacing one member with another
3819 will not work on certain types of media, such as tapes; see @ref{delete}
3820 and @ref{Media}, for more information.)
3821
3822 @menu
3823 * appending files:: Appending Files to an Archive
3824 * multiple::
3825 @end menu
3826
3827 @node appending files
3828 @subsubsection Appending Files to an Archive
3829 @UNREVISED
3830 @cindex Adding files to an Archive
3831 @cindex Appending files to an Archive
3832 @cindex Archives, Appending files to
3833
3834 The simplest way to add a file to an already existing archive is the
3835 @option{--append} (@option{-r}) operation, which writes specified
3836 files into the archive whether or not they are already among the
3837 archived files.
3838
3839 When you use @option{--append}, you @emph{must} specify file name
3840 arguments, as there is no default. If you specify a file that already
3841 exists in the archive, another copy of the file will be added to the
3842 end of the archive. As with other operations, the member names of the
3843 newly added files will be exactly the same as their names given on the
3844 command line. The @option{--verbose} (@option{-v}) option will print
3845 out the names of the files as they are written into the archive.
3846
3847 @option{--append} cannot be performed on some tape drives, unfortunately,
3848 due to deficiencies in the formats those tape drives use. The archive
3849 must be a valid @command{tar} archive, or else the results of using this
3850 operation will be unpredictable. @xref{Media}.
3851
3852 To demonstrate using @option{--append} to add a file to an archive,
3853 create a file called @file{rock} in the @file{practice} directory.
3854 Make sure you are in the @file{practice} directory. Then, run the
3855 following @command{tar} command to add @file{rock} to
3856 @file{collection.tar}:
3857
3858 @smallexample
3859 $ @kbd{tar --append --file=collection.tar rock}
3860 @end smallexample
3861
3862 @noindent
3863 If you now use the @option{--list} (@option{-t}) operation, you will see that
3864 @file{rock} has been added to the archive:
3865
3866 @smallexample
3867 $ @kbd{tar --list --file=collection.tar}
3868 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3869 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3870 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3871 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3872 @end smallexample
3873
3874 @node multiple
3875 @subsubsection Multiple Files with the Same Name
3876
3877 You can use @option{--append} (@option{-r}) to add copies of files
3878 which have been updated since the archive was created. (However, we
3879 do not recommend doing this since there is another @command{tar}
3880 option called @option{--update}; @xref{update}, for more information.
3881 We describe this use of @option{--append} here for the sake of
3882 completeness.) When you extract the archive, the older version will
3883 be effectively lost. This works because files are extracted from an
3884 archive in the order in which they were archived. Thus, when the
3885 archive is extracted, a file archived later in time will replace a
3886 file of the same name which was archived earlier, even though the
3887 older version of the file will remain in the archive unless you delete
3888 all versions of the file.
3889
3890 Supposing you change the file @file{blues} and then append the changed
3891 version to @file{collection.tar}. As you saw above, the original
3892 @file{blues} is in the archive @file{collection.tar}. If you change the
3893 file and append the new version of the file to the archive, there will
3894 be two copies in the archive. When you extract the archive, the older
3895 version of the file will be extracted first, and then replaced by the
3896 newer version when it is extracted.
3897
3898 You can append the new, changed copy of the file @file{blues} to the
3899 archive in this way:
3900
3901 @smallexample
3902 $ @kbd{tar --append --verbose --file=collection.tar blues}
3903 blues
3904 @end smallexample
3905
3906 @noindent
3907 Because you specified the @option{--verbose} option, @command{tar} has
3908 printed the name of the file being appended as it was acted on. Now
3909 list the contents of the archive:
3910
3911 @smallexample
3912 $ @kbd{tar --list --verbose --file=collection.tar}
3913 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3914 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3915 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3916 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3917 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3918 @end smallexample
3919
3920 @noindent
3921 The newest version of @file{blues} is now at the end of the archive
3922 (note the different creation dates and file sizes). If you extract
3923 the archive, the older version of the file @file{blues} will be
3924 replaced by the newer version. You can confirm this by extracting
3925 the archive and running @samp{ls} on the directory.
3926
3927 If you wish to extract the first occurrence of the file @file{blues}
3928 from the archive, use @option{--occurrence} option, as shown in
3929 the following example:
3930
3931 @smallexample
3932 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
3933 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3934 @end smallexample
3935
3936 @xref{Writing}, for more information on @option{--extract} and
3937 @xref{Option Summary, --occurrence}, for the description of
3938 @option{--occurrence} option.
3939
3940 @node update
3941 @subsection Updating an Archive
3942 @UNREVISED
3943 @cindex Updating an archive
3944
3945 @opindex update
3946 In the previous section, you learned how to use @option{--append} to
3947 add a file to an existing archive. A related operation is
3948 @option{--update} (@option{-u}). The @option{--update} operation
3949 updates a @command{tar} archive by comparing the date of the specified
3950 archive members against the date of the file with the same name. If
3951 the file has been modified more recently than the archive member, then
3952 the newer version of the file is added to the archive (as with
3953 @option{--append}).
3954
3955 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
3956 The operation will fail.
3957
3958 @FIXME{other examples of media on which --update will fail? need to ask
3959 charles and/or mib/thomas/dave shevett..}
3960
3961 Both @option{--update} and @option{--append} work by adding to the end
3962 of the archive. When you extract a file from the archive, only the
3963 version stored last will wind up in the file system, unless you use
3964 the @option{--backup} option. @FIXME-ref{Multiple Members with the
3965 Same Name}
3966
3967 @menu
3968 * how to update::
3969 @end menu
3970
3971 @node how to update
3972 @subsubsection How to Update an Archive Using @option{--update}
3973
3974 You must use file name arguments with the @option{--update}
3975 (@option{-u}) operation. If you don't specify any files,
3976 @command{tar} won't act on any files and won't tell you that it didn't
3977 do anything (which may end up confusing you).
3978
3979 @c note: the above parenthetical added because in fact, this
3980 @c behavior just confused the author. :-)
3981
3982 To see the @option{--update} option at work, create a new file,
3983 @file{classical}, in your practice directory, and some extra text to the
3984 file @file{blues}, using any text editor. Then invoke @command{tar} with
3985 the @samp{update} operation and the @option{--verbose} (@option{-v})
3986 option specified, using the names of all the files in the practice
3987 directory as file name arguments:
3988
3989 @smallexample
3990 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
3991 blues
3992 classical
3993 $
3994 @end smallexample
3995
3996 @noindent
3997 Because we have specified verbose mode, @command{tar} prints out the names
3998 of the files it is working on, which in this case are the names of the
3999 files that needed to be updated. If you run @samp{tar --list} and look
4000 at the archive, you will see @file{blues} and @file{classical} at its
4001 end. There will be a total of two versions of the member @samp{blues};
4002 the one at the end will be newer and larger, since you added text before
4003 updating it.
4004
4005 (The reason @command{tar} does not overwrite the older file when updating
4006 it is because writing to the middle of a section of tape is a difficult
4007 process. Tapes are not designed to go backward. @xref{Media}, for more
4008 information about tapes.
4009
4010 @option{--update} (@option{-u}) is not suitable for performing backups for two
4011 reasons: it does not change directory content entries, and it
4012 lengthens the archive every time it is used. The @GNUTAR{}
4013 options intended specifically for backups are more
4014 efficient. If you need to run backups, please consult @ref{Backups}.
4015
4016 @node concatenate
4017 @subsection Combining Archives with @option{--concatenate}
4018
4019 @cindex Adding archives to an archive
4020 @cindex Concatenating Archives
4021 @opindex concatenate
4022 @opindex catenate
4023 @c @cindex @option{-A} described
4024 Sometimes it may be convenient to add a second archive onto the end of
4025 an archive rather than adding individual files to the archive. To add
4026 one or more archives to the end of another archive, you should use the
4027 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4028
4029 To use @option{--concatenate}, give the first archive with
4030 @option{--file} option and name the rest of archives to be
4031 concatenated on the command line. The members, and their member
4032 names, will be copied verbatim from those archives to the first one.
4033 @FIXME-ref{This can cause multiple members to have the same name, for
4034 information on how this affects reading the archive, Multiple
4035 Members with the Same Name.}
4036 The new, concatenated archive will be called by the same name as the
4037 one given with the @option{--file} option. As usual, if you omit
4038 @option{--file}, @command{tar} will use the value of the environment
4039 variable @env{TAPE}, or, if this has not been set, the default archive name.
4040
4041 @FIXME{There is no way to specify a new name...}
4042
4043 To demonstrate how @option{--concatenate} works, create two small archives
4044 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4045 files from @file{practice}:
4046
4047 @smallexample
4048 $ @kbd{tar -cvf bluesrock.tar blues rock}
4049 blues
4050 rock
4051 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4052 folk
4053 jazz
4054 @end smallexample
4055
4056 @noindent
4057 If you like, You can run @samp{tar --list} to make sure the archives
4058 contain what they are supposed to:
4059
4060 @smallexample
4061 $ @kbd{tar -tvf bluesrock.tar}
4062 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4063 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4064 $ @kbd{tar -tvf jazzfolk.tar}
4065 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4066 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4067 @end smallexample
4068
4069 We can concatenate these two archives with @command{tar}:
4070
4071 @smallexample
4072 $ @kbd{cd ..}
4073 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4074 @end smallexample
4075
4076 If you now list the contents of the @file{bluesrock.tar}, you will see
4077 that now it also contains the archive members of @file{jazzfolk.tar}:
4078
4079 @smallexample
4080 $ @kbd{tar --list --file=bluesrock.tar}
4081 blues
4082 rock
4083 folk
4084 jazz
4085 @end smallexample
4086
4087 When you use @option{--concatenate}, the source and target archives must
4088 already exist and must have been created using compatible format
4089 parameters. Notice, that @command{tar} does not check whether the
4090 archives it concatenates have compatible formats, it does not
4091 even check if the files are really tar archives.
4092
4093 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4094 tape drives, due to deficiencies in the formats those tape drives use.
4095
4096 @cindex @code{concatenate} vs @command{cat}
4097 @cindex @command{cat} vs @code{concatenate}
4098 It may seem more intuitive to you to want or try to use @command{cat} to
4099 concatenate two archives instead of using the @option{--concatenate}
4100 operation; after all, @command{cat} is the utility for combining files.
4101
4102 However, @command{tar} archives incorporate an end-of-file marker which
4103 must be removed if the concatenated archives are to be read properly as
4104 one archive. @option{--concatenate} removes the end-of-archive marker
4105 from the target archive before each new archive is appended. If you use
4106 @command{cat} to combine the archives, the result will not be a valid
4107 @command{tar} format archive. If you need to retrieve files from an
4108 archive that was added to using the @command{cat} utility, use the
4109 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4110 information on dealing with archives improperly combined using the
4111 @command{cat} shell utility.
4112
4113 @node delete
4114 @subsection Removing Archive Members Using @option{--delete}
4115 @UNREVISED
4116 @cindex Deleting files from an archive
4117 @cindex Removing files from an archive
4118
4119 @opindex delete
4120 You can remove members from an archive by using the @option{--delete}
4121 option. Specify the name of the archive with @option{--file}
4122 (@option{-f}) and then specify the names of the members to be deleted;
4123 if you list no member names, nothing will be deleted. The
4124 @option{--verbose} option will cause @command{tar} to print the names
4125 of the members as they are deleted. As with @option{--extract}, you
4126 must give the exact member names when using @samp{tar --delete}.
4127 @option{--delete} will remove all versions of the named file from the
4128 archive. The @option{--delete} operation can run very slowly.
4129
4130 Unlike other operations, @option{--delete} has no short form.
4131
4132 @cindex Tapes, using @option{--delete} and
4133 @cindex Deleting from tape archives
4134 This operation will rewrite the archive. You can only use
4135 @option{--delete} on an archive if the archive device allows you to
4136 write to any point on the media, such as a disk; because of this, it
4137 does not work on magnetic tapes. Do not try to delete an archive member
4138 from a magnetic tape; the action will not succeed, and you will be
4139 likely to scramble the archive and damage your tape. There is no safe
4140 way (except by completely re-writing the archive) to delete files from
4141 most kinds of magnetic tape. @xref{Media}.
4142
4143 To delete all versions of the file @file{blues} from the archive
4144 @file{collection.tar} in the @file{practice} directory, make sure you
4145 are in that directory, and then,
4146
4147 @smallexample
4148 $ @kbd{tar --list --file=collection.tar}
4149 blues
4150 folk
4151 jazz
4152 rock
4153 $ @kbd{tar --delete --file=collection.tar blues}
4154 $ @kbd{tar --list --file=collection.tar}
4155 folk
4156 jazz
4157 rock
4158 $
4159 @end smallexample
4160
4161 @FIXME{Check if the above listing is actually produced after running
4162 all the examples on collection.tar.}
4163
4164 The @option{--delete} option has been reported to work properly when
4165 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4166
4167 @node compare
4168 @subsection Comparing Archive Members with the File System
4169 @cindex Verifying the currency of an archive
4170 @UNREVISED
4171
4172 @opindex compare
4173 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4174 specified archive members against files with the same names, and then
4175 reports differences in file size, mode, owner, modification date and
4176 contents. You should @emph{only} specify archive member names, not file
4177 names. If you do not name any members, then @command{tar} will compare the
4178 entire archive. If a file is represented in the archive but does not
4179 exist in the file system, @command{tar} reports a difference.
4180
4181 You have to specify the record size of the archive when modifying an
4182 archive with a non-default record size.
4183
4184 @command{tar} ignores files in the file system that do not have
4185 corresponding members in the archive.
4186
4187 The following example compares the archive members @file{rock},
4188 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4189 files of the same name in the file system. (Note that there is no file,
4190 @file{funk}; @command{tar} will report an error message.)
4191
4192 @smallexample
4193 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4194 rock
4195 blues
4196 tar: funk not found in archive
4197 @end smallexample
4198
4199 The spirit behind the @option{--compare} (@option{--diff},
4200 @option{-d}) option is to check whether the archive represents the
4201 current state of files on disk, more than validating the integrity of
4202 the archive media. For this later goal, @xref{verify}.
4203
4204 @node quoting styles
4205 @subsection Quoting Member Names
4206
4207 When displaying member names, @command{tar} takes care to avoid
4208 ambiguities caused by certain characters. This is called @dfn{name
4209 quoting}. The characters in question are:
4210
4211 @itemize @bullet
4212 @item Non-printable control characters:
4213
4214 @multitable @columnfractions 0.20 0.10 0.60
4215 @headitem Character @tab ASCII @tab Character name
4216 @item \a @tab 7 @tab Audible bell
4217 @item \b @tab 8 @tab Backspace
4218 @item \f @tab 12 @tab Form feed
4219 @item \n @tab 10 @tab New line
4220 @item \r @tab 13 @tab Carriage return
4221 @item \t @tab 9 @tab Horizontal tabulation
4222 @item \v @tab 11 @tab Vertical tabulation
4223 @end multitable
4224
4225 @item Space (ASCII 32)
4226
4227 @item Single and double quotes (@samp{'} and @samp{"})
4228
4229 @item Backslash (@samp{\})
4230 @end itemize
4231
4232 The exact way @command{tar} uses to quote these characters depends on
4233 the @dfn{quoting style}. The default quoting style, called
4234 @dfn{escape} (see below), uses backslash notation to represent control
4235 characters, space and backslash. Using this quoting style, control
4236 characters are represented as listed in column @samp{Character} in the
4237 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
4238
4239 @GNUTAR{} offers seven distinct quoting styles, which can be selected
4240 using @option{--quoting-style} option:
4241
4242 @table @option
4243 @item --quoting-style=@var{style}
4244 @opindex quoting-style
4245
4246 Sets quoting style. Valid values for @var{style} argument are:
4247 literal, shell, shell-always, c, escape, locale, clocale.
4248 @end table
4249
4250 These styles are described in detail below. To illustrate their
4251 effect, we will use an imaginary tar archive @file{arch.tar}
4252 containing the following members:
4253
4254 @smallexample
4255 @group
4256 # 1. Contains horizontal tabulation character.
4257 a tab
4258 # 2. Contains newline character
4259 a
4260 newline
4261 # 3. Contains a space
4262 a space
4263 # 4. Contains double quotes
4264 a"double"quote
4265 # 5. Contains single quotes
4266 a'single'quote
4267 # 6. Contains a backslash character:
4268 a\backslash
4269 @end group
4270 @end smallexample
4271
4272 Here is how usual @command{ls} command would have listed them, if they
4273 had existed in the current working directory:
4274
4275 @smallexample
4276 @group
4277 $ @kbd{ls}
4278 a\ttab
4279 a\nnewline
4280 a\ space
4281 a"double"quote
4282 a'single'quote
4283 a\\backslash
4284 @end group
4285 @end smallexample
4286
4287 Quoting styles:
4288
4289 @table @samp
4290 @item literal
4291 No quoting, display each character as is:
4292
4293 @smallexample
4294 @group
4295 $ @kbd{tar tf arch.tar --quoting-style=literal}
4296 ./
4297 ./a space
4298 ./a'single'quote
4299 ./a"double"quote
4300 ./a\backslash
4301 ./a tab
4302 ./a
4303 newline
4304 @end group
4305 @end smallexample
4306
4307 @item shell
4308 Display characters the same way Bourne shell does:
4309 control characters, except @samp{\t} and @samp{\n}, are printed using
4310 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
4311 single quote is printed as @samp{\'}. If a name contains any quoted
4312 characters, it is enclosed in single quotes. In particular, if a name
4313 contains single quotes, it is printed as several single-quoted strings:
4314
4315 @smallexample
4316 @group
4317 $ @kbd{tar tf arch.tar --quoting-style=shell}
4318 ./
4319 './a space'
4320 './a'\''single'\''quote'
4321 './a"double"quote'
4322 './a\backslash'
4323 './a tab'
4324 './a
4325 newline'
4326 @end group
4327 @end smallexample
4328
4329 @item shell-always
4330 Same as @samp{shell}, but the names are always enclosed in single
4331 quotes:
4332
4333 @smallexample
4334 @group
4335 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
4336 './'
4337 './a space'
4338 './a'\''single'\''quote'
4339 './a"double"quote'
4340 './a\backslash'
4341 './a tab'
4342 './a
4343 newline'
4344 @end group
4345 @end smallexample
4346
4347 @item c
4348 Use the notation of the C programming language. All names are
4349 enclosed in double quotes. Control characters are quoted using
4350 backslash notations, double quotes are represented as @samp{\"},
4351 backslash characters are represented as @samp{\\}. Single quotes and
4352 spaces are not quoted:
4353
4354 @smallexample
4355 @group
4356 $ @kbd{tar tf arch.tar --quoting-style=c}
4357 "./"
4358 "./a space"
4359 "./a'single'quote"
4360 "./a\"double\"quote"
4361 "./a\\backslash"
4362 "./a\ttab"
4363 "./a\nnewline"
4364 @end group
4365 @end smallexample
4366
4367 @item escape
4368 Control characters are printed using backslash notation, a space is
4369 printed as @samp{\ } and a backslash as @samp{\\}. This is the
4370 default quoting style, unless it was changed when configured the
4371 package.
4372
4373 @smallexample
4374 @group
4375 $ @kbd{tar tf arch.tar --quoting-style=escape}
4376 ./
4377 ./a space
4378 ./a'single'quote
4379 ./a"double"quote
4380 ./a\\backslash
4381 ./a\ttab
4382 ./a\nnewline
4383 @end group
4384 @end smallexample
4385
4386 @item locale
4387 Control characters, single quote and backslash are printed using
4388 backslash notation. All names are quoted using left and right
4389 quotation marks, appropriate to the current locale. If it does not
4390 define quotation marks, use @samp{`} as left and @samp{'} as right
4391 quotation marks. Any occurrences of the right quotation mark in a
4392 name are escaped with @samp{\}, for example:
4393
4394 For example:
4395
4396 @smallexample
4397 @group
4398 $ @kbd{tar tf arch.tar --quoting-style=locale}
4399 `./'
4400 `./a space'
4401 `./a\'single\'quote'
4402 `./a"double"quote'
4403 `./a\\backslash'
4404 `./a\ttab'
4405 `./a\nnewline'
4406 @end group
4407 @end smallexample
4408
4409 @item clocale
4410 Same as @samp{locale}, but @samp{"} is used for both left and right
4411 quotation marks, if not provided by the currently selected locale:
4412
4413 @smallexample
4414 @group
4415 $ @kbd{tar tf arch.tar --quoting-style=clocale}
4416 "./"
4417 "./a space"
4418 "./a'single'quote"
4419 "./a\"double\"quote"
4420 "./a\\backslash"
4421 "./a\ttab"
4422 "./a\nnewline"
4423 @end group
4424 @end smallexample
4425 @end table
4426
4427 You can specify which characters should be quoted in addition to those
4428 implied by the current quoting style:
4429
4430 @table @option
4431 @item --quote-chars=@var{string}
4432 Always quote characters from @var{string}, even if the selected
4433 quoting style would not quote them.
4434 @end table
4435
4436 For example, using @samp{escape} quoting (compare with the usual
4437 escape listing above):
4438
4439 @smallexample
4440 @group
4441 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
4442 ./
4443 ./a\ space
4444 ./a'single'quote
4445 ./a\"double\"quote
4446 ./a\\backslash
4447 ./a\ttab
4448 ./a\nnewline
4449 @end group
4450 @end smallexample
4451
4452 To disable quoting of such additional characters, use the following
4453 option:
4454
4455 @table @option
4456 @item --no-quote-chars=@var{string}
4457 Remove characters listed in @var{string} from the list of quoted
4458 characters set by the previous @option{--quote-chars} option.
4459 @end table
4460
4461 This option is particularly useful if you have added
4462 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
4463 and wish to disable it for the current invocation.
4464
4465 Note, that @option{--no-quote-chars} does @emph{not} disable those
4466 characters that are quoted by default in the selected quoting style.
4467
4468 @node create options
4469 @section Options Used by @option{--create}
4470
4471 @opindex create, additional options
4472 The previous chapter described the basics of how to use
4473 @option{--create} (@option{-c}) to create an archive from a set of files.
4474 @xref{create}. This section described advanced options to be used with
4475 @option{--create}.
4476
4477 @menu
4478 * Ignore Failed Read::
4479 @end menu
4480
4481 @node Ignore Failed Read
4482 @subsection Ignore Fail Read
4483
4484 @table @option
4485 @item --ignore-failed-read
4486 Do not exit with nonzero on unreadable files or directories.
4487 @end table
4488
4489 @node extract options
4490 @section Options Used by @option{--extract}
4491 @UNREVISED
4492
4493 @opindex extract, additional options
4494 The previous chapter showed how to use @option{--extract} to extract
4495 an archive into the file system. Various options cause @command{tar} to
4496 extract more information than just file contents, such as the owner,
4497 the permissions, the modification date, and so forth. This section
4498 presents options to be used with @option{--extract} when certain special
4499 considerations arise. You may review the information presented in
4500 @ref{extract} for more basic information about the
4501 @option{--extract} operation.
4502
4503 @menu
4504 * Reading:: Options to Help Read Archives
4505 * Writing:: Changing How @command{tar} Writes Files
4506 * Scarce:: Coping with Scarce Resources
4507 @end menu
4508
4509 @node Reading
4510 @subsection Options to Help Read Archives
4511 @cindex Options when reading archives
4512 @UNREVISED
4513
4514 @cindex Reading incomplete records
4515 @cindex Records, incomplete
4516 @opindex read-full-records
4517 Normally, @command{tar} will request data in full record increments from
4518 an archive storage device. If the device cannot return a full record,
4519 @command{tar} will report an error. However, some devices do not always
4520 return full records, or do not require the last record of an archive to
4521 be padded out to the next record boundary. To keep reading until you
4522 obtain a full record, or to accept an incomplete record if it contains
4523 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4524 in conjunction with the @option{--extract} or @option{--list} operations.
4525 @xref{Blocking}.
4526
4527 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4528 @command{tar} reads an archive from standard input, or from a remote
4529 machine. This is because on BSD Unix systems, attempting to read a
4530 pipe returns however much happens to be in the pipe, even if it is
4531 less than was requested. If this option were not enabled, @command{tar}
4532 would fail as soon as it read an incomplete record from the pipe.
4533
4534 If you're not sure of the blocking factor of an archive, you can
4535 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4536 @option{--blocking-factor=@var{512-size}} (@option{-b
4537 @var{512-size}}), using a blocking factor larger than what the archive
4538 uses. This lets you avoid having to determine the blocking factor
4539 of an archive. @xref{Blocking Factor}.
4540
4541 @menu
4542 * read full records::
4543 * Ignore Zeros::
4544 @end menu
4545
4546 @node read full records
4547 @unnumberedsubsubsec Reading Full Records
4548
4549 @FIXME{need sentence or so of intro here}
4550
4551 @table @option
4552 @opindex read-full-records
4553 @item --read-full-records
4554 @item -B
4555 Use in conjunction with @option{--extract} (@option{--get},
4556 @option{-x}) to read an archive which contains incomplete records, or
4557 one which has a blocking factor less than the one specified.
4558 @end table
4559
4560 @node Ignore Zeros
4561 @unnumberedsubsubsec Ignoring Blocks of Zeros
4562
4563 @cindex End-of-archive blocks, ignoring
4564 @cindex Ignoring end-of-archive blocks
4565 @opindex ignore-zeros
4566 Normally, @command{tar} stops reading when it encounters a block of zeros
4567 between file entries (which usually indicates the end of the archive).
4568 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4569 completely read an archive which contains a block of zeros before the
4570 end (i.e., a damaged archive, or one that was created by concatenating
4571 several archives together).
4572
4573 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4574 versions of @command{tar} write garbage after the end-of-archive entry,
4575 since that part of the media is never supposed to be read. @GNUTAR{}
4576 does not write after the end of an archive, but seeks to
4577 maintain compatiblity among archiving utilities.
4578
4579 @table @option
4580 @item --ignore-zeros
4581 @itemx -i
4582 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4583 encountered while reading an archive. Use in conjunction with
4584 @option{--extract} or @option{--list}.
4585 @end table
4586
4587 @node Writing
4588 @subsection Changing How @command{tar} Writes Files
4589 @UNREVISED
4590
4591 @FIXME{Introductory paragraph}
4592
4593 @menu
4594 * Dealing with Old Files::
4595 * Overwrite Old Files::
4596 * Keep Old Files::
4597 * Keep Newer Files::
4598 * Unlink First::
4599 * Recursive Unlink::
4600 * Data Modification Times::
4601 * Setting Access Permissions::
4602 * Directory Modification Times and Permissions::
4603 * Writing to Standard Output::
4604 * Writing to an External Program::
4605 * remove files::
4606 @end menu
4607
4608 @node Dealing with Old Files
4609 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4610
4611 @opindex overwrite-dir, introduced
4612 When extracting files, if @command{tar} discovers that the extracted
4613 file already exists, it normally replaces the file by removing it before
4614 extracting it, to prevent confusion in the presence of hard or symbolic
4615 links. (If the existing file is a symbolic link, it is removed, not
4616 followed.) However, if a directory cannot be removed because it is
4617 nonempty, @command{tar} normally overwrites its metadata (ownership,
4618 permission, etc.). The @option{--overwrite-dir} option enables this
4619 default behavior. To be more cautious and preserve the metadata of
4620 such a directory, use the @option{--no-overwrite-dir} option.
4621
4622 @cindex Overwriting old files, prevention
4623 @opindex keep-old-files, introduced
4624 To be even more cautious and prevent existing files from being replaced, use
4625 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4626 to replace or update a file that already exists, i.e., a file with the
4627 same name as an archive member prevents extraction of that archive
4628 member. Instead, it reports an error.
4629
4630 @opindex overwrite, introduced
4631 To be more aggressive about altering existing files, use the
4632 @option{--overwrite} option. It causes @command{tar} to overwrite
4633 existing files and to follow existing symbolic links when extracting.
4634
4635 @cindex Protecting old files
4636 Some people argue that @GNUTAR{} should not hesitate
4637 to overwrite files with other files when extracting. When extracting
4638 a @command{tar} archive, they expect to see a faithful copy of the
4639 state of the file system when the archive was created. It is debatable
4640 that this would always be a proper behavior. For example, suppose one
4641 has an archive in which @file{usr/local} is a link to
4642 @file{usr/local2}. Since then, maybe the site removed the link and
4643 renamed the whole hierarchy from @file{/usr/local2} to
4644 @file{/usr/local}. Such things happen all the time. I guess it would
4645 not be welcome at all that @GNUTAR{} removes the
4646 whole hierarchy just to make room for the link to be reinstated
4647 (unless it @emph{also} simultaneously restores the full
4648 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4649 able to remove a whole hierarchy to reestablish a symbolic link, for
4650 example, but @emph{only if} @option{--recursive-unlink} is specified
4651 to allow this behavior. In any case, single files are silently
4652 removed.
4653
4654 @opindex unlink-first, introduced
4655 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4656 some cases by causing @command{tar} to remove files unconditionally
4657 before extracting them.
4658
4659 @node Overwrite Old Files
4660 @unnumberedsubsubsec Overwrite Old Files
4661
4662 @table @option
4663 @opindex overwrite
4664 @item --overwrite
4665 Overwrite existing files and directory metadata when extracting files
4666 from an archive.
4667
4668 This causes @command{tar} to write extracted files into the file system without
4669 regard to the files already on the system; i.e., files with the same
4670 names as archive members are overwritten when the archive is extracted.
4671 It also causes @command{tar} to extract the ownership, permissions,
4672 and time stamps onto any preexisting files or directories.
4673 If the name of a corresponding file name is a symbolic link, the file
4674 pointed to by the symbolic link will be overwritten instead of the
4675 symbolic link itself (if this is possible). Moreover, special devices,
4676 empty directories and even symbolic links are automatically removed if
4677 they are in the way of extraction.
4678
4679 Be careful when using the @option{--overwrite} option, particularly when
4680 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4681 can change the contents, ownership or permissions of any file on your
4682 system. Also, many systems do not take kindly to overwriting files that
4683 are currently being executed.
4684
4685 @opindex overwrite-dir
4686 @item --overwrite-dir
4687 Overwrite the metadata of directories when extracting files from an
4688 archive, but remove other files before extracting.
4689 @end table
4690
4691 @node Keep Old Files
4692 @unnumberedsubsubsec Keep Old Files
4693
4694 @table @option
4695 @opindex keep-old-files
4696 @item --keep-old-files
4697 @itemx -k
4698 Do not replace existing files from archive. The
4699 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4700 from replacing existing files with files with the same name from the
4701 archive. The @option{--keep-old-files} option is meaningless with
4702 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4703 files in the file system during extraction.
4704 @end table
4705
4706 @node Keep Newer Files
4707 @unnumberedsubsubsec Keep Newer Files
4708
4709 @table @option
4710 @opindex keep-newer-files
4711 @item --keep-newer-files
4712 Do not replace existing files that are newer than their archive
4713 copies. This option is meaningless with @option{--list} (@option{-t}).
4714 @end table
4715
4716 @node Unlink First
4717 @unnumberedsubsubsec Unlink First
4718
4719 @table @option
4720 @opindex unlink-first
4721 @item --unlink-first
4722 @itemx -U
4723 Remove files before extracting over them.
4724 This can make @command{tar} run a bit faster if you know in advance
4725 that the extracted files all need to be removed. Normally this option
4726 slows @command{tar} down slightly, so it is disabled by default.
4727 @end table
4728
4729 @node Recursive Unlink
4730 @unnumberedsubsubsec Recursive Unlink
4731
4732 @table @option
4733 @opindex recursive-unlink
4734 @item --recursive-unlink
4735 When this option is specified, try removing files and directory hierarchies
4736 before extracting over them. @emph{This is a dangerous option!}
4737 @end table
4738
4739 If you specify the @option{--recursive-unlink} option,
4740 @command{tar} removes @emph{anything} that keeps you from extracting a file
4741 as far as current permissions will allow it. This could include removal
4742 of the contents of a full directory hierarchy.
4743
4744 @node Data Modification Times
4745 @unnumberedsubsubsec Setting Data Modification Times
4746
4747 @cindex Data modification times of extracted files
4748 @cindex Modification times of extracted files
4749 Normally, @command{tar} sets the data modification times of extracted
4750 files to the corresponding times recorded for the files in the archive, but
4751 limits the permissions of extracted files by the current @code{umask}
4752 setting.
4753
4754 To set the data modification times of extracted files to the time when
4755 the files were extracted, use the @option{--touch} (@option{-m}) option in
4756 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4757
4758 @table @option
4759 @opindex touch
4760 @item --touch
4761 @itemx -m
4762 Sets the data modification time of extracted archive members to the time
4763 they were extracted, not the time recorded for them in the archive.
4764 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4765 @end table
4766
4767 @node Setting Access Permissions
4768 @unnumberedsubsubsec Setting Access Permissions
4769
4770 @cindex Permissions of extracted files
4771 @cindex Modes of extracted files
4772 To set the modes (access permissions) of extracted files to those
4773 recorded for those files in the archive, use @option{--same-permissions}
4774 in conjunction with the @option{--extract} (@option{--get},
4775 @option{-x}) operation.
4776
4777 @table @option
4778 @opindex preserve-permission
4779 @opindex same-permission
4780 @item --preserve-permission
4781 @itemx --same-permission
4782 @c @itemx --ignore-umask
4783 @itemx -p
4784 Set modes of extracted archive members to those recorded in the
4785 archive, instead of current umask settings. Use in conjunction with
4786 @option{--extract} (@option{--get}, @option{-x}).
4787 @end table
4788
4789 @node Directory Modification Times and Permissions
4790 @unnumberedsubsubsec Directory Modification Times and Permissions
4791
4792 After sucessfully extracting a file member, @GNUTAR{} normally
4793 restores its permissions and modification times, as described in the
4794 previous sections. This cannot be done for directories, because
4795 after extracting a directory @command{tar} will almost certainly
4796 extract files into that directory and this will cause the directory
4797 modification time to be updated. Moreover, restoring that directory
4798 permissions may not permit file creation within it. Thus, restoring
4799 directory permissions and modification times must be delayed at least
4800 until all files have been extracted into that directory. @GNUTAR{}
4801 restores directories using the following approach.
4802
4803 The extracted directories are created with the mode specified in the
4804 archive, as modified by the umask of the user, which gives sufficient
4805 permissions to allow file creation. The meta-information about the
4806 directory is recorded in the temporary list of directories. When
4807 preparing to extract next archive member, @GNUTAR{} checks if the
4808 directory prefix of this file contains the remembered directory. If
4809 it does not, the program assumes that all files have been extracted
4810 into that directory, restores its modification time and permissions
4811 and removes its entry from the internal list. This approach allows
4812 to correctly restore directory meta-information in the majority of
4813 cases, while keeping memory requirements sufficiently small. It is
4814 based on the fact, that most @command{tar} archives use the predefined
4815 order of members: first the directory, then all the files and
4816 subdirectories in that directory.
4817
4818 However, this is not always true. The most important exception are
4819 incremental archives (@pxref{Incremental Dumps}). The member order in
4820 an incremental archive is reversed: first all directory members are
4821 stored, followed by other (non-directory) members. So, when extracting
4822 from incremental archives, @GNUTAR{} alters the above procedure. It
4823 remebers all restored directories, and restores their meta-data
4824 only after the entire archive has been processed. Notice, that you do
4825 not need to specity any special options for that, as @GNUTAR{}
4826 automatically detects archives in incremental format.
4827
4828 There may be cases, when such processing is required for normal archives
4829 too. Consider the following example:
4830
4831 @smallexample
4832 @group
4833 $ @kbd{tar --no-recursion -cvf archive \
4834 foo foo/file1 bar bar/file foo/file2}
4835 foo/
4836 foo/file1
4837 bar/
4838 bar/file
4839 foo/file2
4840 @end group
4841 @end smallexample
4842
4843 During the normal operation, after encountering @file{bar}
4844 @GNUTAR{} will assume that all files from the directory @file{foo}
4845 were already extracted and will therefore restore its timestamp and
4846 permission bits. However, after extracting @file{foo/file2} the
4847 directory timestamp will be offset again.
4848
4849 To correctly restore directory meta-information in such cases, use
4850 @option{delay-directory-restore} command line option:
4851
4852 @table @option
4853 @opindex delay-directory-restore
4854 @item --delay-directory-restore
4855 Delays restoring of the modification times and permissions of extracted
4856 directories until the end of extraction. This way, correct
4857 meta-information is restored even if the archive has unusual member
4858 ordering.
4859
4860 @opindex no-delay-directory-restore
4861 @item --no-delay-directory-restore
4862 Cancel the effect of the previous @option{--delay-directory-restore}.
4863 Use this option if you have used @option{--delay-directory-restore} in
4864 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4865 temporarily disable it.
4866 @end table
4867
4868 @node Writing to Standard Output
4869 @unnumberedsubsubsec Writing to Standard Output
4870
4871 @cindex Writing extracted files to standard output
4872 @cindex Standard output, writing extracted files to
4873 To write the extracted files to the standard output, instead of
4874 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4875 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4876 extracting files to send them through a pipe, and do not need to
4877 preserve them in the file system. If you extract multiple members,
4878 they appear on standard output concatenated, in the order they are
4879 found in the archive.
4880
4881 @table @option
4882 @opindex to-stdout
4883 @item --to-stdout
4884 @itemx -O
4885 Writes files to the standard output. Use only in conjunction with
4886 @option{--extract} (@option{--get}, @option{-x}). When this option is
4887 used, instead of creating the files specified, @command{tar} writes
4888 the contents of the files extracted to its standard output. This may
4889 be useful if you are only extracting the files in order to send them
4890 through a pipe. This option is meaningless with @option{--list}
4891 (@option{-t}).
4892 @end table
4893
4894 This can be useful, for example, if you have a tar archive containing
4895 a big file and don't want to store the file on disk before processing
4896 it. You can use a command like this:
4897
4898 @smallexample
4899 tar -xOzf foo.tgz bigfile | process
4900 @end smallexample
4901
4902 or even like this if you want to process the concatenation of the files:
4903
4904 @smallexample
4905 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4906 @end smallexample
4907
4908 Hovewer, @option{--to-command} may be more convenient for use with
4909 multiple files. See the next section.
4910
4911 @node Writing to an External Program
4912 @unnumberedsubsubsec Writing to an External Program
4913
4914 You can instruct @command{tar} to send the contents of each extracted
4915 file to the standard input of an external program:
4916
4917 @table @option
4918 @opindex to-command
4919 @item --to-command=@var{command}
4920 Extract files and pipe their contents to the standard input of
4921 @var{command}. When this option is used, instead of creating the
4922 files specified, @command{tar} invokes @var{command} and pipes the
4923 contents of the files to its standard output. @var{Command} may
4924 contain command line arguments. The program is executed via
4925 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4926 extracted. Non-regular files (directories, etc.) are ignored when this
4927 option is used.
4928 @end table
4929
4930 The command can obtain the information about the file it processes
4931 from the following environment variables:
4932
4933 @table @var
4934 @vrindex TAR_FILETYPE, to-command environment
4935 @item TAR_FILETYPE
4936 Type of the file. It is a single letter with the following meaning:
4937
4938 @multitable @columnfractions 0.10 0.90
4939 @item f @tab Regular file
4940 @item d @tab Directory
4941 @item l @tab Symbolic link
4942 @item h @tab Hard link
4943 @item b @tab Block device
4944 @item c @tab Character device
4945 @end multitable
4946
4947 Currently only regular files are supported.
4948
4949 @vrindex TAR_MODE, to-command environment
4950 @item TAR_MODE
4951 File mode, an octal number.
4952
4953 @vrindex TAR_FILENAME, to-command environment
4954 @item TAR_FILENAME
4955 The name of the file.
4956
4957 @vrindex TAR_REALNAME, to-command environment
4958 @item TAR_REALNAME
4959 Name of the file as stored in the archive.
4960
4961 @vrindex TAR_UNAME, to-command environment
4962 @item TAR_UNAME
4963 Name of the file owner.
4964
4965 @vrindex TAR_GNAME, to-command environment
4966 @item TAR_GNAME
4967 Name of the file owner group.
4968
4969 @vrindex TAR_ATIME, to-command environment
4970 @item TAR_ATIME
4971 Time of last access. It is a decimal number, representing seconds
4972 since the epoch. If the archive provides times with nanosecond
4973 precision, the nanoseconds are appended to the timestamp after a
4974 decimal point.
4975
4976 @vrindex TAR_MTIME, to-command environment
4977 @item TAR_MTIME
4978 Time of last modification.
4979
4980 @vrindex TAR_CTIME, to-command environment
4981 @item TAR_CTIME
4982 Time of last status change.
4983
4984 @vrindex TAR_SIZE, to-command environment
4985 @item TAR_SIZE
4986 Size of the file.
4987
4988 @vrindex TAR_UID, to-command environment
4989 @item TAR_UID
4990 UID of the file owner.
4991
4992 @vrindex TAR_GID, to-command environment
4993 @item TAR_GID
4994 GID of the file owner.
4995 @end table
4996
4997 In addition to these variables, @env{TAR_VERSION} contains the
4998 @GNUTAR{} version number.
4999
5000 If @var{command} exits with a non-0 status, @command{tar} will print
5001 an error message similar to the following:
5002
5003 @smallexample
5004 tar: 2345: Child returned status 1
5005 @end smallexample
5006
5007 Here, @samp{2345} is the PID of the finished process.
5008
5009 If this behavior is not wanted, use @option{--ignore-command-error}:
5010
5011 @table @option
5012 @opindex ignore-command-error
5013 @item --ignore-command-error
5014 Ignore exit codes of subprocesses. Notice that if the program
5015 exits on signal or otherwise terminates abnormally, the error message
5016 will be printed even if this option is used.
5017
5018 @opindex no-ignore-command-error
5019 @item --no-ignore-command-error
5020 Cancel the effect of any previous @option{--ignore-command-error}
5021 option. This option is useful if you have set
5022 @option{--ignore-command-error} in @env{TAR_OPTIONS}
5023 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
5024 @end table
5025
5026 @node remove files
5027 @unnumberedsubsubsec Removing Files
5028
5029 @FIXME{The section is too terse. Something more to add? An example,
5030 maybe?}
5031
5032 @table @option
5033 @opindex remove-files
5034 @item --remove-files
5035 Remove files after adding them to the archive.
5036 @end table
5037
5038 @node Scarce
5039 @subsection Coping with Scarce Resources
5040 @UNREVISED
5041
5042 @cindex Small memory
5043 @cindex Running out of space
5044
5045 @menu
5046 * Starting File::
5047 * Same Order::
5048 @end menu
5049
5050 @node Starting File
5051 @unnumberedsubsubsec Starting File
5052
5053 @table @option
5054 @opindex starting-file
5055 @item --starting-file=@var{name}
5056 @itemx -K @var{name}
5057 Starts an operation in the middle of an archive. Use in conjunction
5058 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5059 @end table
5060
5061 @cindex Middle of the archive, starting in the
5062 If a previous attempt to extract files failed due to lack of disk
5063 space, you can use @option{--starting-file=@var{name}} (@option{-K
5064 @var{name}}) to start extracting only after member @var{name} of the
5065 archive. This assumes, of course, that there is now free space, or
5066 that you are now extracting into a different file system. (You could
5067 also choose to suspend @command{tar}, remove unnecessary files from
5068 the file system, and then restart the same @command{tar} operation.
5069 In this case, @option{--starting-file} is not necessary.
5070 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
5071
5072 @node Same Order
5073 @unnumberedsubsubsec Same Order
5074
5075 @table @option
5076 @cindex Large lists of file names on small machines
5077 @opindex same-order
5078 @opindex preserve-order
5079 @item --same-order
5080 @itemx --preserve-order
5081 @itemx -s
5082 To process large lists of file names on machines with small amounts of
5083 memory. Use in conjunction with @option{--compare} (@option{--diff},
5084 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5085 (@option{--get}, @option{-x}).
5086 @end table
5087
5088 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5089 names to be listed or extracted is sorted in the same order as the
5090 files in the archive. This allows a large list of names to be used,
5091 even on a small machine that would not otherwise be able to hold all
5092 the names in memory at the same time. Such a sorted list can easily be
5093 created by running @samp{tar -t} on the archive and editing its output.
5094
5095 This option is probably never needed on modern computer systems.
5096
5097 @node backup
5098 @section Backup options
5099
5100 @cindex backup options
5101
5102 @GNUTAR{} offers options for making backups of files
5103 before writing new versions. These options control the details of
5104 these backups. They may apply to the archive itself before it is
5105 created or rewritten, as well as individual extracted members. Other
5106 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5107 and @command{mv}, for example) offer similar options.
5108
5109 Backup options may prove unexpectedly useful when extracting archives
5110 containing many members having identical name, or when extracting archives
5111 on systems having file name limitations, making different members appear
5112 has having similar names through the side-effect of name truncation.
5113 (This is true only if we have a good scheme for truncated backup names,
5114 which I'm not sure at all: I suspect work is needed in this area.)
5115 When any existing file is backed up before being overwritten by extraction,
5116 then clashing files are automatically be renamed to be unique, and the
5117 true name is kept for only the last file of a series of clashing files.
5118 By using verbose mode, users may track exactly what happens.
5119
5120 At the detail level, some decisions are still experimental, and may
5121 change in the future, we are waiting comments from our users. So, please
5122 do not learn to depend blindly on the details of the backup features.
5123 For example, currently, directories themselves are never renamed through
5124 using these options, so, extracting a file over a directory still has
5125 good chances to fail. Also, backup options apply to created archives,
5126 not only to extracted members. For created archives, backups will not
5127 be attempted when the archive is a block or character device, or when it
5128 refers to a remote file.
5129
5130 For the sake of simplicity and efficiency, backups are made by renaming old
5131 files prior to creation or extraction, and not by copying. The original
5132 name is restored if the file creation fails. If a failure occurs after a
5133 partial extraction of a file, both the backup and the partially extracted
5134 file are kept.
5135
5136 @table @samp
5137 @item --backup[=@var{method}]
5138 @opindex backup
5139 @vindex VERSION_CONTROL
5140 @cindex backups
5141 Back up files that are about to be overwritten or removed.
5142 Without this option, the original versions are destroyed.
5143
5144 Use @var{method} to determine the type of backups made.
5145 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5146 environment variable. And if @env{VERSION_CONTROL} is not set,
5147 use the @samp{existing} method.
5148
5149 @vindex version-control @r{Emacs variable}
5150 This option corresponds to the Emacs variable @samp{version-control};
5151 the same values for @var{method} are accepted as in Emacs. This option
5152 also allows more descriptive names. The valid @var{method}s are:
5153
5154 @table @samp
5155 @item t
5156 @itemx numbered
5157 @cindex numbered @r{backup method}
5158 Always make numbered backups.
5159
5160 @item nil
5161 @itemx existing
5162 @cindex existing @r{backup method}
5163 Make numbered backups of files that already have them, simple backups
5164 of the others.
5165
5166 @item never
5167 @itemx simple
5168 @cindex simple @r{backup method}
5169 Always make simple backups.
5170
5171 @end table
5172
5173 @item --suffix=@var{suffix}
5174 @opindex suffix
5175 @cindex backup suffix
5176 @vindex SIMPLE_BACKUP_SUFFIX
5177 Append @var{suffix} to each backup file made with @option{--backup}. If this
5178 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5179 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5180 set, the default is @samp{~}, just as in Emacs.
5181
5182 @end table
5183
5184 Some people express the desire to @emph{always} use the @option{--backup}
5185 option, by defining some kind of alias or script. This is not as easy
5186 as one may think, due to the fact that old style options should appear first
5187 and consume arguments a bit unpredictably for an alias or script. But,
5188 if you are ready to give up using old style options, you may resort to
5189 using something like (a Bourne shell function here):
5190
5191 @smallexample
5192 tar () @{ /usr/local/bin/tar --backup $*; @}
5193 @end smallexample
5194
5195 @node Applications
5196 @section Notable @command{tar} Usages
5197 @UNREVISED
5198
5199 @FIXME{Using Unix file linking capability to recreate directory
5200 structures---linking files into one subdirectory and then
5201 @command{tar}ring that directory.}
5202
5203 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5204
5205 @findex uuencode
5206 You can easily use archive files to transport a group of files from
5207 one system to another: put all relevant files into an archive on one
5208 computer system, transfer the archive to another system, and extract
5209 the contents there. The basic transfer medium might be magnetic tape,
5210 Internet FTP, or even electronic mail (though you must encode the
5211 archive with @command{uuencode} in order to transport it properly by
5212 mail). Both machines do not have to use the same operating system, as
5213 long as they both support the @command{tar} program.
5214
5215 For example, here is how you might copy a directory's contents from
5216 one disk to another, while preserving the dates, modes, owners and
5217 link-structure of all the files therein. In this case, the transfer
5218 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5219
5220 @smallexample
5221 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5222 @end smallexample
5223
5224 @noindent
5225 You can avoid subshells by using @option{-C} option:
5226
5227 @smallexample
5228 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5229 @end smallexample
5230
5231 @noindent
5232 The command also works using short option forms:
5233
5234 @smallexample
5235 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5236 | (cd targetdir; tar --extract --file=-)}
5237 # Or:
5238 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5239 | tar --directory targetdir --extract --file=-}
5240 @end smallexample
5241
5242 @noindent
5243 This is one of the easiest methods to transfer a @command{tar} archive.
5244
5245 @node looking ahead
5246 @section Looking Ahead: The Rest of this Manual
5247
5248 You have now seen how to use all eight of the operations available to
5249 @command{tar}, and a number of the possible options. The next chapter
5250 explains how to choose and change file and archive names, how to use
5251 files to store names of other files which you can then call as
5252 arguments to @command{tar} (this can help you save time if you expect to
5253 archive the same list of files a number of times), and so forth.
5254 @FIXME{in case it's not obvious, i'm making this up in some sense
5255 based on my limited memory of what the next chapter *really* does. i
5256 just wanted to flesh out this final section a little bit so i'd
5257 remember to stick it in here. :-)}
5258
5259 If there are too many files to conveniently list on the command line,
5260 you can list the names in a file, and @command{tar} will read that file.
5261 @xref{files}.
5262
5263 There are various ways of causing @command{tar} to skip over some files,
5264 and not archive them. @xref{Choosing}.
5265
5266 @node Backups
5267 @chapter Performing Backups and Restoring Files
5268 @UNREVISED
5269
5270 @GNUTAR{} is distributed along with the scripts
5271 which the Free Software Foundation uses for performing backups. There
5272 is no corresponding scripts available yet for doing restoration of
5273 files. Even if there is a good chance those scripts may be satisfying
5274 to you, they are not the only scripts or methods available for doing
5275 backups and restore. You may well create your own, or use more
5276 sophisticated packages dedicated to that purpose.
5277
5278 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5279 Automatic Network Disk Archiver), a backup system developed by James
5280 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5281 This is free software, and it is available at these places:
5282
5283 @smallexample
5284 http://www.cs.umd.edu/projects/amanda/amanda.html
5285 ftp://ftp.cs.umd.edu/pub/amanda
5286 @end smallexample
5287
5288 @FIXME{
5289
5290 Here is a possible plan for a future documentation about the backuping
5291 scripts which are provided within the @GNUTAR{}
5292 distribution.
5293
5294 @itemize @bullet
5295 @item dumps
5296 @itemize @minus
5297 @item what are dumps
5298 @item different levels of dumps
5299 @itemize +
5300 @item full dump = dump everything
5301 @item level 1, level 2 dumps etc
5302 A level @var{n} dump dumps everything changed since the last level
5303 @var{n}-1 dump (?)
5304 @end itemize
5305 @item how to use scripts for dumps (ie, the concept)
5306 @itemize +
5307 @item scripts to run after editing backup specs (details)
5308 @end itemize
5309 @item Backup Specs, what is it.
5310 @itemize +
5311 @item how to customize
5312 @item actual text of script [/sp/dump/backup-specs]
5313 @end itemize
5314 @item Problems
5315 @itemize +
5316 @item rsh doesn't work
5317 @item rtape isn't installed
5318 @item (others?)
5319 @end itemize
5320 @item the @option{--incremental} option of tar
5321 @item tapes
5322 @itemize +
5323 @item write protection
5324 @item types of media, different sizes and types, useful for different things
5325 @item files and tape marks
5326 one tape mark between files, two at end.
5327 @item positioning the tape
5328 MT writes two at end of write,
5329 backspaces over one when writing again.
5330 @end itemize
5331 @end itemize
5332 @end itemize
5333 }
5334
5335 This chapter documents both the provided shell scripts and @command{tar}
5336 options which are more specific to usage as a backup tool.
5337
5338 To @dfn{back up} a file system means to create archives that contain
5339 all the files in that file system. Those archives can then be used to
5340 restore any or all of those files (for instance if a disk crashes or a
5341 file is accidentally deleted). File system @dfn{backups} are also
5342 called @dfn{dumps}.
5343
5344 @menu
5345 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5346 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5347 * Backup Levels:: Levels of Backups
5348 * Backup Parameters:: Setting Parameters for Backups and Restoration
5349 * Scripted Backups:: Using the Backup Scripts
5350 * Scripted Restoration:: Using the Restore Script
5351 @end menu
5352
5353 @node Full Dumps
5354 @section Using @command{tar} to Perform Full Dumps
5355 @UNREVISED
5356
5357 @cindex full dumps
5358 @cindex dumps, full
5359
5360 @cindex corrupted archives
5361 Full dumps should only be made when no other people or programs
5362 are modifying files in the file system. If files are modified while
5363 @command{tar} is making the backup, they may not be stored properly in
5364 the archive, in which case you won't be able to restore them if you
5365 have to. (Files not being modified are written with no trouble, and do
5366 not corrupt the entire archive.)
5367
5368 You will want to use the @option{--label=@var{archive-label}}
5369 (@option{-V @var{archive-label}}) option to give the archive a
5370 volume label, so you can tell what this archive is even if the label
5371 falls off the tape, or anything like that.
5372
5373 Unless the file system you are dumping is guaranteed to fit on
5374 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5375 Make sure you have enough tapes on hand to complete the backup.
5376
5377 If you want to dump each file system separately you will need to use
5378 the @option{--one-file-system} option to prevent
5379 @command{tar} from crossing file system boundaries when storing
5380 (sub)directories.
5381
5382 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5383 option is not needed, since this is a complete copy of everything in
5384 the file system, and a full restore from this backup would only be
5385 done onto a completely
5386 empty disk.
5387
5388 Unless you are in a hurry, and trust the @command{tar} program (and your
5389 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5390 option, to make sure your files really made it onto the dump properly.
5391 This will also detect cases where the file was modified while (or just
5392 after) it was being archived. Not all media (notably cartridge tapes)
5393 are capable of being verified, unfortunately.
5394
5395 @node Incremental Dumps
5396 @section Using @command{tar} to Perform Incremental Dumps
5397
5398 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5399 stores additional metadata so that exact state of the file system
5400 can be restored when extracting the archive.
5401
5402 @GNUTAR{} currently offers two options for handling incremental
5403 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5404 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5405
5406 @opindex listed-incremental
5407 The option @option{--listed-incremental} instructs tar to operate on
5408 an incremental archive with additional metadata stored in a standalone
5409 file, called a @dfn{snapshot file}. The purpose of this file is to help
5410 determine which files have been changed, added or deleted since the
5411 last backup, so that the next incremental backup will contain only
5412 modified files. The name of the snapshot file is given as an argument
5413 to the option:
5414
5415 @table @option
5416 @item --listed-incremental=@var{file}
5417 @itemx -g @var{file}
5418 Handle incremental backups with snapshot data in @var{file}.
5419 @end table
5420
5421 To create an incremental backup, you would use
5422 @option{--listed-incremental} together with @option{--create}
5423 (@pxref{create}). For example:
5424
5425 @smallexample
5426 $ @kbd{tar --create \
5427 --file=archive.1.tar \
5428 --listed-incremental=/var/log/usr.snar \
5429 /usr}
5430 @end smallexample
5431
5432 This will create in @file{archive.1.tar} an incremental backup of
5433 the @file{/usr} file system, storing additional metadata in the file
5434 @file{/var/log/usr.snar}. If this file does not exist, it will be
5435 created. The created archive will then be a @dfn{level 0 backup};
5436 please see the next section for more on backup levels.
5437
5438 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5439 determines which files are modified. In this case only these files will be
5440 stored in the archive. Suppose, for example, that after running the
5441 above command, you delete file @file{/usr/doc/old} and create
5442 directory @file{/usr/local/db} with the following contents:
5443
5444 @smallexample
5445 $ @kbd{ls /usr/local/db}
5446 /usr/local/db/data
5447 /usr/local/db/index
5448 @end smallexample
5449
5450 Some time later you create another incremental backup. You will
5451 then see:
5452
5453 @smallexample
5454 $ @kbd{tar --create \
5455 --file=archive.2.tar \
5456 --listed-incremental=/var/log/usr.snar \
5457 /usr}
5458 tar: usr/local/db: Directory is new
5459 usr/local/db/
5460 usr/local/db/data
5461 usr/local/db/index
5462 @end smallexample
5463
5464 @noindent
5465 The created archive @file{archive.2.tar} will contain only these
5466 three members. This archive is called a @dfn{level 1 backup}. Notice
5467 that @file{/var/log/usr.snar} will be updated with the new data, so if
5468 you plan to create more @samp{level 1} backups, it is necessary to
5469 create a working copy of the snapshot file before running
5470 @command{tar}. The above example will then be modified as follows:
5471
5472 @smallexample
5473 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5474 $ @kbd{tar --create \
5475 --file=archive.2.tar \
5476 --listed-incremental=/var/log/usr.snar-1 \
5477 /usr}
5478 @end smallexample
5479
5480 Incremental dumps depend crucially on time stamps, so the results are
5481 unreliable if you modify a file's time stamps during dumping (e.g.,
5482 with the @option{--atime-preserve=replace} option), or if you set the clock
5483 backwards.
5484
5485 Metadata stored in snapshot files include device numbers, which,
5486 obviously is supposed to be a non-volatile value. However, it turns
5487 out that NFS devices have undependable values when an automounter
5488 gets in the picture. This can lead to a great deal of spurious
5489 redumping in incremental dumps, so it is somewhat useless to compare
5490 two NFS devices numbers over time. The solution implemented currently
5491 is to considers all NFS devices as being equal when it comes to
5492 comparing directories; this is fairly gross, but there does not seem
5493 to be a better way to go.
5494
5495 Note that incremental archives use @command{tar} extensions and may
5496 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5497
5498 @opindex listed-incremental, using with @option{--extract}
5499 @opindex extract, using with @option{--listed-incremental}
5500 To extract from the incremental dumps, use
5501 @option{--listed-incremental} together with @option{--extract}
5502 option (@pxref{extracting files}). In this case, @command{tar} does
5503 not need to access snapshot file, since all the data necessary for
5504 extraction are stored in the archive itself. So, when extracting, you
5505 can give whatever argument to @option{--listed-incremental}, the usual
5506 practice is to use @option{--listed-incremental=/dev/null}.
5507 Alternatively, you can use @option{--incremental}, which needs no
5508 arguments. In general, @option{--incremental} (@option{-G}) can be
5509 used as a shortcut for @option{--listed-incremental} when listing or
5510 extracting incremental backups (for more information, regarding this
5511 option, @pxref{incremental-op}).
5512
5513 When extracting from the incremental backup @GNUTAR{} attempts to
5514 restore the exact state the file system had when the archive was
5515 created. In particular, it will @emph{delete} those files in the file
5516 system that did not exist in their directories when the archive was
5517 created. If you have created several levels of incremental files,
5518 then in order to restore the exact contents the file system had when
5519 the last level was created, you will need to restore from all backups
5520 in turn. Continuing our example, to restore the state of @file{/usr}
5521 file system, one would do@footnote{Notice, that since both archives
5522 were created withouth @option{-P} option (@pxref{absolute}), these
5523 commands should be run from the root file system.}:
5524
5525 @smallexample
5526 $ @kbd{tar --extract \
5527 --listed-incremental=/dev/null \
5528 --file archive.1.tar}
5529 $ @kbd{tar --extract \
5530 --listed-incremental=/dev/null \
5531 --file archive.2.tar}
5532 @end smallexample
5533
5534 To list the contents of an incremental archive, use @option{--list}
5535 (@pxref{list}), as usual. To obtain more information about the
5536 archive, use @option{--listed-incremental} or @option{--incremental}
5537 combined with two @option{--verbose} options@footnote{Two
5538 @option{--verbose} options were selected to avoid breaking usual
5539 verbose listing output (@option{--list --verbose}) when using in
5540 scripts.
5541
5542 @opindex incremental, using with @option{--list}
5543 @opindex listed-incremental, using with @option{--list}
5544 @opindex list, using with @option{--incremental}
5545 @opindex list, using with @option{--listed-incremental}
5546 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5547 contents of the DUMPDIR header (with terminating nulls) when
5548 @option{--incremental} or @option{--listed-incremental} option was
5549 given, no matter what the verbosity level. This behavior, and,
5550 especially, the binary output it produced were considered incovenient
5551 and were changed in version 1.16}:
5552
5553 @smallexample
5554 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5555 @end smallexample
5556
5557 This command will print, for each directory in the archive, the list
5558 of files in that directory at the time the archive was created. This
5559 information is put out in a format which is both human-readable and
5560 unambiguous for a program: each file name is printed as
5561
5562 @smallexample
5563 @var{x} @var{file}
5564 @end smallexample
5565
5566 @noindent
5567 where @var{x} is a letter describing the status of the file: @samp{Y}
5568 if the file is present in the archive, @samp{N} if the file is not
5569 included in the archive, or a @samp{D} if the file is a directory (and
5570 is included in the archive).@FIXME-xref{dumpdir format}. Each such
5571 line is terminated by a newline character. The last line is followed
5572 by an additional newline to indicate the end of the data.
5573
5574 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5575 gives the same behavior as @option{--listed-incremental} when used
5576 with @option{--list} and @option{--extract} options. When used with
5577 @option{--create} option, it creates an incremental archive without
5578 creating snapshot file. Thus, it is impossible to create several
5579 levels of incremental backups with @option{--incremental} option.
5580
5581 @node Backup Levels
5582 @section Levels of Backups
5583
5584 An archive containing all the files in the file system is called a
5585 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5586 creating a full dump every day. This strategy, however, would waste a
5587 substantial amount of archive media and user time, as unchanged files
5588 are daily re-archived.
5589
5590 It is more efficient to do a full dump only occasionally. To back up
5591 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5592 one} dump archives all the files that have changed since the last full
5593 dump.
5594
5595 A typical dump strategy would be to perform a full dump once a week,
5596 and a level one dump once a day. This means some versions of files
5597 will in fact be archived more than once, but this dump strategy makes
5598 it possible to restore a file system to within one day of accuracy by
5599 only extracting two archives---the last weekly (full) dump and the
5600 last daily (level one) dump. The only information lost would be in
5601 files changed or created since the last daily backup. (Doing dumps
5602 more than once a day is usually not worth the trouble).
5603
5604 @GNUTAR{} comes with scripts you can use to do full
5605 and level-one (actually, even level-two and so on) dumps. Using
5606 scripts (shell programs) to perform backups and restoration is a
5607 convenient and reliable alternative to typing out file name lists
5608 and @command{tar} commands by hand.
5609
5610 Before you use these scripts, you need to edit the file
5611 @file{backup-specs}, which specifies parameters used by the backup
5612 scripts and by the restore script. This file is usually located
5613 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5614 detailed description. Once the backup parameters are set, you can
5615 perform backups or restoration by running the appropriate script.
5616
5617 The name of the backup script is @code{backup}. The name of the
5618 restore script is @code{restore}. The following sections describe
5619 their use in detail.
5620
5621 @emph{Please Note:} The backup and restoration scripts are
5622 designed to be used together. While it is possible to restore files by
5623 hand from an archive which was created using a backup script, and to create
5624 an archive by hand which could then be extracted using the restore script,
5625 it is easier to use the scripts. @xref{Incremental Dumps}, before
5626 making such an attempt.
5627
5628 @node Backup Parameters
5629 @section Setting Parameters for Backups and Restoration
5630
5631 The file @file{backup-specs} specifies backup parameters for the
5632 backup and restoration scripts provided with @command{tar}. You must
5633 edit @file{backup-specs} to fit your system configuration and schedule
5634 before using these scripts.
5635
5636 Syntactically, @file{backup-specs} is a shell script, containing
5637 mainly variable assignments. However, any valid shell construct
5638 is allowed in this file. Particularly, you may wish to define
5639 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5640 For more information about shell script syntax, please refer to
5641 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5642 g_02, the definition of the Shell Command Language}. See also
5643 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5644
5645 The shell variables controlling behavior of @code{backup} and
5646 @code{restore} are described in the following subsections.
5647
5648 @menu
5649 * General-Purpose Variables::
5650 * Magnetic Tape Control::
5651 * User Hooks::
5652 * backup-specs example:: An Example Text of @file{Backup-specs}
5653 @end menu
5654
5655 @node General-Purpose Variables
5656 @subsection General-Purpose Variables
5657
5658 @defvr {Backup variable} ADMINISTRATOR
5659 The user name of the backup administrator. @code{Backup} scripts
5660 sends a backup report to this address.
5661 @end defvr
5662
5663 @defvr {Backup variable} BACKUP_HOUR
5664 The hour at which the backups are done. This can be a number from 0
5665 to 23, or the time specification in form @var{hours}:@var{minutes},
5666 or the string @samp{now}.
5667
5668 This variable is used by @code{backup}. Its value may be overridden
5669 using @option{--time} option (@pxref{Scripted Backups}).
5670 @end defvr
5671
5672 @defvr {Backup variable} TAPE_FILE
5673
5674 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5675 is a remote archive (@pxref{remote-dev}), backup script will suppose
5676 that your @command{mt} is able to access remote devices. If @var{RSH}
5677 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5678 invocations of @command{mt}.
5679 @end defvr
5680
5681 @defvr {Backup variable} BLOCKING
5682
5683 The blocking factor @command{tar} will use when writing the dump archive.
5684 @xref{Blocking Factor}.
5685 @end defvr
5686
5687 @defvr {Backup variable} BACKUP_DIRS
5688
5689 A list of file systems to be dumped (for @code{backup}), or restored
5690 (for @code{restore}). You can include any directory
5691 name in the list --- subdirectories on that file system will be
5692 included, regardless of how they may look to other networked machines.
5693 Subdirectories on other file systems will be ignored.
5694
5695 The host name specifies which host to run @command{tar} on, and should
5696 normally be the host that actually contains the file system. However,
5697 the host machine must have @GNUTAR{} installed, and
5698 must be able to access the directory containing the backup scripts and
5699 their support files using the same file name that is used on the
5700 machine where the scripts are run (ie. what @command{pwd} will print
5701 when in that directory on that machine). If the host that contains
5702 the file system does not have this capability, you can specify another
5703 host as long as it can access the file system through NFS.
5704
5705 If the list of file systems is very long you may wish to put it
5706 in a separate file. This file is usually named
5707 @file{/etc/backup/dirs}, but this name may be overridden in
5708 @file{backup-specs} using @code{DIRLIST} variable.
5709 @end defvr
5710
5711 @defvr {Backup variable} DIRLIST
5712
5713 A path to the file containing the list of the file systems to backup
5714 or restore. By default it is @file{/etc/backup/dirs}.
5715 @end defvr
5716
5717 @defvr {Backup variable} BACKUP_FILES
5718
5719 A list of individual files to be dumped (for @code{backup}), or restored
5720 (for @code{restore}). These should be accessible from the machine on
5721 which the backup script is run.
5722
5723 If the list of file systems is very long you may wish to store it
5724 in a separate file. This file is usually named
5725 @file{/etc/backup/files}, but this name may be overridden in
5726 @file{backup-specs} using @code{FILELIST} variable.
5727 @end defvr
5728
5729 @defvr {Backup variable} FILELIST
5730
5731 A path to the file containing the list of the individual files to backup
5732 or restore. By default it is @file{/etc/backup/files}.
5733 @end defvr
5734
5735 @defvr {Backup variable} MT
5736
5737 Full file name of @command{mt} binary.
5738 @end defvr
5739
5740 @defvr {Backup variable} RSH
5741 @anchor{RSH}
5742 Full file name of @command{rsh} binary or its equivalent. You may wish to
5743 set it to @code{ssh}, to improve security. In this case you will have
5744 to use public key authentication.
5745 @end defvr
5746
5747 @defvr {Backup variable} RSH_COMMAND
5748
5749 Full file name of @command{rsh} binary on remote mashines. This will
5750 be passed via @option{--rsh-command} option to the remote invocation
5751 of @GNUTAR{}.
5752 @end defvr
5753
5754 @defvr {Backup variable} VOLNO_FILE
5755
5756 Name of temporary file to hold volume numbers. This needs to be accessible
5757 by all the machines which have file systems to be dumped.
5758 @end defvr
5759
5760 @defvr {Backup variable} XLIST
5761
5762 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5763 located on the remote machine and containing the list of files to
5764 be excluded from the backup. Exclude file lists are searched in
5765 /etc/tar-backup directory. A common use for exclude file lists
5766 is to exclude files containing security-sensitive information
5767 (e.g., @file{/etc/shadow} from backups).
5768
5769 This variable affects only @code{backup}.
5770 @end defvr
5771
5772 @defvr {Backup variable} SLEEP_TIME
5773
5774 Time to sleep between dumps of any two successive file systems
5775
5776 This variable affects only @code{backup}.
5777 @end defvr
5778
5779 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5780
5781 Script to be run when it's time to insert a new tape in for the next
5782 volume. Administrators may want to tailor this script for their site.
5783 If this variable isn't set, @GNUTAR{} will display its built-in prompt
5784 @FIXME-xref{describe it somewhere!}, and will expect confirmation from
5785 the console.
5786 @end defvr
5787
5788 @defvr {Backup variable} SLEEP_MESSAGE
5789
5790 Message to display on the terminal while waiting for dump time. Usually
5791 this will just be some literal text.
5792 @end defvr
5793
5794 @defvr {Backup variable} TAR
5795
5796 Full file name of the @GNUTAR{} executable. If this is not set, backup
5797 scripts will search @command{tar} in the current shell path.
5798 @end defvr
5799
5800 @node Magnetic Tape Control
5801 @subsection Magnetic Tape Control
5802
5803 Backup scripts access tape device using special @dfn{hook functions}.
5804 These functions take a single argument -- the name of the tape
5805 device. Their names are kept in the following variables:
5806
5807 @defvr {Backup variable} MT_BEGIN
5808 The name of @dfn{begin} function. This function is called before
5809 accessing the drive. By default it retensions the tape:
5810
5811 @smallexample
5812 MT_BEGIN=mt_begin
5813
5814 mt_begin() @{
5815 mt -f "$1" retension
5816 @}
5817 @end smallexample
5818 @end defvr
5819
5820 @defvr {Backup variable} MT_REWIND
5821 The name of @dfn{rewind} function. The default definition is as
5822 follows:
5823
5824 @smallexample
5825 MT_REWIND=mt_rewind
5826
5827 mt_rewind() @{
5828 mt -f "$1" rewind
5829 @}
5830 @end smallexample
5831
5832 @end defvr
5833
5834 @defvr {Backup variable} MT_OFFLINE
5835 The name of the function switching the tape off line. By default
5836 it is defined as follows:
5837
5838 @smallexample
5839 MT_OFFLINE=mt_offline
5840
5841 mt_offline() @{
5842 mt -f "$1" offl
5843 @}
5844 @end smallexample
5845 @end defvr
5846
5847 @defvr {Backup variable} MT_STATUS
5848 The name of the function used to obtain the status of the archive device,
5849 including error count. Default definition:
5850
5851 @smallexample
5852 MT_STATUS=mt_status
5853
5854 mt_status() @{
5855 mt -f "$1" status
5856 @}
5857 @end smallexample
5858 @end defvr
5859
5860 @node User Hooks
5861 @subsection User Hooks
5862
5863 @dfn{User hooks} are shell functions executed before and after
5864 each @command{tar} invocation. Thus, there are @dfn{backup
5865 hooks}, which are executed before and after dumping each file
5866 system, and @dfn{restore hooks}, executed before and
5867 after restoring a file system. Each user hook is a shell function
5868 taking four arguments:
5869
5870 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5871 Its arguments are:
5872
5873 @table @var
5874 @item level
5875 Current backup or restore level.
5876
5877 @item host
5878 Name or IP address of the host machine being dumped or restored.
5879
5880 @item fs
5881 Full path name to the file system being dumped or restored.
5882
5883 @item fsname
5884 File system name with directory separators replaced with colons. This
5885 is useful, e.g., for creating unique files.
5886 @end table
5887 @end deffn
5888
5889 Following variables keep the names of user hook functions
5890
5891 @defvr {Backup variable} DUMP_BEGIN
5892 Dump begin function. It is executed before dumping the file system.
5893 @end defvr
5894
5895 @defvr {Backup variable} DUMP_END
5896 Executed after dumping the file system.
5897 @end defvr
5898
5899 @defvr {Backup variable} RESTORE_BEGIN
5900 Executed before restoring the file system.
5901 @end defvr
5902
5903 @defvr {Backup variable} RESTORE_END
5904 Executed after restoring the file system.
5905 @end defvr
5906
5907 @node backup-specs example
5908 @subsection An Example Text of @file{Backup-specs}
5909
5910 The following is an example of @file{backup-specs}:
5911
5912 @smallexample
5913 # site-specific parameters for file system backup.
5914
5915 ADMINISTRATOR=friedman
5916 BACKUP_HOUR=1
5917 TAPE_FILE=/dev/nrsmt0
5918
5919 # Use @code{ssh} instead of the less secure @code{rsh}
5920 RSH=/usr/bin/ssh
5921 RSH_COMMAND=/usr/bin/ssh
5922
5923 # Override MT_STATUS function:
5924 my_status() @{
5925 mts -t $TAPE_FILE
5926 @}
5927 MT_STATUS=my_status
5928
5929 # Disable MT_OFFLINE function
5930 MT_OFFLINE=:
5931
5932 BLOCKING=124
5933 BACKUP_DIRS="
5934 albert:/fs/fsf
5935 apple-gunkies:/gd
5936 albert:/fs/gd2
5937 albert:/fs/gp
5938 geech:/usr/jla
5939 churchy:/usr/roland
5940 albert:/
5941 albert:/usr
5942 apple-gunkies:/
5943 apple-gunkies:/usr
5944 gnu:/hack
5945 gnu:/u
5946 apple-gunkies:/com/mailer/gnu
5947 apple-gunkies:/com/archive/gnu"
5948
5949 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5950
5951 @end smallexample
5952
5953 @node Scripted Backups
5954 @section Using the Backup Scripts
5955
5956 The syntax for running a backup script is:
5957
5958 @smallexample
5959 backup --level=@var{level} --time=@var{time}
5960 @end smallexample
5961
5962 The @option{level} option requests the dump level. Thus, to produce
5963 a full dump, specify @code{--level=0} (this is the default, so
5964 @option{--level} may be omitted if its value is @code{0}).
5965 @footnote{For backward compatibility, the @code{backup} will also
5966 try to deduce the requested dump level from the name of the
5967 script itself. If the name consists of a string @samp{level-}
5968 followed by a single decimal digit, that digit is taken as
5969 the dump level number. Thus, you may create a link from @code{backup}
5970 to @code{level-1} and then run @code{level-1} whenever you need to
5971 create a level one dump.}
5972
5973 The @option{--time} option determines when should the backup be
5974 run. @var{Time} may take three forms:
5975
5976 @table @asis
5977 @item @var{hh}:@var{mm}
5978
5979 The dump must be run at @var{hh} hours @var{mm} minutes.
5980
5981 @item @var{hh}
5982
5983 The dump must be run at @var{hh} hours
5984
5985 @item now
5986
5987 The dump must be run immediately.
5988 @end table
5989
5990 You should start a script with a tape or disk mounted. Once you
5991 start a script, it prompts you for new tapes or disks as it
5992 needs them. Media volumes don't have to correspond to archive
5993 files --- a multi-volume archive can be started in the middle of a
5994 tape that already contains the end of another multi-volume archive.
5995 The @code{restore} script prompts for media by its archive volume,
5996 so to avoid an error message you should keep track of which tape
5997 (or disk) contains which volume of the archive (@pxref{Scripted
5998 Restoration}).
5999
6000 The backup scripts write two files on the file system. The first is a
6001 record file in @file{/etc/tar-backup/}, which is used by the scripts
6002 to store and retrieve information about which files were dumped. This
6003 file is not meant to be read by humans, and should not be deleted by
6004 them. @xref{Snapshot Files}, for a more detailed explanation of this
6005 file.
6006
6007 The second file is a log file containing the names of the file systems
6008 and files dumped, what time the backup was made, and any error
6009 messages that were generated, as well as how much space was left in
6010 the media volume after the last volume of the archive was written.
6011 You should check this log file after every backup. The file name is
6012 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
6013 represents current date, and @var{n} represents current dump level number.
6014
6015 The script also prints the name of each system being dumped to the
6016 standard output.
6017
6018 Following is the full list of options accepted by @code{backup}
6019 script:
6020
6021 @table @option
6022 @item -l @var{level}
6023 @itemx --level=@var{level}
6024 Do backup level @var{level} (default 0).
6025
6026 @item -f
6027 @itemx --force
6028 Force backup even if today's log file already exists.
6029
6030 @item -v[@var{level}]
6031 @itemx --verbose[=@var{level}]
6032 Set verbosity level. The higher the level is, the more debugging
6033 information will be output during execution. Devault @var{level}
6034 is 100, which means the highest debugging level.
6035
6036 @item -t @var{start-time}
6037 @itemx --time=@var{start-time}
6038 Wait till @var{time}, then do backup.
6039
6040 @item -h
6041 @itemx --help
6042 Display short help message and exit.
6043
6044 @item -V
6045 @itemx --version
6046 Display information about the program's name, version, origin and legal
6047 status, all on standard output, and then exit successfully.
6048 @end table
6049
6050
6051 @node Scripted Restoration
6052 @section Using the Restore Script
6053
6054 To restore files that were archived using a scripted backup, use the
6055 @code{restore} script. Its usage is quite straightforward. In the
6056 simplest form, invoke @code{restore --all}, it will
6057 then restore all the file systems and files specified in
6058 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6059
6060 You may select the file systems (and/or files) to restore by
6061 giving @code{restore} list of @dfn{patterns} in its command
6062 line. For example, running
6063
6064 @smallexample
6065 restore 'albert:*'
6066 @end smallexample
6067
6068 @noindent
6069 will restore all file systems on the machine @samp{albert}. A more
6070 complicated example:
6071
6072 @smallexample
6073 restore 'albert:*' '*:/var'
6074 @end smallexample
6075
6076 @noindent
6077 This command will restore all file systems on the machine @samp{albert}
6078 as well as @file{/var} file system on all machines.
6079
6080 By default @code{restore} will start restoring files from the lowest
6081 available dump level (usually zero) and will continue through
6082 all available dump levels. There may be situations where such a
6083 thorough restore is not necessary. For example, you may wish to
6084 restore only files from the recent level one backup. To do so,
6085 use @option{--level} option, as shown in the example below:
6086
6087 @smallexample
6088 restore --level=1
6089 @end smallexample
6090
6091 The full list of options accepted by @code{restore} follows:
6092
6093 @table @option
6094 @item -a
6095 @itemx --all
6096 Restore all file systems and files specified in @file{backup-specs}
6097
6098 @item -l @var{level}
6099 @itemx --level=@var{level}
6100 Start restoring from the given backup level, instead of the default 0.
6101
6102 @item -v[@var{level}]
6103 @itemx --verbose[=@var{level}]
6104 Set verbosity level. The higher the level is, the more debugging
6105 information will be output during execution. Devault @var{level}
6106 is 100, which means the highest debugging level.
6107
6108 @item -h
6109 @itemx --help
6110 Display short help message and exit.
6111
6112 @item -V
6113 @itemx --version
6114 Display information about the program's name, version, origin and legal
6115 status, all on standard output, and then exit successfully.
6116 @end table
6117
6118 You should start the restore script with the media containing the
6119 first volume of the archive mounted. The script will prompt for other
6120 volumes as they are needed. If the archive is on tape, you don't need
6121 to rewind the tape to to its beginning---if the tape head is
6122 positioned past the beginning of the archive, the script will rewind
6123 the tape as needed. @FIXME-xref{Media, for a discussion of tape
6124 positioning.}
6125
6126 @quotation
6127 @strong{Warning:} The script will delete files from the active file
6128 system if they were not in the file system when the archive was made.
6129 @end quotation
6130
6131 @xref{Incremental Dumps}, for an explanation of how the script makes
6132 that determination.
6133
6134 @node Choosing
6135 @chapter Choosing Files and Names for @command{tar}
6136 @UNREVISED
6137
6138 Certain options to @command{tar} enable you to specify a name for your
6139 archive. Other options let you decide which files to include or exclude
6140 from the archive, based on when or whether files were modified, whether
6141 the file names do or don't match specified patterns, or whether files
6142 are in specified directories.
6143
6144 This chapter discusses these options in detail.
6145
6146 @menu
6147 * file:: Choosing the Archive's Name
6148 * Selecting Archive Members::
6149 * files:: Reading Names from a File
6150 * exclude:: Excluding Some Files
6151 * Wildcards:: Wildcards Patterns and Matching
6152 * after:: Operating Only on New Files
6153 * recurse:: Descending into Directories
6154 * one:: Crossing File System Boundaries
6155 @end menu
6156
6157 @node file
6158 @section Choosing and Naming Archive Files
6159 @UNREVISED
6160
6161 @cindex Naming an archive
6162 @cindex Archive Name
6163 @cindex Choosing an archive file
6164 @cindex Where is the archive?
6165 By default, @command{tar} uses an archive file name that was compiled when
6166 it was built on the system; usually this name refers to some physical
6167 tape drive on the machine. However, the person who installed @command{tar}
6168 on the system may not have set the default to a meaningful value as far as
6169 most users are concerned. As a result, you will usually want to tell
6170 @command{tar} where to find (or create) the archive. The
6171 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6172 option allows you to either specify or name a file to use as the archive
6173 instead of the default archive file location.
6174
6175 @table @option
6176 @opindex file, short description
6177 @item --file=@var{archive-name}
6178 @itemx -f @var{archive-name}
6179 Name the archive to create or operate on. Use in conjunction with
6180 any operation.
6181 @end table
6182
6183 For example, in this @command{tar} command,
6184
6185 @smallexample
6186 $ @kbd{tar -cvf collection.tar blues folk jazz}
6187 @end smallexample
6188
6189 @noindent
6190 @file{collection.tar} is the name of the archive. It must directly
6191 follow the @option{-f} option, since whatever directly follows @option{-f}
6192 @emph{will} end up naming the archive. If you neglect to specify an
6193 archive name, you may end up overwriting a file in the working directory
6194 with the archive you create since @command{tar} will use this file's name
6195 for the archive name.
6196
6197 An archive can be saved as a file in the file system, sent through a
6198 pipe or over a network, or written to an I/O device such as a tape,
6199 floppy disk, or CD write drive.
6200
6201 @cindex Writing new archives
6202 @cindex Archive creation
6203 If you do not name the archive, @command{tar} uses the value of the
6204 environment variable @env{TAPE} as the file name for the archive. If
6205 that is not available, @command{tar} uses a default, compiled-in archive
6206 name, usually that for tape unit zero (ie. @file{/dev/tu00}).
6207
6208 @cindex Standard input and output
6209 @cindex tar to standard input and output
6210 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6211 archive from standard input (when listing or extracting files), or
6212 writes it to standard output (when creating an archive). If you use
6213 @file{-} as an @var{archive-name} when modifying an archive,
6214 @command{tar} reads the original archive from its standard input and
6215 writes the entire new archive to its standard output.
6216
6217 The following example is a convenient way of copying directory
6218 hierarchy from @file{sourcedir} to @file{targetdir}.
6219
6220 @smallexample
6221 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6222 @end smallexample
6223
6224 The @option{-C} option allows to avoid using subshells:
6225
6226 @smallexample
6227 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6228 @end smallexample
6229
6230 In both examples above, the leftmost @command{tar} invocation archives
6231 the contents of @file{sourcedir} to the standard output, while the
6232 rightmost one reads this archive from its standard input and
6233 extracts it. The @option{-p} option tells it to restore permissions
6234 of the extracted files.
6235
6236 @cindex Remote devices
6237 @cindex tar to a remote device
6238 @anchor{remote-dev}
6239 To specify an archive file on a device attached to a remote machine,
6240 use the following:
6241
6242 @smallexample
6243 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6244 @end smallexample
6245
6246 @noindent
6247 @command{tar} will complete the remote connection, if possible, and
6248 prompt you for a username and password. If you use
6249 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6250 will complete the remote connection, if possible, using your username
6251 as the username on the remote machine.
6252
6253 @cindex Local and remote archives
6254 @anchor{local and remote archives}
6255 If the archive file name includes a colon (@samp{:}), then it is assumed
6256 to be a file on another machine. If the archive file is
6257 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6258 host @var{host}. The remote host is accessed using the @command{rsh}
6259 program, with a username of @var{user}. If the username is omitted
6260 (along with the @samp{@@} sign), then your user name will be used.
6261 (This is the normal @command{rsh} behavior.) It is necessary for the
6262 remote machine, in addition to permitting your @command{rsh} access, to
6263 have the @file{rmt} program installed (This command is included in
6264 the @GNUTAR{} distribution and by default is installed under
6265 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6266 installation prefix). If you need to use a file whose name includes a
6267 colon, then the remote tape drive behavior
6268 can be inhibited by using the @option{--force-local} option.
6269
6270 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6271 tries to minimize input and output operations. The Amanda backup
6272 system, when used with @GNUTAR{}, has an initial sizing pass which
6273 uses this feature.
6274
6275 @node Selecting Archive Members
6276 @section Selecting Archive Members
6277 @cindex Specifying files to act on
6278 @cindex Specifying archive members
6279
6280 @dfn{File Name arguments} specify which files in the file system
6281 @command{tar} operates on, when creating or adding to an archive, or which
6282 archive members @command{tar} operates on, when reading or deleting from
6283 an archive. @xref{Operations}.
6284
6285 To specify file names, you can include them as the last arguments on
6286 the command line, as follows:
6287 @smallexample
6288 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6289 @end smallexample
6290
6291 If a file name begins with dash (@samp{-}), precede it with
6292 @option{--add-file} option to prevent it from being treated as an
6293 option.
6294
6295 If you specify a directory name as a file name argument, all the files
6296 in that directory are operated on by @command{tar}.
6297
6298 If you do not specify files, @command{tar} behavior differs depending
6299 on the operation mode as described below:
6300
6301 When @command{tar} is invoked with @option{--create} (@option{-c}),
6302 @command{tar} will stop immediately, reporting the following:
6303
6304 @smallexample
6305 @group
6306 $ @kbd{tar cf a.tar}
6307 tar: Cowardly refusing to create an empty archive
6308 Try `tar --help' or `tar --usage' for more information.
6309 @end group
6310 @end smallexample
6311
6312 If you specify either @option{--list} (@option{-t}) or
6313 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6314 operates on all the archive members in the archive.
6315
6316 If run with @option{--diff} option, tar will compare the archive with
6317 the contents of the current working directory.
6318
6319 If you specify any other operation, @command{tar} does nothing.
6320
6321 By default, @command{tar} takes file names from the command line. However,
6322 there are other ways to specify file or member names, or to modify the
6323 manner in which @command{tar} selects the files or members upon which to
6324 operate. In general, these methods work both for specifying the names
6325 of files and archive members.
6326
6327 @node files
6328 @section Reading Names from a File
6329
6330 @cindex Reading file names from a file
6331 @cindex Lists of file names
6332 @cindex File Name arguments, alternatives
6333 Instead of giving the names of files or archive members on the command
6334 line, you can put the names into a file, and then use the
6335 @option{--files-from=@var{file-of-names}} (@option{-T
6336 @var{file-of-names}}) option to @command{tar}. Give the name of the
6337 file which contains the list of files to include as the argument to
6338 @option{--files-from}. In the list, the file names should be separated by
6339 newlines. You will frequently use this option when you have generated
6340 the list of files to archive with the @command{find} utility.
6341
6342 @table @option
6343 @opindex files-from
6344 @item --files-from=@var{file-name}
6345 @itemx -T @var{file-name}
6346 Get names to extract or create from file @var{file-name}.
6347 @end table
6348
6349 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6350 you specify either @code{--files-from=-} or @code{-T -}), then the file
6351 names are read from standard input.
6352
6353 Unless you are running @command{tar} with @option{--create}, you can not use
6354 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6355 command.
6356
6357 Any number of @option{-T} options can be given in the command line.
6358
6359 The following example shows how to use @command{find} to generate a list of
6360 files smaller than 400K in length and put that list into a file
6361 called @file{small-files}. You can then use the @option{-T} option to
6362 @command{tar} to specify the files from that file, @file{small-files}, to
6363 create the archive @file{little.tgz}. (The @option{-z} option to
6364 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6365 more information.)
6366
6367 @smallexample
6368 $ @kbd{find . -size -400 -print > small-files}
6369 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6370 @end smallexample
6371
6372 @noindent
6373 In the file list given by @option{-T} option, any file name beginning
6374 with @samp{-} character is considered a @command{tar} option and is
6375 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6376 recognized only @option{-C} option in file lists, and only if the
6377 option and its argument occupied two consecutive lines.} For example,
6378 the common use of this feature is to change to another directory by
6379 specifying @option{-C} option:
6380
6381 @smallexample
6382 @group
6383 $ @kbd{cat list}
6384 -C/etc
6385 passwd
6386 hosts
6387 -C/lib
6388 libc.a
6389 $ @kbd{tar -c -f foo.tar --files-from list}
6390 @end group
6391 @end smallexample
6392
6393 @noindent
6394 In this example, @command{tar} will first switch to @file{/etc}
6395 directory and add files @file{passwd} and @file{hosts} to the
6396 archive. Then it will change to @file{/lib} directory and will archive
6397 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6398 contain:
6399
6400 @smallexample
6401 @group
6402 $ @kbd{tar tf foo.tar}
6403 passwd
6404 hosts
6405 libc.a
6406 @end group
6407 @end smallexample
6408
6409 @noindent
6410 @opindex directory, using in @option{--files-from} argument
6411 Notice that the option parsing algorithm used with @option{-T} is
6412 stricter than the one used by shell. Namely, when specifying option
6413 arguments, you should observe the following rules:
6414
6415 @itemize @bullet
6416 @item
6417 When using short (single-letter) option form, its argument must
6418 immediately follow the option letter, without any intervening
6419 whitespace. For example: @code{-Cdir}.
6420
6421 @item
6422 When using long option form, the option argument must be separated
6423 from the option by a single equal sign. No whitespace is allowed on
6424 any side of the equal sign. For example: @code{--directory=dir}.
6425
6426 @item
6427 For both short and long option forms, the option argument can be given
6428 on the next line after the option name, e.g.:
6429
6430 @smallexample
6431 @group
6432 --directory
6433 dir
6434 @end group
6435 @end smallexample
6436
6437 @noindent
6438 and
6439
6440 @smallexample
6441 @group
6442 -C
6443 dir
6444 @end group
6445 @end smallexample
6446 @end itemize
6447
6448 @opindex add-file
6449 If you happen to have a file whose name starts with @samp{-},
6450 precede it with @option{--add-file} option to prevent it from
6451 being recognized as an option. For example: @code{--add-file=--my-file}.
6452
6453 @menu
6454 * nul::
6455 @end menu
6456
6457 @node nul
6458 @subsection @code{NUL} Terminated File Names
6459
6460 @cindex File names, terminated by @code{NUL}
6461 @cindex @code{NUL} terminated file names
6462 The @option{--null} option causes
6463 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6464 to read file names terminated by a @code{NUL} instead of a newline, so
6465 files whose names contain newlines can be archived using
6466 @option{--files-from}.
6467
6468 @table @option
6469 @opindex null
6470 @item --null
6471 Only consider @code{NUL} terminated file names, instead of files that
6472 terminate in a newline.
6473 @end table
6474
6475 The @option{--null} option is just like the one in @acronym{GNU}
6476 @command{xargs} and @command{cpio}, and is useful with the
6477 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6478 @command{tar}, @option{--null} also disables special handling for
6479 file names that begin with dash.
6480
6481 This example shows how to use @command{find} to generate a list of files
6482 larger than 800K in length and put that list into a file called
6483 @file{long-files}. The @option{-print0} option to @command{find} is just
6484 like @option{-print}, except that it separates files with a @code{NUL}
6485 rather than with a newline. You can then run @command{tar} with both the
6486 @option{--null} and @option{-T} options to specify that @command{tar} get the
6487 files from that file, @file{long-files}, to create the archive
6488 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6489 @command{tar} to recognize the @code{NUL} separator between files.
6490
6491 @smallexample
6492 $ @kbd{find . -size +800 -print0 > long-files}
6493 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6494 @end smallexample
6495
6496 @FIXME{say anything else here to conclude the section?}
6497
6498 @node exclude
6499 @section Excluding Some Files
6500 @UNREVISED
6501
6502 @cindex File names, excluding files by
6503 @cindex Excluding files by name and pattern
6504 @cindex Excluding files by file system
6505 To avoid operating on files whose names match a particular pattern,
6506 use the @option{--exclude} or @option{--exclude-from} options.
6507
6508 @table @option
6509 @opindex exclude
6510 @item --exclude=@var{pattern}
6511 Causes @command{tar} to ignore files that match the @var{pattern}.
6512 @end table
6513
6514 @findex exclude
6515 The @option{--exclude=@var{pattern}} option prevents any file or
6516 member whose name matches the shell wildcard (@var{pattern}) from
6517 being operated on.
6518 For example, to create an archive with all the contents of the directory
6519 @file{src} except for files whose names end in @file{.o}, use the
6520 command @samp{tar -cf src.tar --exclude='*.o' src}.
6521
6522 You may give multiple @option{--exclude} options.
6523
6524 @table @option
6525 @opindex exclude-from
6526 @item --exclude-from=@var{file}
6527 @itemx -X @var{file}
6528 Causes @command{tar} to ignore files that match the patterns listed in
6529 @var{file}.
6530 @end table
6531
6532 @findex exclude-from
6533 Use the @option{--exclude-from} option to read a
6534 list of patterns, one per line, from @var{file}; @command{tar} will
6535 ignore files matching those patterns. Thus if @command{tar} is
6536 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6537 single line @file{*.o}, no files whose names end in @file{.o} will be
6538 added to the archive.
6539
6540 @table @option
6541 @opindex exclude-caches
6542 @item --exclude-caches
6543 Causes @command{tar} to ignore directories containing a cache directory tag.
6544 @end table
6545
6546 @findex exclude-caches
6547 When creating an archive, the @option{--exclude-caches} option causes
6548 @command{tar} to exclude all directories that contain a @dfn{cache
6549 directory tag}. A cache directory tag is a short file with the
6550 well-known name @file{CACHEDIR.TAG} and having a standard header
6551 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6552 Various applications write cache directory tags into directories they
6553 use to hold regenerable, non-precious data, so that such data can be
6554 more easily excluded from backups.
6555
6556 @menu
6557 * problems with exclude::
6558 @end menu
6559
6560 @node problems with exclude
6561 @unnumberedsubsec Problems with Using the @code{exclude} Options
6562
6563 @opindex exclude, potential problems with
6564 Some users find @samp{exclude} options confusing. Here are some common
6565 pitfalls:
6566
6567 @itemize @bullet
6568 @item
6569 The main operating mode of @command{tar} does not act on a path name
6570 explicitly listed on the command line if one of its file name
6571 components is excluded. In the example above, if
6572 you create an archive and exclude files that end with @samp{*.o}, but
6573 explicitly name the file @samp{dir.o/foo} after all the options have been
6574 listed, @samp{dir.o/foo} will be excluded from the archive.
6575
6576 @item
6577 You can sometimes confuse the meanings of @option{--exclude} and
6578 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6579 to be excluded are given as a pattern on the command line. Use
6580 @option{--exclude-from} to introduce the name of a file which contains
6581 a list of patterns, one per line; each of these patterns can exclude
6582 zero, one, or many files.
6583
6584 @item
6585 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6586 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6587 like @samp{*}. If you do not do this, the shell might expand the
6588 @samp{*} itself using files at hand, so @command{tar} might receive a
6589 list of files instead of one pattern, or none at all, making the
6590 command somewhat illegal. This might not correspond to what you want.
6591
6592 For example, write:
6593
6594 @smallexample
6595 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6596 @end smallexample
6597
6598 @noindent
6599 rather than:
6600
6601 @smallexample
6602 # @emph{Wrong!}
6603 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6604 @end smallexample
6605
6606 @item
6607 You must use use shell syntax, or globbing, rather than @code{regexp}
6608 syntax, when using exclude options in @command{tar}. If you try to use
6609 @code{regexp} syntax to describe files to be excluded, your command
6610 might fail.
6611
6612 @item
6613 @FIXME{The change in semantics must have occurred before 1.11,
6614 so I doubt if it is worth mentioning at all. Anyway, should at
6615 least specify in which version the semantics changed.}
6616 In earlier versions of @command{tar}, what is now the
6617 @option{--exclude-from} option was called @option{--exclude} instead.
6618 Now, @option{--exclude} applies to patterns listed on the command
6619 line and @option{--exclude-from} applies to patterns listed in a
6620 file.
6621
6622 @end itemize
6623
6624 @node Wildcards
6625 @section Wildcards Patterns and Matching
6626
6627 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6628 @samp{*} or @samp{?} for example, are replaced and expanded into all
6629 existing files matching the given pattern. @GNUTAR{} can use wildcard
6630 patterns for matching (or globbing) archive members when extracting
6631 from or listing an archive. Wildcard patterns are also used for
6632 verifying volume labels of @command{tar} archives. This section has the
6633 purpose of explaining wildcard syntax for @command{tar}.
6634
6635 @FIXME{the next few paragraphs need work.}
6636
6637 A @var{pattern} should be written according to shell syntax, using wildcard
6638 characters to effect globbing. Most characters in the pattern stand
6639 for themselves in the matched string, and case is significant: @samp{a}
6640 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6641 pattern matches any single character in the matched string. The character
6642 @samp{*} in the pattern matches zero, one, or more single characters in
6643 the matched string. The character @samp{\} says to take the following
6644 character of the pattern @emph{literally}; it is useful when one needs to
6645 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6646
6647 The character @samp{[}, up to the matching @samp{]}, introduces a character
6648 class. A @dfn{character class} is a list of acceptable characters
6649 for the next single character of the matched string. For example,
6650 @samp{[abcde]} would match any of the first five letters of the alphabet.
6651 Note that within a character class, all of the ``special characters''
6652 listed above other than @samp{\} lose their special meaning; for example,
6653 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6654 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6655 the characters @samp{-} and @samp{]} must either come @emph{first} or
6656 @emph{last} in a character class.)
6657
6658 @cindex Excluding characters from a character class
6659 @cindex Character class, excluding characters from
6660 If the first character of the class after the opening @samp{[}
6661 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6662 Rather than listing character to match, it lists those characters which
6663 are @emph{forbidden} as the next single character of the matched string.
6664
6665 Other characters of the class stand for themselves. The special
6666 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6667 letters, is meant to represent all characters between @var{a} and
6668 @var{e}, inclusive.
6669
6670 @FIXME{need to add a sentence or so here to make this clear for those
6671 who don't have dan around.}
6672
6673 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6674 special for wildcard matches. However, if a pattern completely matches
6675 a directory prefix of a matched string, then it matches the full matched
6676 string: thus, excluding a directory also excludes all the files beneath it.
6677
6678 @menu
6679 * controlling pattern-matching::
6680 @end menu
6681
6682 @node controlling pattern-matching
6683 @unnumberedsubsec Controlling Pattern-Matching
6684
6685 For the purposes of this section, we call @dfn{exclusion members} all
6686 member names obtained while processing @option{--exclude} and
6687 @option{--exclude-from} options, and @dfn{inclusion members} those
6688 member names that were given in the command line or read from the file
6689 specified with @option{--files-from} option.
6690
6691 These two pairs of member lists are used in the following operations:
6692 @option{--diff}, @option{--extract}, @option{--list},
6693 @option{--update}.
6694
6695 There are no inclusion members in create mode (@option{--create} and
6696 @option{--append}), since in this mode the names obtained from the
6697 command line refer to @emph{files}, not archive members.
6698
6699 By default, inclusion members are compared with archive members
6700 literally @footnote{Notice that earlier @GNUTAR{} versions used
6701 globbing for inclusion members, which contradicted to UNIX98
6702 specification and was not documented. @xref{Changes}, for more
6703 information on this and other changes} and exclusion members are
6704 treated as globbing patterns. For example:
6705
6706 @smallexample
6707 @group
6708 $ @kbd{tar tf foo.tar}
6709 a.c
6710 b.c
6711 a.txt
6712 [remarks]
6713 # @i{Member names are used verbatim:}
6714 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6715 [remarks]
6716 # @i{Exclude member names are globbed:}
6717 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6718 a.txt
6719 [remarks]
6720 @end group
6721 @end smallexample
6722
6723 This behavior can be altered by using the following options:
6724
6725 @table @option
6726 @opindex wildcards
6727 @item --wildcards
6728 Treat all member names as wildcards.
6729
6730 @opindex no-wildcards
6731 @item --no-wildcards
6732 Treat all member names as literal strings.
6733 @end table
6734
6735 Thus, to extract files whose names end in @samp{.c}, you can use:
6736
6737 @smallexample
6738 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6739 a.c
6740 b.c
6741 @end smallexample
6742
6743 @noindent
6744 Notice quoting of the pattern to prevent the shell from interpreting
6745 it.
6746
6747 The effect of @option{--wildcards} option is cancelled by
6748 @option{--no-wildcards}. This can be used to pass part of
6749 the command line arguments verbatim and other part as globbing
6750 patterns. For example, the following invocation:
6751
6752 @smallexample
6753 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6754 @end smallexample
6755
6756 @noindent
6757 instructs @command{tar} to extract from @file{foo.tar} all files whose
6758 names end in @samp{.txt} and the file named @file{[remarks]}.
6759
6760 Normally, a pattern matches a name if an initial subsequence of the
6761 name's components matches the pattern, where @samp{*}, @samp{?}, and
6762 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6763 and wildcards can match @samp{/}.
6764
6765 Other than optionally stripping leading @samp{/} from names
6766 (@pxref{absolute}), patterns and names are used as-is. For
6767 example, trailing @samp{/} is not trimmed from a user-specified name
6768 before deciding whether to exclude it.
6769
6770 However, this matching procedure can be altered by the options listed
6771 below. These options accumulate. For example:
6772
6773 @smallexample
6774 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6775 @end smallexample
6776
6777 ignores case when excluding @samp{makefile}, but not when excluding
6778 @samp{readme}.
6779
6780 @table @option
6781 @opindex anchored
6782 @opindex no-anchored
6783 @item --anchored
6784 @itemx --no-anchored
6785 If anchored, a pattern must match an initial subsequence
6786 of the name's components. Otherwise, the pattern can match any
6787 subsequence. Default is @option{--no-anchored} for exclusion members
6788 and @option{--anchored} inclusion members.
6789
6790 @opindex ignore-case
6791 @opindex no-ignore-case
6792 @item --ignore-case
6793 @itemx --no-ignore-case
6794 When ignoring case, upper-case patterns match lower-case names and vice versa.
6795 When not ignoring case (the default), matching is case-sensitive.
6796
6797 @opindex wildcards-match-slash
6798 @opindex no-wildcards-match-slash
6799 @item --wildcards-match-slash
6800 @itemx --no-wildcards-match-slash
6801 When wildcards match slash (the default for exclusion members), a
6802 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6803 name. Otherwise, @samp{/} is matched only by @samp{/}.
6804
6805 @end table
6806
6807 The @option{--recursion} and @option{--no-recursion} options
6808 (@pxref{recurse}) also affect how member patterns are interpreted. If
6809 recursion is in effect, a pattern matches a name if it matches any of
6810 the name's parent directories.
6811
6812 The following table summarizes pattern-matching default values:
6813
6814 @multitable @columnfractions .3 .7
6815 @headitem Members @tab Default settings
6816 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6817 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6818 @end multitable
6819
6820 @node after
6821 @section Operating Only on New Files
6822 @UNREVISED
6823
6824 @cindex Excluding file by age
6825 @cindex Data Modification time, excluding files by
6826 @cindex Modification time, excluding files by
6827 @cindex Age, excluding files by
6828 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
6829 @option{-N @var{date}}) option causes @command{tar} to only work on
6830 files whose data modification or status change times are newer than
6831 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
6832 it is taken to be a file name; the data modification time of that file
6833 is used as the date. If you use this option when creating or appending
6834 to an archive, the archive will only include new files. If you use
6835 @option{--after-date} when extracting an archive, @command{tar} will
6836 only extract files newer than the @var{date} you specify.
6837
6838 If you only want @command{tar} to make the date comparison based on
6839 modification of the file's data (rather than status
6840 changes), then use the @option{--newer-mtime=@var{date}} option.
6841
6842 You may use these options with any operation. Note that these options
6843 differ from the @option{--update} (@option{-u}) operation in that they
6844 allow you to specify a particular date against which @command{tar} can
6845 compare when deciding whether or not to archive the files.
6846
6847 @table @option
6848 @opindex after-date
6849 @opindex newer
6850 @item --after-date=@var{date}
6851 @itemx --newer=@var{date}
6852 @itemx -N @var{date}
6853 Only store files newer than @var{date}.
6854
6855 Acts on files only if their data modification or status change times are
6856 later than @var{date}. Use in conjunction with any operation.
6857
6858 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
6859 name; the data modification time of that file is used as the date.
6860
6861 @opindex newer-mtime
6862 @item --newer-mtime=@var{date}
6863 Acts like @option{--after-date}, but only looks at data modification times.
6864 @end table
6865
6866 These options limit @command{tar} to operate only on files which have
6867 been modified after the date specified. A file's status is considered to have
6868 changed if its contents have been modified, or if its owner,
6869 permissions, and so forth, have been changed. (For more information on
6870 how to specify a date, see @ref{Date input formats}; remember that the
6871 entire date argument must be quoted if it contains any spaces.)
6872
6873 Gurus would say that @option{--after-date} tests both the data
6874 modification time (@code{mtime}, the time the contents of the file
6875 were last modified) and the status change time (@code{ctime}, the time
6876 the file's status was last changed: owner, permissions, etc.@:)
6877 fields, while @option{--newer-mtime} tests only the @code{mtime}
6878 field.
6879
6880 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
6881 @code{ctime} and processes the file if either one is more recent than
6882 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
6883 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
6884 contents of the file were looked at).
6885
6886 Date specifiers can have embedded spaces. Because of this, you may need
6887 to quote date arguments to keep the shell from parsing them as separate
6888 arguments. For example, the following command will add to the archive
6889 all the files modified less than two days ago:
6890
6891 @smallexample
6892 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
6893 @end smallexample
6894
6895 @quotation
6896 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
6897 should not be used for incremental backups. @xref{Incremental Dumps},
6898 for proper way of creating incremental backups.
6899 @end quotation
6900
6901 @node recurse
6902 @section Descending into Directories
6903 @UNREVISED
6904 @cindex Avoiding recursion in directories
6905 @cindex Descending directories, avoiding
6906 @cindex Directories, avoiding recursion
6907 @cindex Recursion in directories, avoiding
6908
6909 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
6910
6911 Usually, @command{tar} will recursively explore all directories (either
6912 those given on the command line or through the @option{--files-from}
6913 option) for the various files they contain. However, you may not always
6914 want @command{tar} to act this way.
6915
6916 @opindex no-recursion
6917 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
6918 into specified directories. If you specify @option{--no-recursion}, you can
6919 use the @command{find} utility for hunting through levels of directories to
6920 construct a list of file names which you could then pass to @command{tar}.
6921 @command{find} allows you to be more selective when choosing which files to
6922 archive; see @ref{files}, for more information on using @command{find} with
6923 @command{tar}, or look.
6924
6925 @table @option
6926 @item --no-recursion
6927 Prevents @command{tar} from recursively descending directories.
6928
6929 @opindex recursion
6930 @item --recursion
6931 Requires @command{tar} to recursively descend directories.
6932 This is the default.
6933 @end table
6934
6935 When you use @option{--no-recursion}, @GNUTAR{} grabs
6936 directory entries themselves, but does not descend on them
6937 recursively. Many people use @command{find} for locating files they
6938 want to back up, and since @command{tar} @emph{usually} recursively
6939 descends on directories, they have to use the @samp{@w{-not -type d}}
6940 test in their @command{find} invocation (@pxref{Type, Type, Type test,
6941 find, Finding Files}), as they usually do not want all the files in a
6942 directory. They then use the @option{--files-from} option to archive
6943 the files located via @command{find}.
6944
6945 The problem when restoring files archived in this manner is that the
6946 directories themselves are not in the archive; so the
6947 @option{--same-permissions} (@option{--preserve-permissions},
6948 @option{-p}) option does not affect them---while users might really
6949 like it to. Specifying @option{--no-recursion} is a way to tell
6950 @command{tar} to grab only the directory entries given to it, adding
6951 no new files on its own. To summarize, if you use @command{find} to
6952 create a list of files to be stored in an archive, use it as follows:
6953
6954 @smallexample
6955 @group
6956 $ @kbd{find @var{dir} @var{tests} | \
6957 tar -cf @var{archive} -T - --no-recursion}
6958 @end group
6959 @end smallexample
6960
6961 The @option{--no-recursion} option also applies when extracting: it
6962 causes @command{tar} to extract only the matched directory entries, not
6963 the files under those directories.
6964
6965 The @option{--no-recursion} option also affects how globbing patterns
6966 are interpreted (@pxref{controlling pattern-matching}).
6967
6968 The @option{--no-recursion} and @option{--recursion} options apply to
6969 later options and operands, and can be overridden by later occurrences
6970 of @option{--no-recursion} and @option{--recursion}. For example:
6971
6972 @smallexample
6973 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
6974 @end smallexample
6975
6976 @noindent
6977 creates an archive with one entry for @file{grape}, and the recursive
6978 contents of @file{grape/concord}, but no entries under @file{grape}
6979 other than @file{grape/concord}.
6980
6981 @node one
6982 @section Crossing File System Boundaries
6983 @cindex File system boundaries, not crossing
6984 @UNREVISED
6985
6986 @command{tar} will normally automatically cross file system boundaries in
6987 order to archive files which are part of a directory tree. You can
6988 change this behavior by running @command{tar} and specifying
6989 @option{--one-file-system}. This option only affects files that are
6990 archived because they are in a directory that is being archived;
6991 @command{tar} will still archive files explicitly named on the command line
6992 or through @option{--files-from}, regardless of where they reside.
6993
6994 @table @option
6995 @opindex one-file-system
6996 @item --one-file-system
6997 Prevents @command{tar} from crossing file system boundaries when
6998 archiving. Use in conjunction with any write operation.
6999 @end table
7000
7001 The @option{--one-file-system} option causes @command{tar} to modify its
7002 normal behavior in archiving the contents of directories. If a file in
7003 a directory is not on the same file system as the directory itself, then
7004 @command{tar} will not archive that file. If the file is a directory
7005 itself, @command{tar} will not archive anything beneath it; in other words,
7006 @command{tar} will not cross mount points.
7007
7008 This option is useful for making full or incremental archival backups of
7009 a file system. If this option is used in conjunction with
7010 @option{--verbose} (@option{-v}), files that are excluded are
7011 mentioned by name on the standard error.
7012
7013 @menu
7014 * directory:: Changing Directory
7015 * absolute:: Absolute File Names
7016 @end menu
7017
7018 @node directory
7019 @subsection Changing the Working Directory
7020 @UNREVISED
7021
7022 @FIXME{need to read over this node now for continuity; i've switched
7023 things around some.}
7024
7025 @cindex Changing directory mid-stream
7026 @cindex Directory, changing mid-stream
7027 @cindex Working directory, specifying
7028 To change the working directory in the middle of a list of file names,
7029 either on the command line or in a file specified using
7030 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7031 This will change the working directory to the specified directory
7032 after that point in the list.
7033
7034 @table @option
7035 @opindex directory
7036 @item --directory=@var{directory}
7037 @itemx -C @var{directory}
7038 Changes the working directory in the middle of a command line.
7039 @end table
7040
7041 For example,
7042
7043 @smallexample
7044 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7045 @end smallexample
7046
7047 @noindent
7048 will place the files @file{grape} and @file{prune} from the current
7049 directory into the archive @file{jams.tar}, followed by the file
7050 @file{cherry} from the directory @file{food}. This option is especially
7051 useful when you have several widely separated files that you want to
7052 store in the same archive.
7053
7054 Note that the file @file{cherry} is recorded in the archive under the
7055 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7056 archive will contain three files that all appear to have come from the
7057 same directory; if the archive is extracted with plain @samp{tar
7058 --extract}, all three files will be written in the current directory.
7059
7060 Contrast this with the command,
7061
7062 @smallexample
7063 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7064 @end smallexample
7065
7066 @noindent
7067 which records the third file in the archive under the name
7068 @file{red/cherry} so that, if the archive is extracted using
7069 @samp{tar --extract}, the third file will be written in a subdirectory
7070 named @file{orange-colored}.
7071
7072 You can use the @option{--directory} option to make the archive
7073 independent of the original name of the directory holding the files.
7074 The following command places the files @file{/etc/passwd},
7075 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7076 @file{foo.tar}:
7077
7078 @smallexample
7079 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7080 @end smallexample
7081
7082 @noindent
7083 However, the names of the archive members will be exactly what they were
7084 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7085 They will not appear to be related by file name to the original
7086 directories where those files were located.
7087
7088 Note that @option{--directory} options are interpreted consecutively. If
7089 @option{--directory} specifies a relative file name, it is interpreted
7090 relative to the then current directory, which might not be the same as
7091 the original current working directory of @command{tar}, due to a previous
7092 @option{--directory} option.
7093
7094 When using @option{--files-from} (@pxref{files}), you can put various
7095 @command{tar} options (including @option{-C}) in the file list. Notice,
7096 however, that in this case the option and its argument may not be
7097 separated by whitespace. If you use short option, its argument must
7098 either follow the option letter immediately, without any intervening
7099 whitespace, or occupy the next line. Otherwise, if you use long
7100 option, separate its argument by an equal sign.
7101
7102 For instance, the file list for the above example will be:
7103
7104 @smallexample
7105 @group
7106 -C
7107 /etc
7108 passwd
7109 hosts
7110 -C
7111 /lib
7112 libc.a
7113 @end group
7114 @end smallexample
7115
7116 @noindent
7117 To use it, you would invoke @command{tar} as follows:
7118
7119 @smallexample
7120 $ @kbd{tar -c -f foo.tar --files-from list}
7121 @end smallexample
7122
7123 Notice also that you can only use the short option variant in the file
7124 list, i.e., always use @option{-C}, not @option{--directory}.
7125
7126 The interpretation of @option{--directory} is disabled by
7127 @option{--null} option.
7128
7129 @node absolute
7130 @subsection Absolute File Names
7131 @UNREVISED
7132
7133 @table @option
7134 @opindex absolute-names
7135 @item --absolute-names
7136 @itemx -P
7137 Do not strip leading slashes from file names, and permit file names
7138 containing a @file{..} file name component.
7139 @end table
7140
7141 By default, @GNUTAR{} drops a leading @samp{/} on
7142 input or output, and complains about file names containing a @file{..}
7143 component. This option turns off this behavior.
7144
7145 When @command{tar} extracts archive members from an archive, it strips any
7146 leading slashes (@samp{/}) from the member name. This causes absolute
7147 member names in the archive to be treated as relative file names. This
7148 allows you to have such members extracted wherever you want, instead of
7149 being restricted to extracting the member in the exact directory named
7150 in the archive. For example, if the archive member has the name
7151 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7152 really @file{etc/passwd}.
7153
7154 File names containing @file{..} can cause problems when extracting, so
7155 @command{tar} normally warns you about such files when creating an
7156 archive, and rejects attempts to extracts such files.
7157
7158 Other @command{tar} programs do not do this. As a result, if you
7159 create an archive whose member names start with a slash, they will be
7160 difficult for other people with a non-@GNUTAR{}
7161 program to use. Therefore, @GNUTAR{} also strips
7162 leading slashes from member names when putting members into the
7163 archive. For example, if you ask @command{tar} to add the file
7164 @file{/bin/ls} to an archive, it will do so, but the member name will
7165 be @file{bin/ls}.@footnote{A side effect of this is that when
7166 @option{--create} is used with @option{--verbose} the resulting output
7167 is not, generally speaking, the same as the one you'd get running
7168 @kbd{tar --list} command. This may be important if you use some
7169 scripts for comparing both outputs. @xref{listing member and file names},
7170 for the information on how to handle this case.}
7171
7172 If you use the @option{--absolute-names} (@option{-P}) option,
7173 @command{tar} will do none of these transformations.
7174
7175 To archive or extract files relative to the root directory, specify
7176 the @option{--absolute-names} (@option{-P}) option.
7177
7178 Normally, @command{tar} acts on files relative to the working
7179 directory---ignoring superior directory names when archiving, and
7180 ignoring leading slashes when extracting.
7181
7182 When you specify @option{--absolute-names} (@option{-P}),
7183 @command{tar} stores file names including all superior directory
7184 names, and preserves leading slashes. If you only invoked
7185 @command{tar} from the root directory you would never need the
7186 @option{--absolute-names} option, but using this option
7187 may be more convenient than switching to root.
7188
7189 @FIXME{Should be an example in the tutorial/wizardry section using this
7190 to transfer files between systems.}
7191
7192 @FIXME{Is write access an issue?}
7193
7194 @table @option
7195 @item --absolute-names
7196 Preserves full file names (including superior directory names) when
7197 archiving files. Preserves leading slash when extracting files.
7198
7199 @end table
7200
7201 @FIXME{this is still horrible; need to talk with dan on monday.}
7202
7203 @command{tar} prints out a message about removing the @samp{/} from
7204 file names. This message appears once per @GNUTAR{}
7205 invocation. It represents something which ought to be told; ignoring
7206 what it means can cause very serious surprises, later.
7207
7208 Some people, nevertheless, do not want to see this message. Wanting to
7209 play really dangerously, one may of course redirect @command{tar} standard
7210 error to the sink. For example, under @command{sh}:
7211
7212 @smallexample
7213 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7214 @end smallexample
7215
7216 @noindent
7217 Another solution, both nicer and simpler, would be to change to
7218 the @file{/} directory first, and then avoid absolute notation.
7219 For example:
7220
7221 @smallexample
7222 $ @kbd{(cd / && tar -c -f archive.tar home)}
7223 # @i{or}:
7224 $ @kbd{tar -c -f archive.tar -C / home}
7225 @end smallexample
7226
7227 @include getdate.texi
7228
7229 @node Formats
7230 @chapter Controlling the Archive Format
7231
7232 @cindex Tar archive formats
7233 Due to historical reasons, there are several formats of tar archives.
7234 All of them are based on the same principles, but have some subtle
7235 differences that often make them incompatible with each other.
7236
7237 GNU tar is able to create and handle archives in a variety of formats.
7238 The most frequently used formats are (in alphabetical order):
7239
7240 @table @asis
7241 @item gnu
7242 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7243 from an early @acronym{POSIX} standard, adding some improvements such as
7244 sparse file handling and incremental archives. Unfortunately these
7245 features were implemented in a way incompatible with other archive
7246 formats.
7247
7248 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7249 length.
7250
7251 @item oldgnu
7252 Format used by @GNUTAR{} of versions prior to 1.12.
7253
7254 @item v7
7255 Archive format, compatible with the V7 implementation of tar. This
7256 format imposes a number of limitations. The most important of them
7257 are:
7258
7259 @enumerate
7260 @item The maximum length of a file name is limited to 99 characters.
7261 @item The maximum length of a symbolic link is limited to 99 characters.
7262 @item It is impossible to store special files (block and character
7263 devices, fifos etc.)
7264 @item Maximum value of user or group ID is limited to 2097151 (7777777
7265 octal)
7266 @item V7 archives do not contain symbolic ownership information (user
7267 and group name of the file owner).
7268 @end enumerate
7269
7270 This format has traditionally been used by Automake when producing
7271 Makefiles. This practice will change in the future, in the meantime,
7272 however this means that projects containing filenames more than 99
7273 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7274 Automake prior to 1.9.
7275
7276 @item ustar
7277 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7278 symbolic ownership information. It is also able to store
7279 special files. However, it imposes several restrictions as well:
7280
7281 @enumerate
7282 @item The maximum length of a file name is limited to 256 characters,
7283 provided that the filename can be split at directory separator in
7284 two parts, first of them being at most 155 bytes long. So, in most
7285 cases the maximum file name length will be shorter than 256
7286 characters.
7287 @item The maximum length of a symbolic link name is limited to
7288 100 characters.
7289 @item Maximum size of a file the archive is able to accomodate
7290 is 8GB
7291 @item Maximum value of UID/GID is 2097151.
7292 @item Maximum number of bits in device major and minor numbers is 21.
7293 @end enumerate
7294
7295 @item star
7296 Format used by J@"org Schilling @command{star}
7297 implementation. @GNUTAR{} is able to read @samp{star} archives but
7298 currently does not produce them.
7299
7300 @item posix
7301 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7302 most flexible and feature-rich format. It does not impose any
7303 restrictions on file sizes or filename lengths. This format is quite
7304 recent, so not all tar implementations are able to handle it properly.
7305 However, this format is designed in such a way that any tar
7306 implementation able to read @samp{ustar} archives will be able to read
7307 most @samp{posix} archives as well, with the only exception that any
7308 additional information (such as long file names etc.) will in such
7309 case be extracted as plain text files along with the files it refers to.
7310
7311 This archive format will be the default format for future versions
7312 of @GNUTAR{}.
7313
7314 @end table
7315
7316 The following table summarizes the limitations of each of these
7317 formats:
7318
7319 @multitable @columnfractions .10 .20 .20 .20 .20
7320 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7321 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7322 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7323 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7324 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7325 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7326 @end multitable
7327
7328 The default format for @GNUTAR{} is defined at compilation
7329 time. You may check it by running @command{tar --help}, and examining
7330 the last lines of its output. Usually, @GNUTAR{} is configured
7331 to create archives in @samp{gnu} format, however, future version will
7332 switch to @samp{posix}.
7333
7334 @menu
7335 * Portability:: Making @command{tar} Archives More Portable
7336 * Compression:: Using Less Space through Compression
7337 * Attributes:: Handling File Attributes
7338 * Standard:: The Standard Format
7339 * Extensions:: @acronym{GNU} Extensions to the Archive Format
7340 * cpio:: Comparison of @command{tar} and @command{cpio}
7341 @end menu
7342
7343 @node Portability
7344 @section Making @command{tar} Archives More Portable
7345
7346 Creating a @command{tar} archive on a particular system that is meant to be
7347 useful later on many other machines and with other versions of @command{tar}
7348 is more challenging than you might think. @command{tar} archive formats
7349 have been evolving since the first versions of Unix. Many such formats
7350 are around, and are not always compatible with each other. This section
7351 discusses a few problems, and gives some advice about making @command{tar}
7352 archives more portable.
7353
7354 One golden rule is simplicity. For example, limit your @command{tar}
7355 archives to contain only regular files and directories, avoiding
7356 other kind of special files. Do not attempt to save sparse files or
7357 contiguous files as such. Let's discuss a few more problems, in turn.
7358
7359 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
7360 archives and archive labels) in GNU and PAX formats.}
7361
7362 @menu
7363 * Portable Names:: Portable Names
7364 * dereference:: Symbolic Links
7365 * old:: Old V7 Archives
7366 * ustar:: Ustar Archives
7367 * gnu:: GNU and old GNU format archives.
7368 * posix:: @acronym{POSIX} archives
7369 * Checksumming:: Checksumming Problems
7370 * Large or Negative Values:: Large files, negative time stamps, etc.
7371 @end menu
7372
7373 @node Portable Names
7374 @subsection Portable Names
7375
7376 Use portable file and member names. A name is portable if it contains
7377 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
7378 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
7379 contain @samp{/-}. Avoid deep directory nesting. For portability to
7380 old Unix hosts, limit your file name components to 14 characters or
7381 less.
7382
7383 If you intend to have your @command{tar} archives to be read under
7384 MSDOS, you should not rely on case distinction for file names, and you
7385 might use the @acronym{GNU} @command{doschk} program for helping you
7386 further diagnosing illegal MSDOS names, which are even more limited
7387 than System V's.
7388
7389 @node dereference
7390 @subsection Symbolic Links
7391 @cindex File names, using symbolic links
7392 @cindex Symbolic link as file name
7393
7394 @opindex dereference
7395 Normally, when @command{tar} archives a symbolic link, it writes a
7396 block to the archive naming the target of the link. In that way, the
7397 @command{tar} archive is a faithful record of the file system contents.
7398 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
7399 @command{tar} to archive the files symbolic links point to, instead of
7400 the links themselves. When this option is used, when @command{tar}
7401 encounters a symbolic link, it will archive the linked-to file,
7402 instead of simply recording the presence of a symbolic link.
7403
7404 The name under which the file is stored in the file system is not
7405 recorded in the archive. To record both the symbolic link name and
7406 the file name in the system, archive the file under both names. If
7407 all links were recorded automatically by @command{tar}, an extracted file
7408 might be linked to a file name that no longer exists in the file
7409 system.
7410
7411 If a linked-to file is encountered again by @command{tar} while creating
7412 the same archive, an entire second copy of it will be stored. (This
7413 @emph{might} be considered a bug.)
7414
7415 So, for portable archives, do not archive symbolic links as such,
7416 and use @option{--dereference} (@option{-h}): many systems do not support
7417 symbolic links, and moreover, your distribution might be unusable if
7418 it contains unresolved symbolic links.
7419
7420 @node old
7421 @subsection Old V7 Archives
7422 @cindex Format, old style
7423 @cindex Old style format
7424 @cindex Old style archives
7425 @cindex v7 archive format
7426
7427 Certain old versions of @command{tar} cannot handle additional
7428 information recorded by newer @command{tar} programs. To create an
7429 archive in V7 format (not ANSI), which can be read by these old
7430 versions, specify the @option{--format=v7} option in
7431 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
7432 accepts @option{--portability} or @samp{op-old-archive} for this
7433 option). When you specify it,
7434 @command{tar} leaves out information about directories, pipes, fifos,
7435 contiguous files, and device files, and specifies file ownership by
7436 group and user IDs instead of group and user names.
7437
7438 When updating an archive, do not use @option{--format=v7}
7439 unless the archive was created using this option.
7440
7441 In most cases, a @emph{new} format archive can be read by an @emph{old}
7442 @command{tar} program without serious trouble, so this option should
7443 seldom be needed. On the other hand, most modern @command{tar}s are
7444 able to read old format archives, so it might be safer for you to
7445 always use @option{--format=v7} for your distributions.
7446
7447 @node ustar
7448 @subsection Ustar Archive Format
7449
7450 @cindex ustar archive format
7451 Archive format defined by @acronym{POSIX}.1-1988 specification is called
7452 @code{ustar}. Although it is more flexible than the V7 format, it
7453 still has many restrictions (@xref{Formats,ustar}, for the detailed
7454 description of @code{ustar} format). Along with V7 format,
7455 @code{ustar} format is a good choice for archives intended to be read
7456 with other implementations of @command{tar}.
7457
7458 To create archive in @code{ustar} format, use @option{--format=ustar}
7459 option in conjunction with the @option{--create} (@option{-c}).
7460
7461 @node gnu
7462 @subsection @acronym{GNU} and old @GNUTAR{} format
7463
7464 @cindex GNU archive format
7465 @cindex Old GNU archive format
7466 @GNUTAR{} was based on an early draft of the
7467 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
7468 @command{tar}, such as the support for file names longer than 100
7469 characters, use portions of the @command{tar} header record which were
7470 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
7471 @acronym{POSIX} have allocated the same parts of the header record for
7472 other purposes. As a result, @GNUTAR{} format is
7473 incompatible with the current @acronym{POSIX} specification, and with
7474 @command{tar} programs that follow it.
7475
7476 In the majority of cases, @command{tar} will be configured to create
7477 this format by default. This will change in the future releases, since
7478 we plan to make @samp{posix} format the default.
7479
7480 To force creation a @GNUTAR{} archive, use option
7481 @option{--format=gnu}.
7482
7483 @node posix
7484 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
7485
7486 @cindex POSIX archive format
7487 @cindex PAX archive format
7488 The version @value{VERSION} of @GNUTAR{} is able
7489 to read and create archives conforming to @acronym{POSIX.1-2001} standard.
7490
7491 A @acronym{POSIX} conformant archive will be created if @command{tar}
7492 was given @option{--format=posix} option.
7493
7494 @node Checksumming
7495 @subsection Checksumming Problems
7496
7497 SunOS and HP-UX @command{tar} fail to accept archives created using
7498 @GNUTAR{} and containing non-ASCII file names, that
7499 is, file names having characters with the eight bit set, because they
7500 use signed checksums, while @GNUTAR{} uses unsigned
7501 checksums while creating archives, as per @acronym{POSIX} standards. On
7502 reading, @GNUTAR{} computes both checksums and
7503 accept any. It is somewhat worrying that a lot of people may go
7504 around doing backup of their files using faulty (or at least
7505 non-standard) software, not learning about it until it's time to
7506 restore their missing files with an incompatible file extractor, or
7507 vice versa.
7508
7509 @GNUTAR{} compute checksums both ways, and accept
7510 any on read, so @acronym{GNU} tar can read Sun tapes even with their
7511 wrong checksums. @GNUTAR{} produces the standard
7512 checksum, however, raising incompatibilities with Sun. That is to
7513 say, @GNUTAR{} has not been modified to
7514 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
7515 I've been told that more recent Sun @command{tar} now read standard
7516 archives, so maybe Sun did a similar patch, after all?
7517
7518 The story seems to be that when Sun first imported @command{tar}
7519 sources on their system, they recompiled it without realizing that
7520 the checksums were computed differently, because of a change in
7521 the default signing of @code{char}'s in their compiler. So they
7522 started computing checksums wrongly. When they later realized their
7523 mistake, they merely decided to stay compatible with it, and with
7524 themselves afterwards. Presumably, but I do not really know, HP-UX
7525 has chosen that their @command{tar} archives to be compatible with Sun's.
7526 The current standards do not favor Sun @command{tar} format. In any
7527 case, it now falls on the shoulders of SunOS and HP-UX users to get
7528 a @command{tar} able to read the good archives they receive.
7529
7530 @node Large or Negative Values
7531 @subsection Large or Negative Values
7532 @cindex large values
7533 @cindex future time stamps
7534 @cindex negative time stamps
7535 @UNREVISED{}
7536
7537 The above sections suggest to use @samp{oldest possible} archive
7538 format if in doubt. However, sometimes it is not possible. If you
7539 attempt to archive a file whose metadata cannot be represented using
7540 required format, @GNUTAR{} will print error message and ignore such a
7541 file. You will than have to switch to a format that is able to
7542 handle such values. The format summary table (@pxref{Formats}) will
7543 help you to do so.
7544
7545 In particular, when trying to archive files larger than 8GB or with
7546 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
7547 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
7548 @acronym{POSIX} archive formats. When considering which format to
7549 choose, bear in mind that the @acronym{GNU} format uses
7550 two's-complement base-256 notation to store values that do not fit
7551 into standard @acronym{ustar} range. Such archives can generally be
7552 read only by a @GNUTAR{} implementation. Moreover, they sometimes
7553 cannot be correctly restored on another hosts even by @GNUTAR{}. For
7554 example, using two's complement representation for negative time
7555 stamps that assumes a signed 32-bit @code{time_t} generates archives
7556 that are not portable to hosts with differing @code{time_t}
7557 representations.
7558
7559 On the other hand, @acronym{POSIX} archives, generally speaking, can
7560 be extracted by any tar implementation that understands older
7561 @acronym{ustar} format. The only exception are files larger than 8GB.
7562
7563 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
7564 POSIX-aware tars.}
7565
7566 @node Compression
7567 @section Using Less Space through Compression
7568
7569 @menu
7570 * gzip:: Creating and Reading Compressed Archives
7571 * sparse:: Archiving Sparse Files
7572 @end menu
7573
7574 @node gzip
7575 @subsection Creating and Reading Compressed Archives
7576 @cindex Compressed archives
7577 @cindex Storing archives in compressed format
7578
7579 @GNUTAR{} is able to create and read compressed archives. It supports
7580 @command{gzip} and @command{bzip2} compression programs. For backward
7581 compatibilty, it also supports @command{compress} command, although
7582 we strongly recommend against using it, since there is a patent
7583 covering the algorithm it uses and you could be sued for patent
7584 infringement merely by running @command{compress}! Besides, it is less
7585 effective than @command{gzip} and @command{bzip2}.
7586
7587 Creating a compressed archive is simple: you just specify a
7588 @dfn{compression option} along with the usual archive creation
7589 commands. The compression option is @option{-z} (@option{--gzip}) to
7590 create a @command{gzip} compressed archive, @option{-j}
7591 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
7592 @option{-Z} (@option{--compress}) to use @command{compress} program.
7593 For example:
7594
7595 @smallexample
7596 $ @kbd{tar cfz archive.tar.gz .}
7597 @end smallexample
7598
7599 Reading compressed archive is even simpler: you don't need to specify
7600 any additional options as @GNUTAR{} recognizes its format
7601 automatically. Thus, the following commands will list and extract the
7602 archive created in previous example:
7603
7604 @smallexample
7605 # List the compressed archive
7606 $ @kbd{tar tf archive.tar.gz}
7607 # Extract the compressed archive
7608 $ @kbd{tar xf archive.tar.gz}
7609 @end smallexample
7610
7611 The only case when you have to specify a decompression option while
7612 reading the archive is when reading from a pipe or from a tape drive
7613 that does not support random access. However, in this case @GNUTAR{}
7614 will indicate which option you should use. For example:
7615
7616 @smallexample
7617 $ @kbd{cat archive.tar.gz | tar tf -}
7618 tar: Archive is compressed. Use -z option
7619 tar: Error is not recoverable: exiting now
7620 @end smallexample
7621
7622 If you see such diagnostics, just add the suggested option to the
7623 invocation of @GNUTAR{}:
7624
7625 @smallexample
7626 $ @kbd{cat archive.tar.gz | tar tfz -}
7627 @end smallexample
7628
7629 Notice also, that there are several restrictions on operations on
7630 compressed archives. First of all, compressed archives cannot be
7631 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
7632 (@option{--delete}) members from them. Likewise, you cannot append
7633 another @command{tar} archive to a compressed archive using
7634 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
7635 compressed.
7636
7637 The following table summarizes compression options used by @GNUTAR{}.
7638
7639 @table @option
7640 @opindex gzip
7641 @opindex ungzip
7642 @item -z
7643 @itemx --gzip
7644 @itemx --ungzip
7645 Filter the archive through @command{gzip}.
7646
7647 You can use @option{--gzip} and @option{--gunzip} on physical devices
7648 (tape drives, etc.) and remote files as well as on normal files; data
7649 to or from such devices or remote files is reblocked by another copy
7650 of the @command{tar} program to enforce the specified (or default) record
7651 size. The default compression parameters are used; if you need to
7652 override them, set @env{GZIP} environment variable, e.g.:
7653
7654 @smallexample
7655 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
7656 @end smallexample
7657
7658 @noindent
7659 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
7660 @command{gzip} explicitly:
7661
7662 @smallexample
7663 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
7664 @end smallexample
7665
7666 @cindex corrupted archives
7667 About corrupted compressed archives: @command{gzip}'ed files have no
7668 redundancy, for maximum compression. The adaptive nature of the
7669 compression scheme means that the compression tables are implicitly
7670 spread all over the archive. If you lose a few blocks, the dynamic
7671 construction of the compression tables becomes unsynchronized, and there
7672 is little chance that you could recover later in the archive.
7673
7674 There are pending suggestions for having a per-volume or per-file
7675 compression in @GNUTAR{}. This would allow for viewing the
7676 contents without decompression, and for resynchronizing decompression at
7677 every volume or file, in case of corrupted archives. Doing so, we might
7678 lose some compressibility. But this would have make recovering easier.
7679 So, there are pros and cons. We'll see!
7680
7681 @opindex bzip2
7682 @item -j
7683 @itemx --bzip2
7684 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
7685
7686 @opindex compress
7687 @opindex uncompress
7688 @item -Z
7689 @itemx --compress
7690 @itemx --uncompress
7691 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
7692
7693 The @acronym{GNU} Project recommends you not use
7694 @command{compress}, because there is a patent covering the algorithm it
7695 uses. You could be sued for patent infringement merely by running
7696 @command{compress}.
7697
7698 @opindex use-compress-program
7699 @item --use-compress-program=@var{prog}
7700 Use external compression program @var{prog}. Use this option if you
7701 have a compression program that @GNUTAR{} does not support. There
7702 are two requirements to which @var{prog} should comply:
7703
7704 First, when called without options, it should read data from standard
7705 input, compress it and output it on standard output.
7706
7707 Secondly, if called with @option{-d} argument, it should do exactly
7708 the opposite, i.e., read the compressed data from the standard input
7709 and produce uncompressed data on the standard output.
7710 @end table
7711
7712 @cindex gpg, using with tar
7713 @cindex gnupg, using with tar
7714 @cindex Using encrypted archives
7715 The @option{--use-compress-program} option, in particular, lets you
7716 implement your own filters, not necessarily dealing with
7717 compression/decomression. For example, suppose you wish to implement
7718 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
7719 gpg, gpg ---- encryption and signing tool, gpg}). The following
7720 script does that:
7721
7722 @smallexample
7723 @group
7724 #! /bin/sh
7725 case $1 in
7726 -d) gpg --decrypt - | gzip -d -c;;
7727 '') gzip -c | gpg -s ;;
7728 *) echo "Unknown option $1">&2; exit 1;;
7729 esac
7730 @end group
7731 @end smallexample
7732
7733 Suppose you name it @file{gpgz} and save it somewhere in your
7734 @env{PATH}. Then the following command will create a commpressed
7735 archive signed with your private key:
7736
7737 @smallexample
7738 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
7739 @end smallexample
7740
7741 @noindent
7742 Likewise, the following command will list its contents:
7743
7744 @smallexample
7745 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
7746 @end smallexample
7747
7748 @ignore
7749 The above is based on the following discussion:
7750
7751 I have one question, or maybe it's a suggestion if there isn't a way
7752 to do it now. I would like to use @option{--gzip}, but I'd also like
7753 the output to be fed through a program like @acronym{GNU}
7754 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
7755 to use :-)), basically adding ECC protection on top of compression.
7756 It seems as if this should be quite easy to do, but I can't work out
7757 exactly how to go about it. Of course, I can pipe the standard output
7758 of @command{tar} through @command{ecc}, but then I lose (though I
7759 haven't started using it yet, I confess) the ability to have
7760 @command{tar} use @command{rmt} for it's I/O (I think).
7761
7762 I think the most straightforward thing would be to let me specify a
7763 general set of filters outboard of compression (preferably ordered,
7764 so the order can be automatically reversed on input operations, and
7765 with the options they require specifiable), but beggars shouldn't be
7766 choosers and anything you decide on would be fine with me.
7767
7768 By the way, I like @command{ecc} but if (as the comments say) it can't
7769 deal with loss of block sync, I'm tempted to throw some time at adding
7770 that capability. Supposing I were to actually do such a thing and
7771 get it (apparently) working, do you accept contributed changes to
7772 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
7773
7774 Isn't that exactly the role of the
7775 @option{--use-compress-prog=@var{program}} option?
7776 I never tried it myself, but I suspect you may want to write a
7777 @var{prog} script or program able to filter stdin to stdout to
7778 way you want. It should recognize the @option{-d} option, for when
7779 extraction is needed rather than creation.
7780
7781 It has been reported that if one writes compressed data (through the
7782 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
7783 the DLT compression mode, the data will actually get bigger and one will
7784 end up with less space on the tape.
7785 @end ignore
7786
7787 @node sparse
7788 @subsection Archiving Sparse Files
7789 @cindex Sparse Files
7790 @UNREVISED
7791
7792 @table @option
7793 @opindex sparse
7794 @item -S
7795 @itemx --sparse
7796 Handle sparse files efficiently.
7797 @end table
7798
7799 This option causes all files to be put in the archive to be tested for
7800 sparseness, and handled specially if they are. The @option{--sparse}
7801 (@option{-S}) option is useful when many @code{dbm} files, for example, are being
7802 backed up. Using this option dramatically decreases the amount of
7803 space needed to store such a file.
7804
7805 In later versions, this option may be removed, and the testing and
7806 treatment of sparse files may be done automatically with any special
7807 @acronym{GNU} options. For now, it is an option needing to be specified on
7808 the command line with the creation or updating of an archive.
7809
7810 Files in the file system occasionally have ``holes.'' A hole in a file
7811 is a section of the file's contents which was never written. The
7812 contents of a hole read as all zeros. On many operating systems,
7813 actual disk storage is not allocated for holes, but they are counted
7814 in the length of the file. If you archive such a file, @command{tar}
7815 could create an archive longer than the original. To have @command{tar}
7816 attempt to recognize the holes in a file, use @option{--sparse} (@option{-S}). When
7817 you use this option, then, for any file using less disk space than
7818 would be expected from its length, @command{tar} searches the file for
7819 consecutive stretches of zeros. It then records in the archive for
7820 the file where the consecutive stretches of zeros are, and only
7821 archives the ``real contents'' of the file. On extraction (using
7822 @option{--sparse} is not needed on extraction) any such
7823 files have holes created wherever the continuous stretches of zeros
7824 were found. Thus, if you use @option{--sparse}, @command{tar} archives
7825 won't take more space than the original.
7826
7827 A file is sparse if it contains blocks of zeros whose existence is
7828 recorded, but that have no space allocated on disk. When you specify
7829 the @option{--sparse} option in conjunction with the @option{--create}
7830 (@option{-c}) operation, @command{tar} tests all files for sparseness
7831 while archiving. If @command{tar} finds a file to be sparse, it uses a
7832 sparse representation of the file in the archive. @xref{create}, for
7833 more information about creating archives.
7834
7835 @option{--sparse} is useful when archiving files, such as dbm files,
7836 likely to contain many nulls. This option dramatically
7837 decreases the amount of space needed to store such an archive.
7838
7839 @quotation
7840 @strong{Please Note:} Always use @option{--sparse} when performing file
7841 system backups, to avoid archiving the expanded forms of files stored
7842 sparsely in the system.
7843
7844 Even if your system has no sparse files currently, some may be
7845 created in the future. If you use @option{--sparse} while making file
7846 system backups as a matter of course, you can be assured the archive
7847 will never take more space on the media than the files take on disk
7848 (otherwise, archiving a disk filled with sparse files might take
7849 hundreds of tapes). @xref{Incremental Dumps}.
7850 @end quotation
7851
7852 @command{tar} ignores the @option{--sparse} option when reading an archive.
7853
7854 @table @option
7855 @item --sparse
7856 @itemx -S
7857 Files stored sparsely in the file system are represented sparsely in
7858 the archive. Use in conjunction with write operations.
7859 @end table
7860
7861 However, users should be well aware that at archive creation time,
7862 @GNUTAR{} still has to read whole disk file to
7863 locate the @dfn{holes}, and so, even if sparse files use little space
7864 on disk and in the archive, they may sometimes require inordinate
7865 amount of time for reading and examining all-zero blocks of a file.
7866 Although it works, it's painfully slow for a large (sparse) file, even
7867 though the resulting tar archive may be small. (One user reports that
7868 dumping a @file{core} file of over 400 megabytes, but with only about
7869 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
7870 ELC, with full CPU utilization.)
7871
7872 This reading is required in all cases and is not related to the fact
7873 the @option{--sparse} option is used or not, so by merely @emph{not}
7874 using the option, you are not saving time@footnote{Well! We should say
7875 the whole truth, here. When @option{--sparse} is selected while creating
7876 an archive, the current @command{tar} algorithm requires sparse files to be
7877 read twice, not once. We hope to develop a new archive format for saving
7878 sparse files in which one pass will be sufficient.}.
7879
7880 Programs like @command{dump} do not have to read the entire file; by
7881 examining the file system directly, they can determine in advance
7882 exactly where the holes are and thus avoid reading through them. The
7883 only data it need read are the actual allocated data blocks.
7884 @GNUTAR{} uses a more portable and straightforward
7885 archiving approach, it would be fairly difficult that it does
7886 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
7887 1990-12-10:
7888
7889 @quotation
7890 What I did say is that you cannot tell the difference between a hole and an
7891 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
7892 best tells you how many holes there are; it doesn't tell you @emph{where}.
7893 Just as programs may, conceivably, care what @code{st_blocks} is (care
7894 to name one that does?), they may also care where the holes are (I have
7895 no examples of this one either, but it's equally imaginable).
7896
7897 I conclude from this that good archivers are not portable. One can
7898 arguably conclude that if you want a portable program, you can in good
7899 conscience restore files with as many holes as possible, since you can't
7900 get it right.
7901 @end quotation
7902
7903 @node Attributes
7904 @section Handling File Attributes
7905 @UNREVISED
7906
7907 When @command{tar} reads files, it updates their access times. To
7908 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
7909 reset the access time retroactively or avoid changing it in the first
7910 place.
7911
7912 Handling of file attributes
7913
7914 @table @option
7915 @opindex atime-preserve
7916 @item --atime-preserve
7917 @itemx --atime-preserve=replace
7918 @itemx --atime-preserve=system
7919 Preserve the access times of files that are read. This works only for
7920 files that you own, unless you have superuser privileges.
7921
7922 @option{--atime-preserve=replace} works on most systems, but it also
7923 restores the data modification time and updates the status change
7924 time. Hence it doesn't interact with incremental dumps nicely
7925 (@pxref{Backups}), and it can set access or data modification times
7926 incorrectly if other programs access the file while @command{tar} is
7927 running.
7928
7929 @option{--atime-preserve=system} avoids changing the access time in
7930 the first place, if the operating system supports this.
7931 Unfortunately, this may or may not work on any given operating system
7932 or file system. If @command{tar} knows for sure it won't work, it
7933 complains right away.
7934
7935 Currently @option{--atime-preserve} with no operand defaults to
7936 @option{--atime-preserve=replace}, but this is intended to change to
7937 @option{--atime-preserve=system} when the latter is better-supported.
7938
7939 @opindex touch
7940 @item -m
7941 @itemx --touch
7942 Do not extract data modification time.
7943
7944 When this option is used, @command{tar} leaves the data modification times
7945 of the files it extracts as the times when the files were extracted,
7946 instead of setting it to the times recorded in the archive.
7947
7948 This option is meaningless with @option{--list} (@option{-t}).
7949
7950 @opindex same-owner
7951 @item --same-owner
7952 Create extracted files with the same ownership they have in the
7953 archive.
7954
7955 This is the default behavior for the superuser,
7956 so this option is meaningful only for non-root users, when @command{tar}
7957 is executed on those systems able to give files away. This is
7958 considered as a security flaw by many people, at least because it
7959 makes quite difficult to correctly account users for the disk space
7960 they occupy. Also, the @code{suid} or @code{sgid} attributes of
7961 files are easily and silently lost when files are given away.
7962
7963 When writing an archive, @command{tar} writes the user id and user name
7964 separately. If it can't find a user name (because the user id is not
7965 in @file{/etc/passwd}), then it does not write one. When restoring,
7966 it tries to look the name (if one was written) up in
7967 @file{/etc/passwd}. If it fails, then it uses the user id stored in
7968 the archive instead.
7969
7970 @opindex no-same-owner
7971 @item --no-same-owner
7972 @itemx -o
7973 Do not attempt to restore ownership when extracting. This is the
7974 default behavior for ordinary users, so this option has an effect
7975 only for the superuser.
7976
7977 @opindex numeric-owner
7978 @item --numeric-owner
7979 The @option{--numeric-owner} option allows (ANSI) archives to be written
7980 without user/group name information or such information to be ignored
7981 when extracting. It effectively disables the generation and/or use
7982 of user/group name information. This option forces extraction using
7983 the numeric ids from the archive, ignoring the names.
7984
7985 This is useful in certain circumstances, when restoring a backup from
7986 an emergency floppy with different passwd/group files for example.
7987 It is otherwise impossible to extract files with the right ownerships
7988 if the password file in use during the extraction does not match the
7989 one belonging to the file system(s) being extracted. This occurs,
7990 for example, if you are restoring your files after a major crash and
7991 had booted from an emergency floppy with no password file or put your
7992 disk into another machine to do the restore.
7993
7994 The numeric ids are @emph{always} saved into @command{tar} archives.
7995 The identifying names are added at create time when provided by the
7996 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
7997 used when moving archives between a collection of machines using
7998 a centralized management for attribution of numeric ids to users
7999 and groups. This is often made through using the NIS capabilities.
8000
8001 When making a @command{tar} file for distribution to other sites, it
8002 is sometimes cleaner to use a single owner for all files in the
8003 distribution, and nicer to specify the write permission bits of the
8004 files as stored in the archive independently of their actual value on
8005 the file system. The way to prepare a clean distribution is usually
8006 to have some Makefile rule creating a directory, copying all needed
8007 files in that directory, then setting ownership and permissions as
8008 wanted (there are a lot of possible schemes), and only then making a
8009 @command{tar} archive out of this directory, before cleaning
8010 everything out. Of course, we could add a lot of options to
8011 @GNUTAR{} for fine tuning permissions and ownership.
8012 This is not the good way, I think. @GNUTAR{} is
8013 already crowded with options and moreover, the approach just explained
8014 gives you a great deal of control already.
8015
8016 @opindex same-permissions, short description
8017 @opindex preserve-permissions, short description
8018 @item -p
8019 @itemx --same-permissions
8020 @itemx --preserve-permissions
8021 Extract all protection information.
8022
8023 This option causes @command{tar} to set the modes (access permissions) of
8024 extracted files exactly as recorded in the archive. If this option
8025 is not used, the current @code{umask} setting limits the permissions
8026 on extracted files. This option is by default enabled when
8027 @command{tar} is executed by a superuser.
8028
8029
8030 This option is meaningless with @option{--list} (@option{-t}).
8031
8032 @opindex preserve
8033 @item --preserve
8034 Same as both @option{--same-permissions} and @option{--same-order}.
8035
8036 The @option{--preserve} option has no equivalent short option name.
8037 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8038
8039 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8040 Neither do I. --Sergey}
8041
8042 @end table
8043
8044 @node Standard
8045 @section Basic Tar Format
8046 @UNREVISED
8047
8048 While an archive may contain many files, the archive itself is a
8049 single ordinary file. Like any other file, an archive file can be
8050 written to a storage device such as a tape or disk, sent through a
8051 pipe or over a network, saved on the active file system, or even
8052 stored in another archive. An archive file is not easy to read or
8053 manipulate without using the @command{tar} utility or Tar mode in
8054 @acronym{GNU} Emacs.
8055
8056 Physically, an archive consists of a series of file entries terminated
8057 by an end-of-archive entry, which consists of two 512 blocks of zero
8058 bytes. A file
8059 entry usually describes one of the files in the archive (an
8060 @dfn{archive member}), and consists of a file header and the contents
8061 of the file. File headers contain file names and statistics, checksum
8062 information which @command{tar} uses to detect file corruption, and
8063 information about file types.
8064
8065 Archives are permitted to have more than one member with the same
8066 member name. One way this situation can occur is if more than one
8067 version of a file has been stored in the archive. For information
8068 about adding new versions of a file to an archive, see @ref{update}.
8069 @FIXME-xref{To learn more about having more than one archive member with the
8070 same name, see -backup node, when it's written.}
8071
8072 In addition to entries describing archive members, an archive may
8073 contain entries which @command{tar} itself uses to store information.
8074 @xref{label}, for an example of such an archive entry.
8075
8076 A @command{tar} archive file contains a series of blocks. Each block
8077 contains @code{BLOCKSIZE} bytes. Although this format may be thought
8078 of as being on magnetic tape, other media are often used.
8079
8080 Each file archived is represented by a header block which describes
8081 the file, followed by zero or more blocks which give the contents
8082 of the file. At the end of the archive file there are two 512-byte blocks
8083 filled with binary zeros as an end-of-file marker. A reasonable system
8084 should write such end-of-file marker at the end of an archive, but
8085 must not assume that such a block exists when reading an archive. In
8086 particular @GNUTAR{} always issues a warning if it does not encounter it.
8087
8088 The blocks may be @dfn{blocked} for physical I/O operations.
8089 Each record of @var{n} blocks (where @var{n} is set by the
8090 @option{--blocking-factor=@var{512-size}} (@option{-b @var{512-size}}) option to @command{tar}) is written with a single
8091 @w{@samp{write ()}} operation. On magnetic tapes, the result of
8092 such a write is a single record. When writing an archive,
8093 the last record of blocks should be written at the full size, with
8094 blocks after the zero block containing all zeros. When reading
8095 an archive, a reasonable system should properly handle an archive
8096 whose last record is shorter than the rest, or which contains garbage
8097 records after a zero block.
8098
8099 The header block is defined in C as follows. In the @GNUTAR{}
8100 distribution, this is part of file @file{src/tar.h}:
8101
8102 @smallexample
8103 @include header.texi
8104 @end smallexample
8105
8106 All characters in header blocks are represented by using 8-bit
8107 characters in the local variant of ASCII. Each field within the
8108 structure is contiguous; that is, there is no padding used within
8109 the structure. Each character on the archive medium is stored
8110 contiguously.
8111
8112 Bytes representing the contents of files (after the header block
8113 of each file) are not translated in any way and are not constrained
8114 to represent characters in any character set. The @command{tar} format
8115 does not distinguish text files from binary files, and no translation
8116 of file contents is performed.
8117
8118 The @code{name}, @code{linkname}, @code{magic}, @code{uname}, and
8119 @code{gname} are null-terminated character strings. All other fields
8120 are zero-filled octal numbers in ASCII. Each numeric field of width
8121 @var{w} contains @var{w} minus 1 digits, and a null.
8122
8123 The @code{name} field is the file name of the file, with directory names
8124 (if any) preceding the file name, separated by slashes.
8125
8126 @FIXME{how big a name before field overflows?}
8127
8128 The @code{mode} field provides nine bits specifying file permissions
8129 and three bits to specify the Set UID, Set GID, and Save Text
8130 (@dfn{sticky}) modes. Values for these bits are defined above.
8131 When special permissions are required to create a file with a given
8132 mode, and the user restoring files from the archive does not hold such
8133 permissions, the mode bit(s) specifying those special permissions
8134 are ignored. Modes which are not supported by the operating system
8135 restoring files from the archive will be ignored. Unsupported modes
8136 should be faked up when creating or updating an archive; e.g., the
8137 group permission could be copied from the @emph{other} permission.
8138
8139 The @code{uid} and @code{gid} fields are the numeric user and group
8140 ID of the file owners, respectively. If the operating system does
8141 not support numeric user or group IDs, these fields should be ignored.
8142
8143 The @code{size} field is the size of the file in bytes; linked files
8144 are archived with this field specified as zero. @FIXME-xref{Modifiers, in
8145 particular the @option{--incremental} (@option{-G}) option.}
8146
8147 The @code{mtime} field is the data modification time of the file at
8148 the time it was archived. It is the ASCII representation of the octal
8149 value of the last time the file's contents were modified, represented
8150 as an integer number of
8151 seconds since January 1, 1970, 00:00 Coordinated Universal Time.
8152
8153 The @code{chksum} field is the ASCII representation of the octal value
8154 of the simple sum of all bytes in the header block. Each 8-bit
8155 byte in the header is added to an unsigned integer, initialized to
8156 zero, the precision of which shall be no less than seventeen bits.
8157 When calculating the checksum, the @code{chksum} field is treated as
8158 if it were all blanks.
8159
8160 The @code{typeflag} field specifies the type of file archived. If a
8161 particular implementation does not recognize or permit the specified
8162 type, the file will be extracted as if it were a regular file. As this
8163 action occurs, @command{tar} issues a warning to the standard error.
8164
8165 The @code{atime} and @code{ctime} fields are used in making incremental
8166 backups; they store, respectively, the particular file's access and
8167 status change times.
8168
8169 The @code{offset} is used by the @option{--multi-volume} (@option{-M}) option, when
8170 making a multi-volume archive. The offset is number of bytes into
8171 the file that we need to restart at to continue the file on the next
8172 tape, i.e., where we store the location that a continued file is
8173 continued at.
8174
8175 The following fields were added to deal with sparse files. A file
8176 is @dfn{sparse} if it takes in unallocated blocks which end up being
8177 represented as zeros, i.e., no useful data. A test to see if a file
8178 is sparse is to look at the number blocks allocated for it versus the
8179 number of characters in the file; if there are fewer blocks allocated
8180 for the file than would normally be allocated for a file of that
8181 size, then the file is sparse. This is the method @command{tar} uses to
8182 detect a sparse file, and once such a file is detected, it is treated
8183 differently from non-sparse files.
8184
8185 Sparse files are often @code{dbm} files, or other database-type files
8186 which have data at some points and emptiness in the greater part of
8187 the file. Such files can appear to be very large when an @samp{ls
8188 -l} is done on them, when in truth, there may be a very small amount
8189 of important data contained in the file. It is thus undesirable
8190 to have @command{tar} think that it must back up this entire file, as
8191 great quantities of room are wasted on empty blocks, which can lead
8192 to running out of room on a tape far earlier than is necessary.
8193 Thus, sparse files are dealt with so that these empty blocks are
8194 not written to the tape. Instead, what is written to the tape is a
8195 description, of sorts, of the sparse file: where the holes are, how
8196 big the holes are, and how much data is found at the end of the hole.
8197 This way, the file takes up potentially far less room on the tape,
8198 and when the file is extracted later on, it will look exactly the way
8199 it looked beforehand. The following is a description of the fields
8200 used to handle a sparse file:
8201
8202 The @code{sp} is an array of @code{struct sparse}. Each @code{struct
8203 sparse} contains two 12-character strings which represent an offset
8204 into the file and a number of bytes to be written at that offset.
8205 The offset is absolute, and not relative to the offset in preceding
8206 array element.
8207
8208 The header can hold four of these @code{struct sparse} at the moment;
8209 if more are needed, they are not stored in the header.
8210
8211 The @code{isextended} flag is set when an @code{extended_header}
8212 is needed to deal with a file. Note that this means that this flag
8213 can only be set when dealing with a sparse file, and it is only set
8214 in the event that the description of the file will not fit in the
8215 allotted room for sparse structures in the header. In other words,
8216 an extended_header is needed.
8217
8218 The @code{extended_header} structure is used for sparse files which
8219 need more sparse structures than can fit in the header. The header can
8220 fit 4 such structures; if more are needed, the flag @code{isextended}
8221 gets set and the next block is an @code{extended_header}.
8222
8223 Each @code{extended_header} structure contains an array of 21
8224 sparse structures, along with a similar @code{isextended} flag
8225 that the header had. There can be an indeterminate number of such
8226 @code{extended_header}s to describe a sparse file.
8227
8228 @table @asis
8229
8230 @item @code{REGTYPE}
8231 @itemx @code{AREGTYPE}
8232 These flags represent a regular file. In order to be compatible
8233 with older versions of @command{tar}, a @code{typeflag} value of
8234 @code{AREGTYPE} should be silently recognized as a regular file.
8235 New archives should be created using @code{REGTYPE}. Also, for
8236 backward compatibility, @command{tar} treats a regular file whose name
8237 ends with a slash as a directory.
8238
8239 @item @code{LNKTYPE}
8240 This flag represents a file linked to another file, of any type,
8241 previously archived. Such files are identified in Unix by each
8242 file having the same device and inode number. The linked-to name is
8243 specified in the @code{linkname} field with a trailing null.
8244
8245 @item @code{SYMTYPE}
8246 This represents a symbolic link to another file. The linked-to name
8247 is specified in the @code{linkname} field with a trailing null.
8248
8249 @item @code{CHRTYPE}
8250 @itemx @code{BLKTYPE}
8251 These represent character special files and block special files
8252 respectively. In this case the @code{devmajor} and @code{devminor}
8253 fields will contain the major and minor device numbers respectively.
8254 Operating systems may map the device specifications to their own
8255 local specification, or may ignore the entry.
8256
8257 @item @code{DIRTYPE}
8258 This flag specifies a directory or sub-directory. The directory
8259 name in the @code{name} field should end with a slash. On systems where
8260 disk allocation is performed on a directory basis, the @code{size} field
8261 will contain the maximum number of bytes (which may be rounded to
8262 the nearest disk block allocation unit) which the directory may
8263 hold. A @code{size} field of zero indicates no such limiting. Systems
8264 which do not support limiting in this manner should ignore the
8265 @code{size} field.
8266
8267 @item @code{FIFOTYPE}
8268 This specifies a FIFO special file. Note that the archiving of a
8269 FIFO file archives the existence of this file and not its contents.
8270
8271 @item @code{CONTTYPE}
8272 This specifies a contiguous file, which is the same as a normal
8273 file except that, in operating systems which support it, all its
8274 space is allocated contiguously on the disk. Operating systems
8275 which do not allow contiguous allocation should silently treat this
8276 type as a normal file.
8277
8278 @item @code{A} @dots{} @code{Z}
8279 These are reserved for custom implementations. Some of these are
8280 used in the @acronym{GNU} modified format, as described below.
8281
8282 @end table
8283
8284 Other values are reserved for specification in future revisions of
8285 the P1003 standard, and should not be used by any @command{tar} program.
8286
8287 The @code{magic} field indicates that this archive was output in
8288 the P1003 archive format. If this field contains @code{TMAGIC},
8289 the @code{uname} and @code{gname} fields will contain the ASCII
8290 representation of the owner and group of the file respectively.
8291 If found, the user and group IDs are used rather than the values in
8292 the @code{uid} and @code{gid} fields.
8293
8294 For references, see ISO/IEC 9945-1:1990 or IEEE Std 1003.1-1990, pages
8295 169-173 (section 10.1) for @cite{Archive/Interchange File Format}; and
8296 IEEE Std 1003.2-1992, pages 380-388 (section 4.48) and pages 936-940
8297 (section E.4.48) for @cite{pax - Portable archive interchange}.
8298
8299 @node Extensions
8300 @section @acronym{GNU} Extensions to the Archive Format
8301 @UNREVISED
8302
8303 The @acronym{GNU} format uses additional file types to describe new types of
8304 files in an archive. These are listed below.
8305
8306 @table @code
8307 @item GNUTYPE_DUMPDIR
8308 @itemx 'D'
8309 This represents a directory and a list of files created by the
8310 @option{--incremental} (@option{-G}) option. The @code{size} field gives the total
8311 size of the associated list of files. Each file name is preceded by
8312 either a @samp{Y} (the file should be in this archive) or an @samp{N}.
8313 (The file is a directory, or is not stored in the archive.) Each file
8314 name is terminated by a null. There is an additional null after the
8315 last file name.
8316
8317 @item GNUTYPE_MULTIVOL
8318 @itemx 'M'
8319 This represents a file continued from another volume of a multi-volume
8320 archive created with the @option{--multi-volume} (@option{-M}) option. The original
8321 type of the file is not given here. The @code{size} field gives the
8322 maximum size of this piece of the file (assuming the volume does
8323 not end before the file is written out). The @code{offset} field
8324 gives the offset from the beginning of the file where this part of
8325 the file begins. Thus @code{size} plus @code{offset} should equal
8326 the original size of the file.
8327
8328 @item GNUTYPE_SPARSE
8329 @itemx 'S'
8330 This flag indicates that we are dealing with a sparse file. Note
8331 that archiving a sparse file requires special operations to find
8332 holes in the file, which mark the positions of these holes, along
8333 with the number of bytes of data to be found after the hole.
8334
8335 @item GNUTYPE_VOLHDR
8336 @itemx 'V'
8337 This file type is used to mark the volume header that was given with
8338 the @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) option when the archive was created. The @code{name}
8339 field contains the @code{name} given after the @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) option.
8340 The @code{size} field is zero. Only the first file in each volume
8341 of an archive should have this type.
8342
8343 @end table
8344
8345 You may have trouble reading a @acronym{GNU} format archive on a
8346 non-@acronym{GNU} system if the options @option{--incremental} (@option{-G}),
8347 @option{--multi-volume} (@option{-M}), @option{--sparse} (@option{-S}), or @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) were
8348 used when writing the archive. In general, if @command{tar} does not
8349 use the @acronym{GNU}-added fields of the header, other versions of
8350 @command{tar} should be able to read the archive. Otherwise, the
8351 @command{tar} program will give an error, the most likely one being a
8352 checksum error.
8353
8354 @node cpio
8355 @section Comparison of @command{tar} and @command{cpio}
8356 @UNREVISED
8357
8358 @FIXME{Reorganize the following material}
8359
8360 The @command{cpio} archive formats, like @command{tar}, do have maximum
8361 pathname lengths. The binary and old ASCII formats have a max path
8362 length of 256, and the new ASCII and CRC ASCII formats have a max
8363 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8364 with arbitrary pathname lengths, but other @command{cpio} implementations
8365 may crash unexplainedly trying to read them.
8366
8367 @command{tar} handles symbolic links in the form in which it comes in BSD;
8368 @command{cpio} doesn't handle symbolic links in the form in which it comes
8369 in System V prior to SVR4, and some vendors may have added symlinks
8370 to their system without enhancing @command{cpio} to know about them.
8371 Others may have enhanced it in a way other than the way I did it
8372 at Sun, and which was adopted by AT&T (and which is, I think, also
8373 present in the @command{cpio} that Berkeley picked up from AT&T and put
8374 into a later BSD release---I think I gave them my changes).
8375
8376 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8377 can handle @command{tar} format input, and write it on output, and it
8378 probably handles symbolic links. They may not have bothered doing
8379 anything to enhance @command{tar} as a result.)
8380
8381 @command{cpio} handles special files; traditional @command{tar} doesn't.
8382
8383 @command{tar} comes with V7, System III, System V, and BSD source;
8384 @command{cpio} comes only with System III, System V, and later BSD
8385 (4.3-tahoe and later).
8386
8387 @command{tar}'s way of handling multiple hard links to a file can handle
8388 file systems that support 32-bit inumbers (e.g., the BSD file system);
8389 @command{cpio}s way requires you to play some games (in its "binary"
8390 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8391 they're 18 bits---it would have to play games with the "file system ID"
8392 field of the header to make sure that the file system ID/i-number pairs
8393 of different files were always different), and I don't know which
8394 @command{cpio}s, if any, play those games. Those that don't might get
8395 confused and think two files are the same file when they're not, and
8396 make hard links between them.
8397
8398 @command{tar}s way of handling multiple hard links to a file places only
8399 one copy of the link on the tape, but the name attached to that copy
8400 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8401 way puts one copy for every link, but you can retrieve it using any
8402 of the names.
8403
8404 @quotation
8405 What type of check sum (if any) is used, and how is this calculated.
8406 @end quotation
8407
8408 See the attached manual pages for @command{tar} and @command{cpio} format.
8409 @command{tar} uses a checksum which is the sum of all the bytes in the
8410 @command{tar} header for a file; @command{cpio} uses no checksum.
8411
8412 @quotation
8413 If anyone knows why @command{cpio} was made when @command{tar} was present
8414 at the unix scene,
8415 @end quotation
8416
8417 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8418 generally-available version of UNIX had @command{tar} at the time. I don't
8419 know whether any version that was generally available @emph{within AT&T}
8420 had @command{tar}, or, if so, whether the people within AT&T who did
8421 @command{cpio} knew about it.
8422
8423 On restore, if there is a corruption on a tape @command{tar} will stop at
8424 that point, while @command{cpio} will skip over it and try to restore the
8425 rest of the files.
8426
8427 The main difference is just in the command syntax and header format.
8428
8429 @command{tar} is a little more tape-oriented in that everything is blocked
8430 to start on a record boundary.
8431
8432 @quotation
8433 Is there any differences between the ability to recover crashed
8434 archives between the two of them. (Is there any chance of recovering
8435 crashed archives at all.)
8436 @end quotation
8437
8438 Theoretically it should be easier under @command{tar} since the blocking
8439 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
8440 However, modern @command{cpio}'s and variations have an option to just
8441 search for the next file header after an error with a reasonable chance
8442 of resyncing. However, lots of tape driver software won't allow you to
8443 continue past a media error which should be the only reason for getting
8444 out of sync unless a file changed sizes while you were writing the
8445 archive.
8446
8447 @quotation
8448 If anyone knows why @command{cpio} was made when @command{tar} was present
8449 at the unix scene, please tell me about this too.
8450 @end quotation
8451
8452 Probably because it is more media efficient (by not blocking everything
8453 and using only the space needed for the headers where @command{tar}
8454 always uses 512 bytes per file header) and it knows how to archive
8455 special files.
8456
8457 You might want to look at the freely available alternatives. The
8458 major ones are @command{afio}, @GNUTAR{}, and
8459 @command{pax}, each of which have their own extensions with some
8460 backwards compatibility.
8461
8462 Sparse files were @command{tar}red as sparse files (which you can
8463 easily test, because the resulting archive gets smaller, and
8464 @acronym{GNU} @command{cpio} can no longer read it).
8465
8466 @node Media
8467 @chapter Tapes and Other Archive Media
8468 @UNREVISED
8469
8470 A few special cases about tape handling warrant more detailed
8471 description. These special cases are discussed below.
8472
8473 Many complexities surround the use of @command{tar} on tape drives. Since
8474 the creation and manipulation of archives located on magnetic tape was
8475 the original purpose of @command{tar}, it contains many features making
8476 such manipulation easier.
8477
8478 Archives are usually written on dismountable media---tape cartridges,
8479 mag tapes, or floppy disks.
8480
8481 The amount of data a tape or disk holds depends not only on its size,
8482 but also on how it is formatted. A 2400 foot long reel of mag tape
8483 holds 40 megabytes of data when formatted at 1600 bits per inch. The
8484 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
8485
8486 Magnetic media are re-usable---once the archive on a tape is no longer
8487 needed, the archive can be erased and the tape or disk used over.
8488 Media quality does deteriorate with use, however. Most tapes or disks
8489 should be discarded when they begin to produce data errors. EXABYTE
8490 tape cartridges should be discarded when they generate an @dfn{error
8491 count} (number of non-usable bits) of more than 10k.
8492
8493 Magnetic media are written and erased using magnetic fields, and
8494 should be protected from such fields to avoid damage to stored data.
8495 Sticking a floppy disk to a filing cabinet using a magnet is probably
8496 not a good idea.
8497
8498 @menu
8499 * Device:: Device selection and switching
8500 * Remote Tape Server::
8501 * Common Problems and Solutions::
8502 * Blocking:: Blocking
8503 * Many:: Many archives on one tape
8504 * Using Multiple Tapes:: Using Multiple Tapes
8505 * label:: Including a Label in the Archive
8506 * verify::
8507 * Write Protection::
8508 @end menu
8509
8510 @node Device
8511 @section Device Selection and Switching
8512 @UNREVISED
8513
8514 @table @option
8515 @item -f [@var{hostname}:]@var{file}
8516 @itemx --file=[@var{hostname}:]@var{file}
8517 Use archive file or device @var{file} on @var{hostname}.
8518 @end table
8519
8520 This option is used to specify the file name of the archive @command{tar}
8521 works on.
8522
8523 If the file name is @samp{-}, @command{tar} reads the archive from standard
8524 input (when listing or extracting), or writes it to standard output
8525 (when creating). If the @samp{-} file name is given when updating an
8526 archive, @command{tar} will read the original archive from its standard
8527 input, and will write the entire new archive to its standard output.
8528
8529 If the file name contains a @samp{:}, it is interpreted as
8530 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
8531 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
8532 either case, @command{tar} will invoke the command @command{rsh} (or
8533 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
8534 machine. If you give an alternate login name, it will be given to the
8535 @command{rsh}.
8536 Naturally, the remote machine must have an executable
8537 @command{/usr/libexec/rmt}. This program is free software from the
8538 University of California, and a copy of the source code can be found
8539 with the sources for @command{tar}; it's compiled and installed by default.
8540 The exact path to this utility is determined when configuring the package.
8541 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
8542 your installation prefix. This location may also be overridden at
8543 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
8544 ---rmt-command}, for detailed description of this option. @xref{Remote
8545 Tape Server}, for the description of @command{rmt} command).
8546
8547 If this option is not given, but the environment variable @env{TAPE}
8548 is set, its value is used; otherwise, old versions of @command{tar}
8549 used a default archive name (which was picked when @command{tar} was
8550 compiled). The default is normally set up to be the @dfn{first} tape
8551 drive or other transportable I/O medium on the system.
8552
8553 Starting with version 1.11.5, @GNUTAR{} uses
8554 standard input and standard output as the default device, and I will
8555 not try anymore supporting automatic device detection at installation
8556 time. This was failing really in too many cases, it was hopeless.
8557 This is now completely left to the installer to override standard
8558 input and standard output for default device, if this seems
8559 preferable. Further, I think @emph{most} actual usages of
8560 @command{tar} are done with pipes or disks, not really tapes,
8561 cartridges or diskettes.
8562
8563 Some users think that using standard input and output is running
8564 after trouble. This could lead to a nasty surprise on your screen if
8565 you forget to specify an output file name---especially if you are going
8566 through a network or terminal server capable of buffering large amounts
8567 of output. We had so many bug reports in that area of configuring
8568 default tapes automatically, and so many contradicting requests, that
8569 we finally consider the problem to be portably intractable. We could
8570 of course use something like @samp{/dev/tape} as a default, but this
8571 is @emph{also} running after various kind of trouble, going from hung
8572 processes to accidental destruction of real tapes. After having seen
8573 all this mess, using standard input and output as a default really
8574 sounds like the only clean choice left, and a very useful one too.
8575
8576 @GNUTAR{} reads and writes archive in records, I
8577 suspect this is the main reason why block devices are preferred over
8578 character devices. Most probably, block devices are more efficient
8579 too. The installer could also check for @samp{DEFTAPE} in
8580 @file{<sys/mtio.h>}.
8581
8582 @table @option
8583 @opindex force-local, short description
8584 @item --force-local
8585 Archive file is local even if it contains a colon.
8586
8587 @opindex rsh-command
8588 @item --rsh-command=@var{command}
8589 Use remote @var{command} instead of @command{rsh}. This option exists
8590 so that people who use something other than the standard @command{rsh}
8591 (e.g., a Kerberized @command{rsh}) can access a remote device.
8592
8593 When this command is not used, the shell command found when
8594 the @command{tar} program was installed is used instead. This is
8595 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
8596 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
8597 The installer may have overridden this by defining the environment
8598 variable @env{RSH} @emph{at installation time}.
8599
8600 @item -[0-7][lmh]
8601 Specify drive and density.
8602
8603 @opindex multi-volume, short description
8604 @item -M
8605 @itemx --multi-volume
8606 Create/list/extract multi-volume archive.
8607
8608 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
8609 that may be larger than will fit on the medium used to hold it.
8610 @xref{Multi-Volume Archives}.
8611
8612 @opindex tape-length, short description
8613 @item -L @var{num}
8614 @itemx --tape-length=@var{num}
8615 Change tape after writing @var{num} x 1024 bytes.
8616
8617 This option might be useful when your tape drivers do not properly
8618 detect end of physical tapes. By being slightly conservative on the
8619 maximum tape length, you might avoid the problem entirely.
8620
8621 @opindex info-script, short description
8622 @opindex new-volume-script, short description
8623 @item -F @var{file}
8624 @itemx --info-script=@var{file}
8625 @itemx --new-volume-script=@var{file}
8626 Execute @file{file} at end of each tape. This implies
8627 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
8628 description of this option.
8629 @end table
8630
8631 @node Remote Tape Server
8632 @section The Remote Tape Server
8633
8634 @cindex remote tape drive
8635 @pindex rmt
8636 In order to access the tape drive on a remote machine, @command{tar}
8637 uses the remote tape server written at the University of California at
8638 Berkeley. The remote tape server must be installed as
8639 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
8640 want to use. @command{tar} calls @command{rmt} by running an
8641 @command{rsh} or @command{remsh} to the remote machine, optionally
8642 using a different login name if one is supplied.
8643
8644 A copy of the source for the remote tape server is provided. It is
8645 Copyright @copyright{} 1983 by the Regents of the University of
8646 California, but can be freely distributed. It is compiled and
8647 installed by default.
8648
8649 @cindex absolute file names
8650 Unless you use the @option{--absolute-names} (@option{-P}) option,
8651 @GNUTAR{} will not allow you to create an archive that contains
8652 absolute file names (a file name beginning with @samp{/}.) If you try,
8653 @command{tar} will automatically remove the leading @samp{/} from the
8654 file names it stores in the archive. It will also type a warning
8655 message telling you what it is doing.
8656
8657 When reading an archive that was created with a different
8658 @command{tar} program, @GNUTAR{} automatically
8659 extracts entries in the archive which have absolute file names as if
8660 the file names were not absolute. This is an important feature. A
8661 visitor here once gave a @command{tar} tape to an operator to restore;
8662 the operator used Sun @command{tar} instead of @GNUTAR{},
8663 and the result was that it replaced large portions of
8664 our @file{/bin} and friends with versions from the tape; needless to
8665 say, we were unhappy about having to recover the file system from
8666 backup tapes.
8667
8668 For example, if the archive contained a file @file{/usr/bin/computoy},
8669 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
8670 relative to the current directory. If you want to extract the files in
8671 an archive to the same absolute names that they had when the archive
8672 was created, you should do a @samp{cd /} before extracting the files
8673 from the archive, or you should either use the @option{--absolute-names}
8674 option, or use the command @samp{tar -C / @dots{}}.
8675
8676 @cindex Ultrix 3.1 and write failure
8677 Some versions of Unix (Ultrix 3.1 is known to have this problem),
8678 can claim that a short write near the end of a tape succeeded,
8679 when it actually failed. This will result in the -M option not
8680 working correctly. The best workaround at the moment is to use a
8681 significantly larger blocking factor than the default 20.
8682
8683 In order to update an archive, @command{tar} must be able to backspace the
8684 archive in order to reread or rewrite a record that was just read (or
8685 written). This is currently possible only on two kinds of files: normal
8686 disk files (or any other file that can be backspaced with @samp{lseek}),
8687 and industry-standard 9-track magnetic tape (or any other kind of tape
8688 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
8689
8690 This means that the @option{--append}, @option{--concatenate}, and
8691 @option{--delete} commands will not work on any other kind of file.
8692 Some media simply cannot be backspaced, which means these commands and
8693 options will never be able to work on them. These non-backspacing
8694 media include pipes and cartridge tape drives.
8695
8696 Some other media can be backspaced, and @command{tar} will work on them
8697 once @command{tar} is modified to do so.
8698
8699 Archives created with the @option{--multi-volume}, @option{--label}, and
8700 @option{--incremental} (@option{-G}) options may not be readable by other version
8701 of @command{tar}. In particular, restoring a file that was split over
8702 a volume boundary will require some careful work with @command{dd}, if
8703 it can be done at all. Other versions of @command{tar} may also create
8704 an empty file whose name is that of the volume header. Some versions
8705 of @command{tar} may create normal files instead of directories archived
8706 with the @option{--incremental} (@option{-G}) option.
8707
8708 @node Common Problems and Solutions
8709 @section Some Common Problems and their Solutions
8710
8711 @ifclear PUBLISH
8712
8713 @format
8714 errors from system:
8715 permission denied
8716 no such file or directory
8717 not owner
8718
8719 errors from @command{tar}:
8720 directory checksum error
8721 header format error
8722
8723 errors from media/system:
8724 i/o error
8725 device busy
8726 @end format
8727
8728 @end ifclear
8729
8730 @node Blocking
8731 @section Blocking
8732 @UNREVISED
8733
8734 @dfn{Block} and @dfn{record} terminology is rather confused, and it
8735 is also confusing to the expert reader. On the other hand, readers
8736 who are new to the field have a fresh mind, and they may safely skip
8737 the next two paragraphs, as the remainder of this manual uses those
8738 two terms in a quite consistent way.
8739
8740 John Gilmore, the writer of the public domain @command{tar} from which
8741 @GNUTAR{} was originally derived, wrote (June 1995):
8742
8743 @quotation
8744 The nomenclature of tape drives comes from IBM, where I believe
8745 they were invented for the IBM 650 or so. On IBM mainframes, what
8746 is recorded on tape are tape blocks. The logical organization of
8747 data is into records. There are various ways of putting records into
8748 blocks, including @code{F} (fixed sized records), @code{V} (variable
8749 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
8750 to a block), @code{VB} (variable size records, @var{n} to a block),
8751 @code{VSB} (variable spanned blocked: variable sized records that can
8752 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
8753 parameter specified this to the operating system.
8754
8755 The Unix man page on @command{tar} was totally confused about this.
8756 When I wrote @code{PD TAR}, I used the historically correct terminology
8757 (@command{tar} writes data records, which are grouped into blocks).
8758 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
8759 here), and now Fran@,{c}ois has migrated that terminology back
8760 into the source code too.
8761 @end quotation
8762
8763 The term @dfn{physical block} means the basic transfer chunk from or
8764 to a device, after which reading or writing may stop without anything
8765 being lost. In this manual, the term @dfn{block} usually refers to
8766 a disk physical block, @emph{assuming} that each disk block is 512
8767 bytes in length. It is true that some disk devices have different
8768 physical blocks, but @command{tar} ignore these differences in its own
8769 format, which is meant to be portable, so a @command{tar} block is always
8770 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
8771 The term @dfn{logical block} often represents the basic chunk of
8772 allocation of many disk blocks as a single entity, which the operating
8773 system treats somewhat atomically; this concept is only barely used
8774 in @GNUTAR{}.
8775
8776 The term @dfn{physical record} is another way to speak of a physical
8777 block, those two terms are somewhat interchangeable. In this manual,
8778 the term @dfn{record} usually refers to a tape physical block,
8779 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
8780 It is true that archives may be put on disk or used with pipes,
8781 but nevertheless, @command{tar} tries to read and write the archive one
8782 @dfn{record} at a time, whatever the medium in use. One record is made
8783 up of an integral number of blocks, and this operation of putting many
8784 disk blocks into a single tape block is called @dfn{reblocking}, or
8785 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
8786 the logical organization of many characters into something meaningful
8787 to the application. The term @dfn{unit record} describes a small set
8788 of characters which are transmitted whole to or by the application,
8789 and often refers to a line of text. Those two last terms are unrelated
8790 to what we call a @dfn{record} in @GNUTAR{}.
8791
8792 When writing to tapes, @command{tar} writes the contents of the archive
8793 in chunks known as @dfn{records}. To change the default blocking
8794 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
8795 @var{512-size}}) option. Each record will then be composed of
8796 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
8797 @xref{Standard}.) Each file written to the archive uses at least one
8798 full record. As a result, using a larger record size can result in
8799 more wasted space for small files. On the other hand, a larger record
8800 size can often be read and written much more efficiently.
8801
8802 Further complicating the problem is that some tape drives ignore the
8803 blocking entirely. For these, a larger record size can still improve
8804 performance (because the software layers above the tape drive still
8805 honor the blocking), but not as dramatically as on tape drives that
8806 honor blocking.
8807
8808 When reading an archive, @command{tar} can usually figure out the
8809 record size on itself. When this is the case, and a non-standard
8810 record size was used when the archive was created, @command{tar} will
8811 print a message about a non-standard blocking factor, and then operate
8812 normally. On some tape devices, however, @command{tar} cannot figure
8813 out the record size itself. On most of those, you can specify a
8814 blocking factor (with @option{--blocking-factor}) larger than the
8815 actual blocking factor, and then use the @option{--read-full-records}
8816 (@option{-B}) option. (If you specify a blocking factor with
8817 @option{--blocking-factor} and don't use the
8818 @option{--read-full-records} option, then @command{tar} will not
8819 attempt to figure out the recording size itself.) On some devices,
8820 you must always specify the record size exactly with
8821 @option{--blocking-factor} when reading, because @command{tar} cannot
8822 figure it out. In any case, use @option{--list} (@option{-t}) before
8823 doing any extractions to see whether @command{tar} is reading the archive
8824 correctly.
8825
8826 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
8827 putting them into records is to put a whole number of them (one or
8828 more) into each record. @command{tar} records are all the same size;
8829 at the end of the file there's a block containing all zeros, which
8830 is how you tell that the remainder of the last record(s) are garbage.
8831
8832 In a standard @command{tar} file (no options), the block size is 512
8833 and the record size is 10240, for a blocking factor of 20. What the
8834 @option{--blocking-factor} option does is sets the blocking factor,
8835 changing the record size while leaving the block size at 512 bytes.
8836 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
8837 most tape drives these days prefer much bigger records in order to
8838 stream and not waste tape. When writing tapes for myself, some tend
8839 to use a factor of the order of 2048, say, giving a record size of
8840 around one megabyte.
8841
8842 If you use a blocking factor larger than 20, older @command{tar}
8843 programs might not be able to read the archive, so we recommend this
8844 as a limit to use in practice. @GNUTAR{}, however,
8845 will support arbitrarily large record sizes, limited only by the
8846 amount of virtual memory or the physical characteristics of the tape
8847 device.
8848
8849 @menu
8850 * Format Variations:: Format Variations
8851 * Blocking Factor:: The Blocking Factor of an Archive
8852 @end menu
8853
8854 @node Format Variations
8855 @subsection Format Variations
8856 @cindex Format Parameters
8857 @cindex Format Options
8858 @cindex Options, archive format specifying
8859 @cindex Options, format specifying
8860 @UNREVISED
8861
8862 Format parameters specify how an archive is written on the archive
8863 media. The best choice of format parameters will vary depending on
8864 the type and number of files being archived, and on the media used to
8865 store the archive.
8866
8867 To specify format parameters when accessing or creating an archive,
8868 you can use the options described in the following sections.
8869 If you do not specify any format parameters, @command{tar} uses
8870 default parameters. You cannot modify a compressed archive.
8871 If you create an archive with the @option{--blocking-factor} option
8872 specified (@pxref{Blocking Factor}), you must specify that
8873 blocking-factor when operating on the archive. @xref{Formats}, for other
8874 examples of format parameter considerations.
8875
8876 @node Blocking Factor
8877 @subsection The Blocking Factor of an Archive
8878 @cindex Blocking Factor
8879 @cindex Record Size
8880 @cindex Number of blocks per record
8881 @cindex Number of bytes per record
8882 @cindex Bytes per record
8883 @cindex Blocks per record
8884 @UNREVISED
8885
8886 @opindex blocking-factor
8887 The data in an archive is grouped into blocks, which are 512 bytes.
8888 Blocks are read and written in whole number multiples called
8889 @dfn{records}. The number of blocks in a record (ie. the size of a
8890 record in units of 512 bytes) is called the @dfn{blocking factor}.
8891 The @option{--blocking-factor=@var{512-size}} (@option{-b
8892 @var{512-size}}) option specifies the blocking factor of an archive.
8893 The default blocking factor is typically 20 (i.e., 10240 bytes), but
8894 can be specified at installation. To find out the blocking factor of
8895 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
8896 This may not work on some devices.
8897
8898 Records are separated by gaps, which waste space on the archive media.
8899 If you are archiving on magnetic tape, using a larger blocking factor
8900 (and therefore larger records) provides faster throughput and allows you
8901 to fit more data on a tape (because there are fewer gaps). If you are
8902 archiving on cartridge, a very large blocking factor (say 126 or more)
8903 greatly increases performance. A smaller blocking factor, on the other
8904 hand, may be useful when archiving small files, to avoid archiving lots
8905 of nulls as @command{tar} fills out the archive to the end of the record.
8906 In general, the ideal record size depends on the size of the
8907 inter-record gaps on the tape you are using, and the average size of the
8908 files you are archiving. @xref{create}, for information on
8909 writing archives.
8910
8911 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
8912
8913 Archives with blocking factors larger than 20 cannot be read
8914 by very old versions of @command{tar}, or by some newer versions
8915 of @command{tar} running on old machines with small address spaces.
8916 With @GNUTAR{}, the blocking factor of an archive is limited
8917 only by the maximum record size of the device containing the archive,
8918 or by the amount of available virtual memory.
8919
8920 Also, on some systems, not using adequate blocking factors, as sometimes
8921 imposed by the device drivers, may yield unexpected diagnostics. For
8922 example, this has been reported:
8923
8924 @smallexample
8925 Cannot write to /dev/dlt: Invalid argument
8926 @end smallexample
8927
8928 @noindent
8929 In such cases, it sometimes happen that the @command{tar} bundled by
8930 the system is aware of block size idiosyncrasies, while @GNUTAR{}
8931 requires an explicit specification for the block size,
8932 which it cannot guess. This yields some people to consider
8933 @GNUTAR{} is misbehaving, because by comparison,
8934 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
8935 for example, might resolve the problem.
8936
8937 If you use a non-default blocking factor when you create an archive, you
8938 must specify the same blocking factor when you modify that archive. Some
8939 archive devices will also require you to specify the blocking factor when
8940 reading that archive, however this is not typically the case. Usually, you
8941 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
8942 reports a non-default record size and then lists the archive members as
8943 it would normally. To extract files from an archive with a non-standard
8944 blocking factor (particularly if you're not sure what the blocking factor
8945 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
8946 specifying a blocking factor larger then the blocking factor of the archive
8947 (ie. @samp{tar --extract --read-full-records --blocking-factor=300}.
8948 @xref{list}, for more information on the @option{--list} (@option{-t})
8949 operation. @xref{Reading}, for a more detailed explanation of that option.
8950
8951 @table @option
8952 @item --blocking-factor=@var{number}
8953 @itemx -b @var{number}
8954 Specifies the blocking factor of an archive. Can be used with any
8955 operation, but is usually not necessary with @option{--list} (@option{-t}).
8956 @end table
8957
8958 Device blocking
8959
8960 @table @option
8961 @item -b @var{blocks}
8962 @itemx --blocking-factor=@var{blocks}
8963 Set record size to @math{@var{blocks} * 512} bytes.
8964
8965 This option is used to specify a @dfn{blocking factor} for the archive.
8966 When reading or writing the archive, @command{tar}, will do reads and writes
8967 of the archive in records of @math{@var{block}*512} bytes. This is true
8968 even when the archive is compressed. Some devices requires that all
8969 write operations be a multiple of a certain size, and so, @command{tar}
8970 pads the archive out to the next record boundary.
8971
8972 The default blocking factor is set when @command{tar} is compiled, and is
8973 typically 20. Blocking factors larger than 20 cannot be read by very
8974 old versions of @command{tar}, or by some newer versions of @command{tar}
8975 running on old machines with small address spaces.
8976
8977 With a magnetic tape, larger records give faster throughput and fit
8978 more data on a tape (because there are fewer inter-record gaps).
8979 If the archive is in a disk file or a pipe, you may want to specify
8980 a smaller blocking factor, since a large one will result in a large
8981 number of null bytes at the end of the archive.
8982
8983 When writing cartridge or other streaming tapes, a much larger
8984 blocking factor (say 126 or more) will greatly increase performance.
8985 However, you must specify the same blocking factor when reading or
8986 updating the archive.
8987
8988 Apparently, Exabyte drives have a physical block size of 8K bytes.
8989 If we choose our blocksize as a multiple of 8k bytes, then the problem
8990 seems to disappear. Id est, we are using block size of 112 right
8991 now, and we haven't had the problem since we switched@dots{}
8992
8993 With @GNUTAR{} the blocking factor is limited only
8994 by the maximum record size of the device containing the archive, or by
8995 the amount of available virtual memory.
8996
8997 However, deblocking or reblocking is virtually avoided in a special
8998 case which often occurs in practice, but which requires all the
8999 following conditions to be simultaneously true:
9000 @itemize @bullet
9001 @item
9002 the archive is subject to a compression option,
9003 @item
9004 the archive is not handled through standard input or output, nor
9005 redirected nor piped,
9006 @item
9007 the archive is directly handled to a local disk, instead of any special
9008 device,
9009 @item
9010 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9011 invocation.
9012 @end itemize
9013
9014 If the output goes directly to a local disk, and not through
9015 stdout, then the last write is not extended to a full record size.
9016 Otherwise, reblocking occurs. Here are a few other remarks on this
9017 topic:
9018
9019 @itemize @bullet
9020
9021 @item
9022 @command{gzip} will complain about trailing garbage if asked to
9023 uncompress a compressed archive on tape, there is an option to turn
9024 the message off, but it breaks the regularity of simply having to use
9025 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9026 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9027 Gailly, by sending a copy of this message to him.
9028
9029 @item
9030 @command{compress} does not show this problem, but as Jean-loup pointed
9031 out to Michael, @samp{compress -d} silently adds garbage after
9032 the result of decompression, which tar ignores because it already
9033 recognized its end-of-file indicator. So this bug may be safely
9034 ignored.
9035
9036 @item
9037 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9038 but will still return an exit status of 2 which tar reports in turn.
9039 @command{tar} might ignore the exit status returned, but I hate doing
9040 that, as it weakens the protection @command{tar} offers users against
9041 other possible problems at decompression time. If @command{gzip} was
9042 silently skipping trailing zeros @emph{and} also avoiding setting the
9043 exit status in this innocuous case, that would solve this situation.
9044
9045 @item
9046 @command{tar} should become more solid at not stopping to read a pipe at
9047 the first null block encountered. This inelegantly breaks the pipe.
9048 @command{tar} should rather drain the pipe out before exiting itself.
9049 @end itemize
9050
9051 @opindex ignore-zeros, short description
9052 @item -i
9053 @itemx --ignore-zeros
9054 Ignore blocks of zeros in archive (means EOF).
9055
9056 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9057 of zeros in the archive. Normally a block of zeros indicates the
9058 end of the archive, but when reading a damaged archive, or one which
9059 was created by concatenating several archives together, this option
9060 allows @command{tar} to read the entire archive. This option is not on
9061 by default because many versions of @command{tar} write garbage after
9062 the zeroed blocks.
9063
9064 Note that this option causes @command{tar} to read to the end of the
9065 archive file, which may sometimes avoid problems when multiple files
9066 are stored on a single physical tape.
9067
9068 @opindex read-full-records, short description
9069 @item -B
9070 @itemx --read-full-records
9071 Reblock as we read (for reading 4.2BSD pipes).
9072
9073 If @option{--read-full-records} is used, @command{tar}
9074 will not panic if an attempt to read a record from the archive does
9075 not return a full record. Instead, @command{tar} will keep reading
9076 until it has obtained a full
9077 record.
9078
9079 This option is turned on by default when @command{tar} is reading
9080 an archive from standard input, or from a remote machine. This is
9081 because on BSD Unix systems, a read of a pipe will return however
9082 much happens to be in the pipe, even if it is less than @command{tar}
9083 requested. If this option was not used, @command{tar} would fail as
9084 soon as it read an incomplete record from the pipe.
9085
9086 This option is also useful with the commands for updating an archive.
9087
9088 @end table
9089
9090 Tape blocking
9091
9092 @FIXME{Appropriate options should be moved here from elsewhere.}
9093
9094 @cindex blocking factor
9095 @cindex tape blocking
9096
9097 When handling various tapes or cartridges, you have to take care of
9098 selecting a proper blocking, that is, the number of disk blocks you
9099 put together as a single tape block on the tape, without intervening
9100 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9101 with no information on it, used for decelerating the tape to a
9102 full stop, and for later regaining the reading or writing speed.
9103 When the tape driver starts reading a record, the record has to
9104 be read whole without stopping, as a tape gap is needed to stop the
9105 tape motion without loosing information.
9106
9107 @cindex Exabyte blocking
9108 @cindex DAT blocking
9109 Using higher blocking (putting more disk blocks per tape block) will use
9110 the tape more efficiently as there will be less tape gaps. But reading
9111 such tapes may be more difficult for the system, as more memory will be
9112 required to receive at once the whole record. Further, if there is a
9113 reading error on a huge record, this is less likely that the system will
9114 succeed in recovering the information. So, blocking should not be too
9115 low, nor it should be too high. @command{tar} uses by default a blocking of
9116 20 for historical reasons, and it does not really matter when reading or
9117 writing to disk. Current tape technology would easily accommodate higher
9118 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9119 We were told that for some DLT drives, the blocking should be a multiple
9120 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9121 Other manufacturers may use different recommendations for the same tapes.
9122 This might also depends of the buffering techniques used inside modern
9123 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9124 Others request blocking to be some exponent of two.
9125
9126 So, there is no fixed rule for blocking. But blocking at read time
9127 should ideally be the same as blocking used at write time. At one place
9128 I know, with a wide variety of equipment, they found it best to use a
9129 blocking of 32 to guarantee that their tapes are fully interchangeable.
9130
9131 I was also told that, for recycled tapes, prior erasure (by the same
9132 drive unit that will be used to create the archives) sometimes lowers
9133 the error rates observed at rewriting time.
9134
9135 I might also use @option{--number-blocks} instead of
9136 @option{--block-number}, so @option{--block} will then expand to
9137 @option{--blocking-factor} unambiguously.
9138
9139 @node Many
9140 @section Many Archives on One Tape
9141
9142 @FIXME{Appropriate options should be moved here from elsewhere.}
9143
9144 @findex ntape @r{device}
9145 Most tape devices have two entries in the @file{/dev} directory, or
9146 entries that come in pairs, which differ only in the minor number for
9147 this device. Let's take for example @file{/dev/tape}, which often
9148 points to the only or usual tape device of a given system. There might
9149 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9150 name is the @emph{rewinding} version of the device, while the name
9151 having @samp{nr} in it is the @emph{no rewinding} version of the same
9152 device.
9153
9154 A rewinding tape device will bring back the tape to its beginning point
9155 automatically when this device is opened or closed. Since @command{tar}
9156 opens the archive file before using it and closes it afterwards, this
9157 means that a simple:
9158
9159 @smallexample
9160 $ @kbd{tar cf /dev/tape @var{directory}}
9161 @end smallexample
9162
9163 @noindent
9164 will reposition the tape to its beginning both prior and after saving
9165 @var{directory} contents to it, thus erasing prior tape contents and
9166 making it so that any subsequent write operation will destroy what has
9167 just been saved.
9168
9169 @cindex tape positioning
9170 So, a rewinding device is normally meant to hold one and only one file.
9171 If you want to put more than one @command{tar} archive on a given tape, you
9172 will need to avoid using the rewinding version of the tape device. You
9173 will also have to pay special attention to tape positioning. Errors in
9174 positioning may overwrite the valuable data already on your tape. Many
9175 people, burnt by past experiences, will only use rewinding devices and
9176 limit themselves to one file per tape, precisely to avoid the risk of
9177 such errors. Be fully aware that writing at the wrong position on a
9178 tape loses all information past this point and most probably until the
9179 end of the tape, and this destroyed information @emph{cannot} be
9180 recovered.
9181
9182 To save @var{directory-1} as a first archive at the beginning of a
9183 tape, and leave that tape ready for a second archive, you should use:
9184
9185 @smallexample
9186 $ @kbd{mt -f /dev/nrtape rewind}
9187 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9188 @end smallexample
9189
9190 @cindex tape marks
9191 @dfn{Tape marks} are special magnetic patterns written on the tape
9192 media, which are later recognizable by the reading hardware. These
9193 marks are used after each file, when there are many on a single tape.
9194 An empty file (that is to say, two tape marks in a row) signal the
9195 logical end of the tape, after which no file exist. Usually,
9196 non-rewinding tape device drivers will react to the close request issued
9197 by @command{tar} by first writing two tape marks after your archive, and by
9198 backspacing over one of these. So, if you remove the tape at that time
9199 from the tape drive, it is properly terminated. But if you write
9200 another file at the current position, the second tape mark will be
9201 erased by the new information, leaving only one tape mark between files.
9202
9203 So, you may now save @var{directory-2} as a second archive after the
9204 first on the same tape by issuing the command:
9205
9206 @smallexample
9207 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9208 @end smallexample
9209
9210 @noindent
9211 and so on for all the archives you want to put on the same tape.
9212
9213 Another usual case is that you do not write all the archives the same
9214 day, and you need to remove and store the tape between two archive
9215 sessions. In general, you must remember how many files are already
9216 saved on your tape. Suppose your tape already has 16 files on it, and
9217 that you are ready to write the 17th. You have to take care of skipping
9218 the first 16 tape marks before saving @var{directory-17}, say, by using
9219 these commands:
9220
9221 @smallexample
9222 $ @kbd{mt -f /dev/nrtape rewind}
9223 $ @kbd{mt -f /dev/nrtape fsf 16}
9224 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9225 @end smallexample
9226
9227 In all the previous examples, we put aside blocking considerations, but
9228 you should do the proper things for that as well. @xref{Blocking}.
9229
9230 @menu
9231 * Tape Positioning:: Tape Positions and Tape Marks
9232 * mt:: The @command{mt} Utility
9233 @end menu
9234
9235 @node Tape Positioning
9236 @subsection Tape Positions and Tape Marks
9237 @UNREVISED
9238
9239 Just as archives can store more than one file from the file system,
9240 tapes can store more than one archive file. To keep track of where
9241 archive files (or any other type of file stored on tape) begin and
9242 end, tape archive devices write magnetic @dfn{tape marks} on the
9243 archive media. Tape drives write one tape mark between files,
9244 two at the end of all the file entries.
9245
9246 If you think of data as a series of records "rrrr"'s, and tape marks as
9247 "*"'s, a tape might look like the following:
9248
9249 @smallexample
9250 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9251 @end smallexample
9252
9253 Tape devices read and write tapes using a read/write @dfn{tape
9254 head}---a physical part of the device which can only access one
9255 point on the tape at a time. When you use @command{tar} to read or
9256 write archive data from a tape device, the device will begin reading
9257 or writing from wherever on the tape the tape head happens to be,
9258 regardless of which archive or what part of the archive the tape
9259 head is on. Before writing an archive, you should make sure that no
9260 data on the tape will be overwritten (unless it is no longer needed).
9261 Before reading an archive, you should make sure the tape head is at
9262 the beginning of the archive you want to read. You can do it manually
9263 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9264 that automatically (@pxref{Scripted Restoration}).
9265
9266 If you want to add new archive file entries to a tape, you should
9267 advance the tape to the end of the existing file entries, backspace
9268 over the last tape mark, and write the new archive file. If you were
9269 to add two archives to the example above, the tape might look like the
9270 following:
9271
9272 @smallexample
9273 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9274 @end smallexample
9275
9276 @node mt
9277 @subsection The @command{mt} Utility
9278 @UNREVISED
9279
9280 @FIXME{Is it true that this only works on non-block devices?
9281 should explain the difference, (fixed or variable).}
9282 @xref{Blocking Factor}.
9283
9284 You can use the @command{mt} utility to advance or rewind a tape past a
9285 specified number of archive files on the tape. This will allow you
9286 to move to the beginning of an archive before extracting or reading
9287 it, or to the end of all the archives before writing a new one.
9288 @FIXME{Why isn't there an "advance 'til you find two tape marks
9289 together"?}
9290
9291 The syntax of the @command{mt} command is:
9292
9293 @smallexample
9294 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9295 @end smallexample
9296
9297 where @var{tapename} is the name of the tape device, @var{number} is
9298 the number of times an operation is performed (with a default of one),
9299 and @var{operation} is one of the following:
9300
9301 @FIXME{is there any use for record operations?}
9302
9303 @table @option
9304 @item eof
9305 @itemx weof
9306 Writes @var{number} tape marks at the current position on the tape.
9307
9308 @item fsf
9309 Moves tape position forward @var{number} files.
9310
9311 @item bsf
9312 Moves tape position back @var{number} files.
9313
9314 @item rewind
9315 Rewinds the tape. (Ignores @var{number}).
9316
9317 @item offline
9318 @itemx rewoff1
9319 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9320
9321 @item status
9322 Prints status information about the tape unit.
9323
9324 @end table
9325
9326 @FIXME{Is there a better way to frob the spacing on the list?}
9327
9328 If you don't specify a @var{tapename}, @command{mt} uses the environment
9329 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} uses the device
9330 @file{/dev/rmt12}.
9331
9332 @command{mt} returns a 0 exit status when the operation(s) were
9333 successful, 1 if the command was unrecognized, and 2 if an operation
9334 failed.
9335
9336 @node Using Multiple Tapes
9337 @section Using Multiple Tapes
9338 @UNREVISED
9339
9340 Often you might want to write a large archive, one larger than will fit
9341 on the actual tape you are using. In such a case, you can run multiple
9342 @command{tar} commands, but this can be inconvenient, particularly if you
9343 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9344 Therefore, @command{tar} supports multiple tapes automatically.
9345
9346 Use @option{--multi-volume} (@option{-M}) on the command line, and
9347 then @command{tar} will, when it reaches the end of the tape, prompt
9348 for another tape, and continue the archive. Each tape will have an
9349 independent archive, and can be read without needing the other. (As
9350 an exception to this, the file that @command{tar} was archiving when
9351 it ran out of tape will usually be split between the two archives; in
9352 this case you need to extract from the first archive, using
9353 @option{--multi-volume}, and then put in the second tape when
9354 prompted, so @command{tar} can restore both halves of the file.)
9355
9356 @GNUTAR{} multi-volume archives do not use a truly portable format.
9357 You need @GNUTAR{} at both ends to process them properly.
9358
9359 When prompting for a new tape, @command{tar} accepts any of the following
9360 responses:
9361
9362 @table @kbd
9363 @item ?
9364 Request @command{tar} to explain possible responses
9365 @item q
9366 Request @command{tar} to exit immediately.
9367 @item n @var{file-name}
9368 Request @command{tar} to write the next volume on the file @var{file-name}.
9369 @item !
9370 Request @command{tar} to run a subshell. This option can be disabled
9371 by giving @option{--restrict} command line option to @command{tar}.
9372 @item y
9373 Request @command{tar} to begin writing the next volume.
9374 @end table
9375
9376 (You should only type @samp{y} after you have changed the tape;
9377 otherwise @command{tar} will write over the volume it just finished.)
9378
9379 @cindex End-of-archive info script
9380 @cindex Info script
9381 @anchor{info-script}
9382 @opindex info-script
9383 @opindex new-volume-script
9384 If you want more elaborate behavior than this, give @command{tar} the
9385 @option{--info-script=@var{script-name}}
9386 (@option{--new-volume-script=@var{script-name}}, @option{-F
9387 @var{script-name}}) option. The file @var{script-name} is expected to
9388 be a program (or shell script) to be run instead of the normal
9389 prompting procedure. It is executed without any command line
9390 arguments. Additional data is passed to it via the following
9391 environment variables:
9392
9393 @table @env
9394 @vrindex TAR_VERSION, info script environment variable
9395 @item TAR_VERSION
9396 @GNUTAR{} version number.
9397
9398 @vrindex TAR_ARCHIVE, info script environment variable
9399 @item TAR_ARCHIVE
9400 The name of the archive @command{tar} is processing.
9401
9402 @vrindex TAR_VOLUME, info script environment variable
9403 @item TAR_VOLUME
9404 Ordinal number of the volume @command{tar} is about to start.
9405
9406 @vrindex TAR_SUBCOMMAND, info script environment variable
9407 @item TAR_SUBCOMMAND
9408 Short option describing the operation @command{tar} is executed.
9409 @xref{Operations}, for a complete list of subcommand options.
9410
9411 @vrindex TAR_FORMAT, info script environment variable
9412 @item TAR_FORMAT
9413 Format of the archive being processed. @xref{Formats}, for a complete
9414 list of archive format names.
9415 @end table
9416
9417 The info script can instruct @command{tar} to use new archive name,
9418 by writing in to file descriptor 3 (see below for an
9419 example).
9420
9421 If the info script fails, @command{tar} exits; otherwise, it begins
9422 writing the next volume.
9423
9424 The method @command{tar} uses to detect end of tape is not perfect, and
9425 fails on some operating systems or on some devices. You can use the
9426 @option{--tape-length=@var{size}} (@option{-L @var{size}}) option if
9427 @command{tar} can't detect the end of the tape itself. This option
9428 selects @option{--multi-volume} (@option{-M}) automatically. The
9429 @var{size} argument should then be the usable size of the tape in
9430 units of 1024 bytes. But for many devices, and floppy disks in
9431 particular, this option is never required for real, as far as we know.
9432
9433 @cindex Volume number file
9434 @cindex volno file
9435 @anchor{volno-file}
9436 @opindex volno-file
9437 The volume number used by @command{tar} in its tape-change prompt
9438 can be changed; if you give the
9439 @option{--volno-file=@var{file-of-number}} option, then
9440 @var{file-of-number} should be an unexisting file to be created, or
9441 else, a file already containing a decimal number. That number will be
9442 used as the volume number of the first volume written. When
9443 @command{tar} is finished, it will rewrite the file with the
9444 now-current volume number. (This does not change the volume number
9445 written on a tape label, as per @ref{label}, it @emph{only} affects
9446 the number used in the prompt.)
9447
9448 If you want @command{tar} to cycle through a series of files or tape
9449 drives, there are three approaches to choose from. First of all, you
9450 can give @command{tar} multiple @option{--file} options. In this case
9451 the specified files will be used, in sequence, as the successive
9452 volumes of the archive. Only when the first one in the sequence needs
9453 to be used again will @command{tar} prompt for a tape change (or run
9454 the info script). Secondly, you can use the @samp{n} response to the
9455 tape-change prompt, and, finally, you can use an info script, that
9456 writes new archive name to file descriptor. The following example
9457 illustrates this approach:
9458
9459 @smallexample
9460 @group
9461 #! /bin/sh
9462 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
9463
9464 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
9465 case $TAR_SUBCOMMAND in
9466 -c) ;;
9467 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
9468 ;;
9469 *) exit 1
9470 esac
9471
9472 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
9473 @end group
9474 @end smallexample
9475
9476 Each volume of a multi-volume archive is an independent @command{tar}
9477 archive, complete in itself. For example, you can list or extract any
9478 volume alone; just don't specify @option{--multi-volume}
9479 (@option{-M}). However, if one file in the archive is split across
9480 volumes, the only way to extract it successfully is with a
9481 multi-volume extract command @option{--extract --multi-volume}
9482 (@option{-xM}) starting on or before the volume where the file begins.
9483
9484 For example, let's presume someone has two tape drives on a system
9485 named @file{/dev/tape0} and @file{/dev/tape1}. For having @GNUTAR{}
9486 to switch to the second drive when it needs to write the
9487 second tape, and then back to the first tape, etc., just do either of:
9488
9489 @smallexample
9490 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
9491 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
9492 @end smallexample
9493
9494 @menu
9495 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9496 * Tape Files:: Tape Files
9497 * Tarcat:: Concatenate Volumes into a Single Archive
9498
9499 @end menu
9500
9501 @node Multi-Volume Archives
9502 @subsection Archives Longer than One Tape or Disk
9503 @cindex Multi-volume archives
9504 @UNREVISED
9505
9506 @opindex multi-volume
9507 To create an archive that is larger than will fit on a single unit of
9508 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9509 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9510 archive can be manipulated like any other archive (provided the
9511 @option{--multi-volume} option is specified), but is stored on more
9512 than one tape or disk.
9513
9514 When you specify @option{--multi-volume}, @command{tar} does not report an
9515 error when it comes to the end of an archive volume (when reading), or
9516 the end of the media (when writing). Instead, it prompts you to load
9517 a new storage volume. If the archive is on a magnetic tape, you
9518 should change tapes when you see the prompt; if the archive is on a
9519 floppy disk, you should change disks; etc.
9520
9521 You can read each individual volume of a multi-volume archive as if it
9522 were an archive by itself. For example, to list the contents of one
9523 volume, use @option{--list}, without @option{--multi-volume} specified.
9524 To extract an archive member from one volume (assuming it is described
9525 that volume), use @option{--extract}, again without
9526 @option{--multi-volume}.
9527
9528 If an archive member is split across volumes (ie. its entry begins on
9529 one volume of the media and ends on another), you need to specify
9530 @option{--multi-volume} to extract it successfully. In this case, you
9531 should load the volume where the archive member starts, and use
9532 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
9533 volumes as it needs them. @xref{extracting archives}, for more
9534 information about extracting archives.
9535
9536 @option{--info-script=@var{script-name}}
9537 (@option{--new-volume-script=@var{script-name}}, @option{-F
9538 @var{script-name}}) (@pxref{info-script}) is like
9539 @option{--multi-volume} (@option{-M}), except that @command{tar} does
9540 not prompt you directly to change media volumes when a volume is
9541 full---instead, @command{tar} runs commands you have stored in
9542 @var{script-name}. For example, this option can be used to eject
9543 cassettes, or to broadcast messages such as @samp{Someone please come
9544 change my tape} when performing unattended backups. When
9545 @var{script-name} is done, @command{tar} will assume that the media
9546 has been changed.
9547
9548 Multi-volume archives can be modified like any other archive. To add
9549 files to a multi-volume archive, you need to only mount the last
9550 volume of the archive media (and new volumes, if needed). For all
9551 other operations, you need to use the entire archive.
9552
9553 If a multi-volume archive was labeled using
9554 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9555 (@pxref{label}) when it was created, @command{tar} will not
9556 automatically label volumes which are added later. To label
9557 subsequent volumes, specify @option{--label=@var{archive-label}} again
9558 in conjunction with the @option{--append}, @option{--update} or
9559 @option{--concatenate} operation.
9560
9561 @cindex Labeling multi-volume archives
9562 @FIXME{example}
9563
9564 @FIXME{There should be a sample program here, including an exit
9565 before end. Is the exit status even checked in tar? :-(}
9566
9567 @table @option
9568 @item --multi-volume
9569 @itemx -M
9570 Creates a multi-volume archive, when used in conjunction with
9571 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9572 archive, specify @option{--multi-volume} in conjunction with that
9573 operation.
9574
9575 @item --info-script=@var{program-file}
9576 @itemx --new-volume-script=@var{program-file}
9577 @itemx -F @var{program-file}
9578 Creates a multi-volume archive via a script. Used in conjunction with
9579 @option{--create} (@option{-c}). @xref{info-script}, dor a detailed discussion.
9580 @end table
9581
9582 Beware that there is @emph{no} real standard about the proper way, for
9583 a @command{tar} archive, to span volume boundaries. If you have a
9584 multi-volume created by some vendor's @command{tar}, there is almost
9585 no chance you could read all the volumes with @GNUTAR{}.
9586 The converse is also true: you may not expect
9587 multi-volume archives created by @GNUTAR{} to be
9588 fully recovered by vendor's @command{tar}. Since there is little
9589 chance that, in mixed system configurations, some vendor's
9590 @command{tar} will work on another vendor's machine, and there is a
9591 great chance that @GNUTAR{} will work on most of
9592 them, your best bet is to install @GNUTAR{} on all
9593 machines between which you know exchange of files is possible.
9594
9595 @node Tape Files
9596 @subsection Tape Files
9597 @UNREVISED
9598
9599 To give the archive a name which will be recorded in it, use the
9600 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
9601 option. This will write a special block identifying
9602 @var{volume-label} as the name of the archive to the front of the
9603 archive which will be displayed when the archive is listed with
9604 @option{--list}. If you are creating a multi-volume archive with
9605 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
9606 volume label will have @samp{Volume @var{nnn}} appended to the name
9607 you give, where @var{nnn} is the number of the volume of the archive.
9608 (If you use the @option{--label=@var{volume-label}}) option when
9609 reading an archive, it checks to make sure the label on the tape
9610 matches the one you give. @xref{label}.
9611
9612 When @command{tar} writes an archive to tape, it creates a single
9613 tape file. If multiple archives are written to the same tape, one
9614 after the other, they each get written as separate tape files. When
9615 extracting, it is necessary to position the tape at the right place
9616 before running @command{tar}. To do this, use the @command{mt} command.
9617 For more information on the @command{mt} command and on the organization
9618 of tapes into a sequence of tape files, see @ref{mt}.
9619
9620 People seem to often do:
9621
9622 @smallexample
9623 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
9624 @end smallexample
9625
9626 or such, for pushing a common date in all volumes or an archive set.
9627
9628 @node Tarcat
9629 @subsection Concatenate Volumes into a Single Archive
9630
9631 @pindex tarcat
9632 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
9633 archive to a single @command{tar} archive. Simply concatenating all
9634 volumes into one will not work, since each volume carries an additional
9635 information at the beginning. @GNUTAR{} is shipped with the shell
9636 script @command{tarcat} designed for this purpose.
9637
9638 The script takes a list of files comprising a multi-volume archive
9639 and creates the resulting archive at the standard output. For example:
9640
9641 @smallexample
9642 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
9643 @end smallexample
9644
9645 The script implements a simple heuristics to determine the format of
9646 the first volume file and to decide how to process the rest of the
9647 files. However, it makes no attempt to verify whether the files are
9648 given in order or even if they are valid @command{tar} archives.
9649 It uses @command{dd} and does not filter its standard error, so you
9650 will usually see lots of spurious messages.
9651
9652 @FIXME{The script is not installed. Should we install it?}
9653
9654 @node label
9655 @section Including a Label in the Archive
9656 @cindex Labeling an archive
9657 @cindex Labels on the archive media
9658 @UNREVISED
9659
9660 @opindex label
9661 To avoid problems caused by misplaced paper labels on the archive
9662 media, you can include a @dfn{label} entry---an archive member which
9663 contains the name of the archive---in the archive itself. Use the
9664 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9665 option in conjunction with the @option{--create} operation to include
9666 a label entry in the archive as it is being created.
9667
9668 @table @option
9669 @item --label=@var{archive-label}
9670 @itemx -V @var{archive-label}
9671 Includes an @dfn{archive-label} at the beginning of the archive when
9672 the archive is being created, when used in conjunction with the
9673 @option{--create} operation. Checks to make sure the archive label
9674 matches the one specified (when used in conjunction with any other
9675 operation.
9676 @end table
9677
9678 If you create an archive using both
9679 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9680 and @option{--multi-volume} (@option{-M}), each volume of the archive
9681 will have an archive label of the form @samp{@var{archive-label}
9682 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
9683 next, and so on. @xref{Using Multiple Tapes}, for information on
9684 creating multiple volume archives.
9685
9686 @cindex Volume label, listing
9687 @cindex Listing volume label
9688 The volume label will be displayed by @option{--list} along with
9689 the file contents. If verbose display is requested, it will also be
9690 explicitely marked as in the example below:
9691
9692 @smallexample
9693 @group
9694 $ @kbd{tar --verbose --list --file=iamanarchive}
9695 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
9696 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
9697 @end group
9698 @end smallexample
9699
9700 @opindex test-label
9701 @anchor{--test-label option}
9702 However, @option{--list} option will cause listing entire
9703 contents of the archive, which may be undesirable (for example, if the
9704 archive is stored on a tape). You can request checking only the volume
9705 by specifying @option{--test-label} option. This option reads only the
9706 first block of an archive, so it can be used with slow storage
9707 devices. For example:
9708
9709 @smallexample
9710 @group
9711 $ @kbd{tar --test-label --file=iamanarchive}
9712 iamalabel
9713 @end group
9714 @end smallexample
9715
9716 If @option{--test-label} is used with a single command line
9717 argument, @command{tar} compares the volume label with the
9718 argument. It exits with code 0 if the two strings match, and with code
9719 2 otherwise. In this case no output is displayed. For example:
9720
9721 @smallexample
9722 @group
9723 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
9724 @result{} 0
9725 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
9726 @result{} 1
9727 @end group
9728 @end smallexample
9729
9730 If you request any operation, other than @option{--create}, along
9731 with using @option{--label} option, @command{tar} will first check if
9732 the archive label matches the one specified and will refuse to proceed
9733 if it does not. Use this as a safety precaution to avoid accidentally
9734 overwriting existing archives. For example, if you wish to add files
9735 to @file{archive}, presumably labelled with string @samp{My volume},
9736 you will get:
9737
9738 @smallexample
9739 @group
9740 $ @kbd{tar -rf archive --label 'My volume' .}
9741 tar: Archive not labeled to match `My volume'
9742 @end group
9743 @end smallexample
9744
9745 @noindent
9746 in case its label does not match. This will work even if
9747 @file{archive} is not labelled at all.
9748
9749 Similarly, @command{tar} will refuse to list or extract the
9750 archive if its label doesn't match the @var{archive-label}
9751 specified. In those cases, @var{archive-label} argument is interpreted
9752 as a globbing-style pattern which must match the actual magnetic
9753 volume label. @xref{exclude}, for a precise description of how match
9754 is attempted@footnote{Previous versions of @command{tar} used full
9755 regular expression matching, or before that, only exact string
9756 matching, instead of wildcard matchers. We decided for the sake of
9757 simplicity to use a uniform matching device through
9758 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
9759 the volume label matcher will also suffix @var{archive-label} by
9760 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
9761 up. Since the volume numbering is automatically added in labels at
9762 creation time, it sounded logical to equally help the user taking care
9763 of it when the archive is being read.
9764
9765 The @option{--label} was once called @option{--volume}, but is not
9766 available under that name anymore.
9767
9768 You can also use @option{--label} to get a common information on
9769 all tapes of a series. For having this information different in each
9770 series created through a single script used on a regular basis, just
9771 manage to get some date string as part of the label. For example:
9772
9773 @smallexample
9774 @group
9775 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
9776 $ @kbd{tar --create --file=/dev/tape --multi-volume \
9777 --volume="Daily backup for `date +%Y-%m-%d`"}
9778 @end group
9779 @end smallexample
9780
9781 Also note that each label has its own date and time, which corresponds
9782 to when @GNUTAR{} initially attempted to write it,
9783 often soon after the operator launches @command{tar} or types the
9784 carriage return telling that the next tape is ready. Comparing date
9785 labels does give an idea of tape throughput only if the delays for
9786 rewinding tapes and the operator switching them were negligible, which
9787 is usually not the case.
9788
9789 @node verify
9790 @section Verifying Data as It is Stored
9791 @cindex Verifying a write operation
9792 @cindex Double-checking a write operation
9793
9794 @table @option
9795 @item -W
9796 @itemx --verify
9797 @opindex verify, short description
9798 Attempt to verify the archive after writing.
9799 @end table
9800
9801 This option causes @command{tar} to verify the archive after writing it.
9802 Each volume is checked after it is written, and any discrepancies
9803 are recorded on the standard error output.
9804
9805 Verification requires that the archive be on a back-space-able medium.
9806 This means pipes, some cartridge tape drives, and some other devices
9807 cannot be verified.
9808
9809 You can insure the accuracy of an archive by comparing files in the
9810 system with archive members. @command{tar} can compare an archive to the
9811 file system as the archive is being written, to verify a write
9812 operation, or can compare a previously written archive, to insure that
9813 it is up to date.
9814
9815 @opindex verify, using with @option{--create}
9816 @opindex create, using with @option{--verify}
9817 To check for discrepancies in an archive immediately after it is
9818 written, use the @option{--verify} (@option{-W}) option in conjunction with
9819 the @option{--create} operation. When this option is
9820 specified, @command{tar} checks archive members against their counterparts
9821 in the file system, and reports discrepancies on the standard error.
9822
9823 To verify an archive, you must be able to read it from before the end
9824 of the last written entry. This option is useful for detecting data
9825 errors on some tapes. Archives written to pipes, some cartridge tape
9826 drives, and some other devices cannot be verified.
9827
9828 One can explicitly compare an already made archive with the file
9829 system by using the @option{--compare} (@option{--diff}, @option{-d})
9830 option, instead of using the more automatic @option{--verify} option.
9831 @xref{compare}.
9832
9833 Note that these two options have a slightly different intent. The
9834 @option{--compare} option checks how identical are the logical contents of some
9835 archive with what is on your disks, while the @option{--verify} option is
9836 really for checking if the physical contents agree and if the recording
9837 media itself is of dependable quality. So, for the @option{--verify}
9838 operation, @command{tar} tries to defeat all in-memory cache pertaining to
9839 the archive, while it lets the speed optimization undisturbed for the
9840 @option{--compare} option. If you nevertheless use @option{--compare} for
9841 media verification, you may have to defeat the in-memory cache yourself,
9842 maybe by opening and reclosing the door latch of your recording unit,
9843 forcing some doubt in your operating system about the fact this is really
9844 the same volume as the one just written or read.
9845
9846 The @option{--verify} option would not be necessary if drivers were indeed
9847 able to detect dependably all write failures. This sometimes require many
9848 magnetic heads, some able to read after the writes occurred. One would
9849 not say that drivers unable to detect all cases are necessarily flawed,
9850 as long as programming is concerned.
9851
9852 The @option{--verify} (@option{-W}) option will not work in
9853 conjunction with the @option{--multi-volume} (@option{-M}) option or
9854 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
9855 and @option{--delete} operations. @xref{Operations}, for more
9856 information on these operations.
9857
9858 Also, since @command{tar} normally strips leading @samp{/} from file
9859 names (@pxref{absolute}), a command like @samp{tar --verify -cf
9860 /tmp/foo.tar /etc} will work as desired only if the working directory is
9861 @file{/}, as @command{tar} uses the archive's relative member names
9862 (e.g., @file{etc/motd}) when verifying the archive.
9863
9864 @node Write Protection
9865 @section Write Protection
9866
9867 Almost all tapes and diskettes, and in a few rare cases, even disks can
9868 be @dfn{write protected}, to protect data on them from being changed.
9869 Once an archive is written, you should write protect the media to prevent
9870 the archive from being accidentally overwritten or deleted. (This will
9871 protect the archive from being changed with a tape or floppy drive---it
9872 will not protect it from magnet fields or other physical hazards).
9873
9874 The write protection device itself is usually an integral part of the
9875 physical media, and can be a two position (write enabled/write
9876 disabled) switch, a notch which can be popped out or covered, a ring
9877 which can be removed from the center of a tape reel, or some other
9878 changeable feature.
9879
9880 @node Changes
9881 @appendix Changes
9882
9883 This appendix lists some important user-visible changes between
9884 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
9885 version of this document is available at
9886 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
9887 @GNUTAR{} documentation page}.
9888
9889 @table @asis
9890 @item Use of globbing patterns when listing and extracting.
9891
9892 Previous versions of GNU tar assumed shell-style globbing when
9893 extracting from or listing an archive. For example:
9894
9895 @smallexample
9896 $ @kbd{tar xf foo.tar '*.c'}
9897 @end smallexample
9898
9899 would extract all files whose names end in @samp{.c}. This behavior
9900 was not documented and was incompatible with traditional tar
9901 implementations. Therefore, starting from version 1.15.91, GNU tar
9902 no longer uses globbing by default. For example, the above invocation
9903 is now interpreted as a request to extract from the archive the file
9904 named @file{*.c}.
9905
9906 To facilitate transition to the new behavior for those users who got
9907 used to the previous incorrect one, @command{tar} will print a warning
9908 if it finds out that a requested member was not found in the archive
9909 and its name looks like a globbing pattern. For example:
9910
9911 @smallexample
9912 $ @kbd{tar xf foo.tar '*.c'}
9913 tar: Pattern matching characters used in file names. Please,
9914 tar: use --wildcards to enable pattern matching, or --no-wildcards to
9915 tar: suppress this warning.
9916 tar: *.c: Not found in archive
9917 tar: Error exit delayed from previous errors
9918 @end smallexample
9919
9920 To treat member names as globbing patterns, use --wildcards option.
9921 If you want to tar to mimic the behavior of versions prior to 1.15.91,
9922 add this option to your @env{TAR_OPTIONS} variable.
9923
9924 @xref{Wildcards}, for the detailed discussion of the use of globbing
9925 patterns by @GNUTAR{}.
9926
9927 @item Use of short option @option{-o}.
9928
9929 Earlier versions of @GNUTAR{} understood @option{-o} command line
9930 option as a synonym for @option{--old-archive}.
9931
9932 @GNUTAR{} starting from version 1.13.90 understands this option as
9933 a synonym for @option{--no-same-owner}. This is compatible with
9934 UNIX98 @command{tar} implementations.
9935
9936 However, to facilitate transition, @option{-o} option retains its
9937 old semantics when it is used with one of archive-creation commands.
9938 Users are encouraged to use @option{--format=oldgnu} instead.
9939
9940 It is especially important, since versions of @acronym{GNU} Automake
9941 up to and including 1.8.4 invoke tar with this option to produce
9942 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
9943 of this issue and its implications.
9944
9945 @FIXME{Change the first argument to tar-formats if and when Automake
9946 people accept my patch to the documentation, and the new Automake is
9947 out --Sergey 2006-05-25}.
9948 @xref{Options, tar-v7, Changing Automake's Behavior,
9949 automake, GNU Automake}, for a description on how to use various
9950 archive formats with @command{automake}.
9951
9952 Future versions of @GNUTAR{} will understand @option{-o} only as a
9953 synonym for @option{--no-same-owner}.
9954
9955 @item Use of short option @option{-l}
9956
9957 Earlier versions of @GNUTAR{} understood @option{-l} option as a
9958 synonym for @option{--one-file-system}. Since such usage contradicted
9959 to UNIX98 specification and harmed compatibility with other
9960 implementation, it was declared deprecated in version 1.14. However,
9961 to facilitate transition to its new semantics, it was supported by
9962 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
9963 variant of @option{--check-links} was introduced in version 1.15.91.
9964
9965 @item Use of options @option{--portability} and @option{--old-archive}
9966
9967 These options are deprecated. Please use @option{--format=v7} instead.
9968
9969 @item Use of option @option{--posix}
9970
9971 This option is deprecated. Please use @option{--format=posix} instead.
9972 @end table
9973
9974 @node Configuring Help Summary
9975 @appendix Configuring Help Summary
9976
9977 Running @kbd{tar --help} displays the short @command{tar} option
9978 summary (@pxref{help}). This summary is organised by @dfn{groups} of
9979 semantically close options. The options within each group are printed
9980 in the following order: a short option, eventually followed by a list
9981 of corresponding long option names, followed by a short description of
9982 the option. For example, here is an excerpt from the actual @kbd{tar
9983 --help} output:
9984
9985 @verbatim
9986 Main operation mode:
9987
9988 -A, --catenate, --concatenate append tar files to an archive
9989 -c, --create create a new archive
9990 -d, --diff, --compare find differences between archive and
9991 file system
9992 --delete delete from the archive
9993 @end verbatim
9994
9995 @vrindex ARGP_HELP_FMT, environment variable
9996 The exact visual representation of the help output is configurable via
9997 @env{ARGP_HELP_FMT} environment variable. The value of this variable
9998 is a comma-separated list of @dfn{format variable} assignments. There
9999 are two kinds of format variables. An @dfn{offset variable} keeps the
10000 offset of some part of help output text from the leftmost column on
10001 the screen. A @dfn{boolean} variable is a flag that toggles some
10002 output feature on or off. Depending on the type of the corresponding
10003 variable, there are two kinds of assignments:
10004
10005 @table @asis
10006 @item Offset assignment
10007
10008 The assignment to an offset variable has the following syntax:
10009
10010 @smallexample
10011 @var{variable}=@var{value}
10012 @end smallexample
10013
10014 @noindent
10015 where @var{variable} is the variable name, and @var{value} is a
10016 numeric value to be assigned to the variable.
10017
10018 @item Boolean assignment
10019
10020 To assign @code{true} value to a variable, simply put this variable name. To
10021 assign @code{false} value, prefix the variable name with @samp{no-}. For
10022 example:
10023
10024 @smallexample
10025 @group
10026 # Assign @code{true} value:
10027 dup-args
10028 # Assign @code{false} value:
10029 no-dup-args
10030 @end group
10031 @end smallexample
10032 @end table
10033
10034 Following variables are declared:
10035
10036 @deftypevr {Help Output} boolean dup-args
10037 If true, arguments for an option are shown with both short and long
10038 options, even when a given option has both forms, for example:
10039
10040 @smallexample
10041 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10042 @end smallexample
10043
10044 If false, then if an option has both short and long forms, the
10045 argument is only shown with the long one, for example:
10046
10047 @smallexample
10048 -f, --file=ARCHIVE use archive file or device ARCHIVE
10049 @end smallexample
10050
10051 @noindent
10052 and a message indicating that the argument is applicable to both
10053 forms is printed below the options. This message can be disabled
10054 using @code{dup-args-note} (see below).
10055
10056 The default is false.
10057 @end deftypevr
10058
10059 @deftypevr {Help Output} boolean dup-args-note
10060 If this variable is true, which is the default, the following notice
10061 is displayed at the end of the help output:
10062
10063 @quotation
10064 Mandatory or optional arguments to long options are also mandatory or
10065 optional for any corresponding short options.
10066 @end quotation
10067
10068 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10069 variables @code{dup-args} or @code{dup-args-note} should be set.
10070 @end deftypevr
10071
10072 @deftypevr {Help Output} offset short-opt-col
10073 Column in which short options start. Default is 2.
10074
10075 @smallexample
10076 @group
10077 $ @kbd{tar --help|grep ARCHIVE}
10078 -f, --file=ARCHIVE use archive file or device ARCHIVE
10079 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10080 -f, --file=ARCHIVE use archive file or device ARCHIVE
10081 @end group
10082 @end smallexample
10083 @end deftypevr
10084
10085 @deftypevr {Help Output} offset long-opt-col
10086 Column in which long options start. Default is 6. For example:
10087
10088 @smallexample
10089 @group
10090 $ @kbd{tar --help|grep ARCHIVE}
10091 -f, --file=ARCHIVE use archive file or device ARCHIVE
10092 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10093 -f, --file=ARCHIVE use archive file or device ARCHIVE
10094 @end group
10095 @end smallexample
10096 @end deftypevr
10097
10098 @deftypevr {Help Output} offset doc-opt-col
10099 Column in which @dfn{doc options} start. A doc option isn't actually
10100 an option, but rather an arbitrary piece of documentation that is
10101 displayed in much the same manner as the options. For example, in
10102 the description of @option{--format} option:
10103
10104 @smallexample
10105 @group
10106 -H, --format=FORMAT create archive of the given format.
10107
10108 FORMAT is one of the following:
10109
10110 gnu GNU tar 1.13.x format
10111 oldgnu GNU format as per tar <= 1.12
10112 pax POSIX 1003.1-2001 (pax) format
10113 posix same as pax
10114 ustar POSIX 1003.1-1988 (ustar) format
10115 v7 old V7 tar format
10116 @end group
10117 @end smallexample
10118
10119 @noindent
10120 the format names are doc options. Thus, if you set
10121 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10122 will look as follows:
10123
10124 @smallexample
10125 @group
10126 -H, --format=FORMAT create archive of the given format.
10127
10128 FORMAT is one of the following:
10129
10130 gnu GNU tar 1.13.x format
10131 oldgnu GNU format as per tar <= 1.12
10132 pax POSIX 1003.1-2001 (pax) format
10133 posix same as pax
10134 ustar POSIX 1003.1-1988 (ustar) format
10135 v7 old V7 tar format
10136 @end group
10137 @end smallexample
10138 @end deftypevr
10139
10140 @deftypevr {Help Output} offset opt-doc-col
10141 Column in which option description starts. Default is 29.
10142
10143 @smallexample
10144 @group
10145 $ @kbd{tar --help|grep ARCHIVE}
10146 -f, --file=ARCHIVE use archive file or device ARCHIVE
10147 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10148 -f, --file=ARCHIVE use archive file or device ARCHIVE
10149 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10150 -f, --file=ARCHIVE
10151 use archive file or device ARCHIVE
10152 @end group
10153 @end smallexample
10154
10155 @noindent
10156 Notice, that the description starts on a separate line if
10157 @code{opt-doc-col} value is too small.
10158 @end deftypevr
10159
10160 @deftypevr {Help Output} offset header-col
10161 Column in which @dfn{group headers} are printed. A group header is a
10162 descriptive text preceding an option group. For example, in the
10163 following text:
10164
10165 @verbatim
10166 Main operation mode:
10167
10168 -A, --catenate, --concatenate append tar files to
10169 an archive
10170 -c, --create create a new archive
10171 @end verbatim
10172 @noindent
10173 @samp{Main operation mode:} is the group header.
10174
10175 The default value is 1.
10176 @end deftypevr
10177
10178 @deftypevr {Help Output} offset usage-indent
10179 Indentation of wrapped usage lines. Affects @option{--usage}
10180 output. Default is 12.
10181 @end deftypevr
10182
10183 @deftypevr {Help Output} offset rmargin
10184 Right margin of the text output. Used for wrapping.
10185 @end deftypevr
10186
10187 @node Genfile
10188 @appendix Genfile
10189 @include genfile.texi
10190
10191 @node Snapshot Files
10192 @appendix Format of the Incremental Snapshot Files
10193 @include snapshot.texi
10194
10195 @node Free Software Needs Free Documentation
10196 @appendix Free Software Needs Free Documentation
10197 @include freemanuals.texi
10198
10199 @node Copying This Manual
10200 @appendix Copying This Manual
10201
10202 @menu
10203 * GNU Free Documentation License:: License for copying this manual
10204 @end menu
10205
10206 @include fdl.texi
10207
10208 @node Index of Command Line Options
10209 @appendix Index of Command Line Options
10210
10211 This appendix contains an index of all @GNUTAR{} long command line
10212 options. The options are listed without the preceeding double-dash.
10213
10214 @FIXME{@itemize
10215 @item Make sure @emph{all} options are indexed.
10216 @item Provide an index of short options
10217 @end itemize}
10218
10219 @printindex op
10220
10221 @node Index
10222 @appendix Index
10223
10224 @printindex cp
10225
10226 @summarycontents
10227 @contents
10228 @bye
10229
10230 @c Local variables:
10231 @c texinfo-column-for-description: 32
10232 @c End:
This page took 0.456434 seconds and 5 git commands to generate.