]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Pass command line arguments to external commands.
[chaz/tar] / doc / tar.texi
1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename tar.info
4 @include version.texi
5 @settitle GNU tar @value{VERSION}
6 @setchapternewpage odd
7
8 @finalout
9
10 @smallbook
11 @c %**end of header
12
13 @c Maintenance notes:
14 @c 1. Pay attention to @FIXME{}s and @UNREVISED{}s
15 @c 2. Before creating final variant:
16 @c 2.1. Run 'make check-options' to make sure all options are properly
17 @c documented;
18 @c 2.2. Run 'make master-menu' (see comment before the master menu).
19
20 @include rendition.texi
21 @include value.texi
22
23 @defcodeindex op
24 @defcodeindex kw
25
26 @c Put everything in one index (arbitrarily chosen to be the concept index).
27 @syncodeindex fn cp
28 @syncodeindex ky cp
29 @syncodeindex pg cp
30 @syncodeindex vr cp
31 @syncodeindex kw cp
32
33 @copying
34
35 This manual is for @acronym{GNU} @command{tar} (version
36 @value{VERSION}, @value{UPDATED}), which creates and extracts files
37 from archives.
38
39 Copyright @copyright{} 1992, 1994--1997, 1999--2001, 2003--2013 Free
40 Software Foundation, Inc.
41
42 @quotation
43 Permission is granted to copy, distribute and/or modify this document
44 under the terms of the GNU Free Documentation License, Version 1.3 or
45 any later version published by the Free Software Foundation; with the
46 Invariant Sections being ``GNU General Public License'', with the
47 Front-Cover Texts being ``A GNU Manual'', and with the Back-Cover Texts
48 as in (a) below. A copy of the license is included in the section
49 entitled ``GNU Free Documentation License''.
50
51 (a) The FSF's Back-Cover Text is: ``You have the freedom to
52 copy and modify this GNU manual.''
53 @end quotation
54 @end copying
55
56 @dircategory Archiving
57 @direntry
58 * Tar: (tar). Making tape (or disk) archives.
59 @end direntry
60
61 @dircategory Individual utilities
62 @direntry
63 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
64 @end direntry
65
66 @shorttitlepage @acronym{GNU} @command{tar}
67
68 @titlepage
69 @title @acronym{GNU} tar: an archiver tool
70 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
71 @author John Gilmore, Jay Fenlason et al.
72
73 @page
74 @vskip 0pt plus 1filll
75 @insertcopying
76 @end titlepage
77
78 @ifnottex
79 @node Top
80 @top @acronym{GNU} tar: an archiver tool
81
82 @insertcopying
83
84 @cindex file archival
85 @cindex archiving files
86
87 The first part of this master menu lists the major nodes in this Info
88 document. The rest of the menu lists all the lower level nodes.
89 @end ifnottex
90
91 @c The master menu goes here.
92 @c
93 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
94 @c loaded and run texinfo-master-menu.
95 @c To update it from the command line, run
96 @c
97 @c make master-menu
98
99 @menu
100 * Introduction::
101 * Tutorial::
102 * tar invocation::
103 * operations::
104 * Backups::
105 * Choosing::
106 * Date input formats::
107 * Formats::
108 * Media::
109 * Reliability and security::
110
111 Appendices
112
113 * Changes::
114 * Configuring Help Summary::
115 * Fixing Snapshot Files::
116 * Tar Internals::
117 * Genfile::
118 * Free Software Needs Free Documentation::
119 * GNU Free Documentation License::
120 * Index of Command Line Options::
121 * Index::
122
123 @detailmenu
124 --- The Detailed Node Listing ---
125
126 Introduction
127
128 * Book Contents:: What this Book Contains
129 * Definitions:: Some Definitions
130 * What tar Does:: What @command{tar} Does
131 * Naming tar Archives:: How @command{tar} Archives are Named
132 * Authors:: @GNUTAR{} Authors
133 * Reports:: Reporting bugs or suggestions
134
135 Tutorial Introduction to @command{tar}
136
137 * assumptions::
138 * stylistic conventions::
139 * basic tar options:: Basic @command{tar} Operations and Options
140 * frequent operations::
141 * Two Frequent Options::
142 * create:: How to Create Archives
143 * list:: How to List Archives
144 * extract:: How to Extract Members from an Archive
145 * going further::
146
147 Two Frequently Used Options
148
149 * file tutorial::
150 * verbose tutorial::
151 * help tutorial::
152
153 How to Create Archives
154
155 * prepare for examples::
156 * Creating the archive::
157 * create verbose::
158 * short create::
159 * create dir::
160
161 How to List Archives
162
163 * list dir::
164
165 How to Extract Members from an Archive
166
167 * extracting archives::
168 * extracting files::
169 * extract dir::
170 * extracting untrusted archives::
171 * failing commands::
172
173 Invoking @GNUTAR{}
174
175 * Synopsis::
176 * using tar options::
177 * Styles::
178 * All Options::
179 * help::
180 * defaults::
181 * verbose::
182 * checkpoints::
183 * warnings::
184 * interactive::
185
186 The Three Option Styles
187
188 * Long Options:: Long Option Style
189 * Short Options:: Short Option Style
190 * Old Options:: Old Option Style
191 * Mixing:: Mixing Option Styles
192
193 All @command{tar} Options
194
195 * Operation Summary::
196 * Option Summary::
197 * Short Option Summary::
198
199 @GNUTAR{} Operations
200
201 * Basic tar::
202 * Advanced tar::
203 * create options::
204 * extract options::
205 * backup::
206 * Applications::
207 * looking ahead::
208
209 Advanced @GNUTAR{} Operations
210
211 * Operations::
212 * append::
213 * update::
214 * concatenate::
215 * delete::
216 * compare::
217
218 How to Add Files to Existing Archives: @option{--append}
219
220 * appending files:: Appending Files to an Archive
221 * multiple::
222
223 Updating an Archive
224
225 * how to update::
226
227 Options Used by @option{--create}
228
229 * override:: Overriding File Metadata.
230 * Ignore Failed Read::
231
232 Options Used by @option{--extract}
233
234 * Reading:: Options to Help Read Archives
235 * Writing:: Changing How @command{tar} Writes Files
236 * Scarce:: Coping with Scarce Resources
237
238 Options to Help Read Archives
239
240 * read full records::
241 * Ignore Zeros::
242
243 Changing How @command{tar} Writes Files
244
245 * Dealing with Old Files::
246 * Overwrite Old Files::
247 * Keep Old Files::
248 * Keep Newer Files::
249 * Unlink First::
250 * Recursive Unlink::
251 * Data Modification Times::
252 * Setting Access Permissions::
253 * Directory Modification Times and Permissions::
254 * Writing to Standard Output::
255 * Writing to an External Program::
256 * remove files::
257
258 Coping with Scarce Resources
259
260 * Starting File::
261 * Same Order::
262
263 Performing Backups and Restoring Files
264
265 * Full Dumps:: Using @command{tar} to Perform Full Dumps
266 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
267 * Backup Levels:: Levels of Backups
268 * Backup Parameters:: Setting Parameters for Backups and Restoration
269 * Scripted Backups:: Using the Backup Scripts
270 * Scripted Restoration:: Using the Restore Script
271
272 Setting Parameters for Backups and Restoration
273
274 * General-Purpose Variables::
275 * Magnetic Tape Control::
276 * User Hooks::
277 * backup-specs example:: An Example Text of @file{Backup-specs}
278
279 Choosing Files and Names for @command{tar}
280
281 * file:: Choosing the Archive's Name
282 * Selecting Archive Members::
283 * files:: Reading Names from a File
284 * exclude:: Excluding Some Files
285 * wildcards:: Wildcards Patterns and Matching
286 * quoting styles:: Ways of Quoting Special Characters in Names
287 * transform:: Modifying File and Member Names
288 * after:: Operating Only on New Files
289 * recurse:: Descending into Directories
290 * one:: Crossing File System Boundaries
291
292 Reading Names from a File
293
294 * nul::
295
296 Excluding Some Files
297
298 * problems with exclude::
299
300 Wildcards Patterns and Matching
301
302 * controlling pattern-matching::
303
304 Crossing File System Boundaries
305
306 * directory:: Changing Directory
307 * absolute:: Absolute File Names
308
309 Date input formats
310
311 * General date syntax:: Common rules.
312 * Calendar date items:: 19 Dec 1994.
313 * Time of day items:: 9:20pm.
314 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
315 * Day of week items:: Monday and others.
316 * Relative items in date strings:: next tuesday, 2 years ago.
317 * Pure numbers in date strings:: 19931219, 1440.
318 * Seconds since the Epoch:: @@1078100502.
319 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
320 * Authors of parse_datetime:: Bellovin, Eggert, Salz, Berets, et al.
321
322 Controlling the Archive Format
323
324 * Compression:: Using Less Space through Compression
325 * Attributes:: Handling File Attributes
326 * Portability:: Making @command{tar} Archives More Portable
327 * cpio:: Comparison of @command{tar} and @command{cpio}
328
329 Using Less Space through Compression
330
331 * gzip:: Creating and Reading Compressed Archives
332 * sparse:: Archiving Sparse Files
333
334 Creating and Reading Compressed Archives
335
336 * lbzip2:: Using lbzip2 with @GNUTAR{}.
337
338 Making @command{tar} Archives More Portable
339
340 * Portable Names:: Portable Names
341 * dereference:: Symbolic Links
342 * hard links:: Hard Links
343 * old:: Old V7 Archives
344 * ustar:: Ustar Archives
345 * gnu:: GNU and old GNU format archives.
346 * posix:: @acronym{POSIX} archives
347 * Checksumming:: Checksumming Problems
348 * Large or Negative Values:: Large files, negative time stamps, etc.
349 * Other Tars:: How to Extract GNU-Specific Data Using
350 Other @command{tar} Implementations
351
352 @GNUTAR{} and @acronym{POSIX} @command{tar}
353
354 * PAX keywords:: Controlling Extended Header Keywords.
355
356 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
357
358 * Split Recovery:: Members Split Between Volumes
359 * Sparse Recovery:: Sparse Members
360
361 Tapes and Other Archive Media
362
363 * Device:: Device selection and switching
364 * Remote Tape Server::
365 * Common Problems and Solutions::
366 * Blocking:: Blocking
367 * Many:: Many archives on one tape
368 * Using Multiple Tapes:: Using Multiple Tapes
369 * label:: Including a Label in the Archive
370 * verify::
371 * Write Protection::
372
373 Blocking
374
375 * Format Variations:: Format Variations
376 * Blocking Factor:: The Blocking Factor of an Archive
377
378 Many Archives on One Tape
379
380 * Tape Positioning:: Tape Positions and Tape Marks
381 * mt:: The @command{mt} Utility
382
383 Using Multiple Tapes
384
385 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
386 * Tape Files:: Tape Files
387 * Tarcat:: Concatenate Volumes into a Single Archive
388
389
390 Tar Internals
391
392 * Standard:: Basic Tar Format
393 * Extensions:: @acronym{GNU} Extensions to the Archive Format
394 * Sparse Formats:: Storing Sparse Files
395 * Snapshot Files::
396 * Dumpdir::
397
398 Storing Sparse Files
399
400 * Old GNU Format::
401 * PAX 0:: PAX Format, Versions 0.0 and 0.1
402 * PAX 1:: PAX Format, Version 1.0
403
404 Genfile
405
406 * Generate Mode:: File Generation Mode.
407 * Status Mode:: File Status Mode.
408 * Exec Mode:: Synchronous Execution mode.
409
410 Copying This Manual
411
412 * GNU Free Documentation License:: License for copying this manual
413
414 @end detailmenu
415 @end menu
416
417 @node Introduction
418 @chapter Introduction
419
420 @GNUTAR{} creates
421 and manipulates @dfn{archives} which are actually collections of
422 many other files; the program provides users with an organized and
423 systematic method for controlling a large amount of data.
424 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
425 archives need not (and these days, typically do not) reside on tapes.
426
427 @menu
428 * Book Contents:: What this Book Contains
429 * Definitions:: Some Definitions
430 * What tar Does:: What @command{tar} Does
431 * Naming tar Archives:: How @command{tar} Archives are Named
432 * Authors:: @GNUTAR{} Authors
433 * Reports:: Reporting bugs or suggestions
434 @end menu
435
436 @node Book Contents
437 @section What this Book Contains
438
439 The first part of this chapter introduces you to various terms that will
440 recur throughout the book. It also tells you who has worked on @GNUTAR{}
441 and its documentation, and where you should send bug reports
442 or comments.
443
444 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
445 gentle introduction for people who are new to using @command{tar}. It is
446 meant to be self-contained, not requiring any reading from subsequent
447 chapters to make sense. It moves from topic to topic in a logical,
448 progressive order, building on information already explained.
449
450 Although the tutorial is paced and structured to allow beginners to
451 learn how to use @command{tar}, it is not intended solely for beginners.
452 The tutorial explains how to use the three most frequently used
453 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
454 two frequently used options (@samp{file} and @samp{verbose}). The other
455 chapters do not refer to the tutorial frequently; however, if a section
456 discusses something which is a complex variant of a basic concept, there
457 may be a cross-reference to that basic concept. (The entire book,
458 including the tutorial, assumes that the reader understands some basic
459 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
460
461 The third chapter presents the remaining five operations, and
462 information about using @command{tar} options and option syntax.
463
464 The other chapters are meant to be used as a reference. Each chapter
465 presents everything that needs to be said about a specific topic.
466
467 One of the chapters (@pxref{Date input formats}) exists in its
468 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
469 In addition, one section of this manual (@pxref{Standard}) contains a
470 big quote which is taken directly from @command{tar} sources.
471
472 In general, we give both long and short (abbreviated) option names
473 at least once in each section where the relevant option is covered, so
474 that novice readers will become familiar with both styles. (A few
475 options have no short versions, and the relevant sections will
476 indicate this.)
477
478 @node Definitions
479 @section Some Definitions
480
481 @cindex archive
482 @cindex tar archive
483 The @command{tar} program is used to create and manipulate @command{tar}
484 archives. An @dfn{archive} is a single file which contains the contents
485 of many files, while still identifying the names of the files, their
486 owner(s), and so forth. (In addition, archives record access
487 permissions, user and group, size in bytes, and data modification time.
488 Some archives also record the file names in each archived directory, as
489 well as other file and directory information.) You can use @command{tar}
490 to @dfn{create} a new archive in a specified directory.
491
492 @cindex member
493 @cindex archive member
494 @cindex file name
495 @cindex member name
496 The files inside an archive are called @dfn{members}. Within this
497 manual, we use the term @dfn{file} to refer only to files accessible in
498 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
499 @dfn{member} to refer only to the members of an archive. Similarly, a
500 @dfn{file name} is the name of a file, as it resides in the file system,
501 and a @dfn{member name} is the name of an archive member within the
502 archive.
503
504 @cindex extraction
505 @cindex unpacking
506 The term @dfn{extraction} refers to the process of copying an archive
507 member (or multiple members) into a file in the file system. Extracting
508 all the members of an archive is often called @dfn{extracting the
509 archive}. The term @dfn{unpack} can also be used to refer to the
510 extraction of many or all the members of an archive. Extracting an
511 archive does not destroy the archive's structure, just as creating an
512 archive does not destroy the copies of the files that exist outside of
513 the archive. You may also @dfn{list} the members in a given archive
514 (this is often thought of as ``printing'' them to the standard output,
515 or the command line), or @dfn{append} members to a pre-existing archive.
516 All of these operations can be performed using @command{tar}.
517
518 @node What tar Does
519 @section What @command{tar} Does
520
521 @cindex tar
522 The @command{tar} program provides the ability to create @command{tar}
523 archives, as well as various other kinds of manipulation. For example,
524 you can use @command{tar} on previously created archives to extract files,
525 to store additional files, or to update or list files which were already
526 stored.
527
528 Initially, @command{tar} archives were used to store files conveniently on
529 magnetic tape. The name @command{tar} comes from this use; it stands for
530 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
531 direct its output to available devices, files, or other programs (using
532 pipes). @command{tar} may even access remote devices or files (as archives).
533
534 You can use @command{tar} archives in many ways. We want to stress a few
535 of them: storage, backup, and transportation.
536
537 @FIXME{the following table entries need a bit of work.}
538 @table @asis
539 @item Storage
540 Often, @command{tar} archives are used to store related files for
541 convenient file transfer over a network. For example, the
542 @acronym{GNU} Project distributes its software bundled into
543 @command{tar} archives, so that all the files relating to a particular
544 program (or set of related programs) can be transferred as a single
545 unit.
546
547 A magnetic tape can store several files in sequence. However, the tape
548 has no names for these files; it only knows their relative position on
549 the tape. One way to store several files on one tape and retain their
550 names is by creating a @command{tar} archive. Even when the basic transfer
551 mechanism can keep track of names, as FTP can, the nuisance of handling
552 multiple files, directories, and multiple links makes @command{tar}
553 archives useful.
554
555 Archive files are also used for long-term storage. You can think of
556 this as transportation from the present into the future. (It is a
557 science-fiction idiom that you can move through time as well as in
558 space; the idea here is that @command{tar} can be used to move archives in
559 all dimensions, even time!)
560
561 @item Backup
562 Because the archive created by @command{tar} is capable of preserving
563 file information and directory structure, @command{tar} is commonly
564 used for performing full and incremental backups of disks. A backup
565 puts a collection of files (possibly pertaining to many users and
566 projects) together on a disk or a tape. This guards against
567 accidental destruction of the information in those files.
568 @GNUTAR{} has special features that allow it to be
569 used to make incremental and full dumps of all the files in a
570 file system.
571
572 @item Transportation
573 You can create an archive on one system, transfer it to another system,
574 and extract the contents there. This allows you to transport a group of
575 files from one system to another.
576 @end table
577
578 @node Naming tar Archives
579 @section How @command{tar} Archives are Named
580
581 Conventionally, @command{tar} archives are given names ending with
582 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
583 but this manual follows that convention in order to accustom readers to
584 it and to make examples more clear.
585
586 @cindex tar file
587 @cindex entry
588 @cindex tar entry
589 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
590 archive members as ``files'' or ``entries''. For people familiar with
591 the operation of @command{tar}, this causes no difficulty. However, in
592 this manual, we consistently refer to ``archives'' and ``archive
593 members'' to make learning to use @command{tar} easier for novice users.
594
595 @node Authors
596 @section @GNUTAR{} Authors
597
598 @GNUTAR{} was originally written by John Gilmore,
599 and modified by many people. The @acronym{GNU} enhancements were
600 written by Jay Fenlason, then Joy Kendall, and the whole package has
601 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
602 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
603 numerous and kind users.
604
605 We wish to stress that @command{tar} is a collective work, and owes much to
606 all those people who reported problems, offered solutions and other
607 insights, or shared their thoughts and suggestions. An impressive, yet
608 partial list of those contributors can be found in the @file{THANKS}
609 file from the @GNUTAR{} distribution.
610
611 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
612 sure i want to spell out the history in this detail, at least not for
613 the printed book. i'm just not sure it needs to be said this way.
614 i'll think about it.}
615
616 @FIXME{History is more important, and surely more interesting, than
617 actual names. Quoting names without history would be meaningless. FP}
618
619 Jay Fenlason put together a draft of a @GNUTAR{}
620 manual, borrowing notes from the original man page from John Gilmore.
621 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
622 Gorin worked on a tutorial and manual for @GNUTAR{}.
623 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
624 taking information from all these sources and merging them. Melissa
625 Weisshaus finally edited and redesigned the book to create version
626 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
627 by the current maintainer, Sergey Poznyakoff.
628
629 For version 1.12, Daniel Hagerty contributed a great deal of technical
630 consulting. In particular, he is the primary author of @ref{Backups}.
631
632 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
633 (see @url{http://savannah.gnu.org/projects/tar}), and
634 active development and maintenance work has started
635 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
636 Poznyakoff and Jeff Bailey.
637
638 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
639
640 @node Reports
641 @section Reporting bugs or suggestions
642
643 @cindex bug reports
644 @cindex reporting bugs
645 If you find problems or have suggestions about this program or manual,
646 please report them to @file{bug-tar@@gnu.org}.
647
648 When reporting a bug, please be sure to include as much detail as
649 possible, in order to reproduce it. @FIXME{Be more specific, I'd
650 like to make this node as detailed as 'Bug reporting' node in Emacs
651 manual.}
652
653 @node Tutorial
654 @chapter Tutorial Introduction to @command{tar}
655
656 This chapter guides you through some basic examples of three @command{tar}
657 operations: @option{--create}, @option{--list}, and @option{--extract}. If
658 you already know how to use some other version of @command{tar}, then you
659 may not need to read this chapter. This chapter omits most complicated
660 details about how @command{tar} works.
661
662 @menu
663 * assumptions::
664 * stylistic conventions::
665 * basic tar options:: Basic @command{tar} Operations and Options
666 * frequent operations::
667 * Two Frequent Options::
668 * create:: How to Create Archives
669 * list:: How to List Archives
670 * extract:: How to Extract Members from an Archive
671 * going further::
672 @end menu
673
674 @node assumptions
675 @section Assumptions this Tutorial Makes
676
677 This chapter is paced to allow beginners to learn about @command{tar}
678 slowly. At the same time, we will try to cover all the basic aspects of
679 these three operations. In order to accomplish both of these tasks, we
680 have made certain assumptions about your knowledge before reading this
681 manual, and the hardware you will be using:
682
683 @itemize @bullet
684 @item
685 Before you start to work through this tutorial, you should understand
686 what the terms ``archive'' and ``archive member'' mean
687 (@pxref{Definitions}). In addition, you should understand something
688 about how Unix-type operating systems work, and you should know how to
689 use some basic utilities. For example, you should know how to create,
690 list, copy, rename, edit, and delete files and directories; how to
691 change between directories; and how to figure out where you are in the
692 file system. You should have some basic understanding of directory
693 structure and how files are named according to which directory they are
694 in. You should understand concepts such as standard output and standard
695 input, what various definitions of the term @samp{argument} mean, and the
696 differences between relative and absolute file names. @FIXME{and what
697 else?}
698
699 @item
700 This manual assumes that you are working from your own home directory
701 (unless we state otherwise). In this tutorial, you will create a
702 directory to practice @command{tar} commands in. When we show file names,
703 we will assume that those names are relative to your home directory.
704 For example, my home directory is @file{/home/fsf/melissa}. All of
705 my examples are in a subdirectory of the directory named by that file
706 name; the subdirectory is called @file{practice}.
707
708 @item
709 In general, we show examples of archives which exist on (or can be
710 written to, or worked with from) a directory on a hard disk. In most
711 cases, you could write those archives to, or work with them on any other
712 device, such as a tape drive. However, some of the later examples in
713 the tutorial and next chapter will not work on tape drives.
714 Additionally, working with tapes is much more complicated than working
715 with hard disks. For these reasons, the tutorial does not cover working
716 with tape drives. @xref{Media}, for complete information on using
717 @command{tar} archives with tape drives.
718
719 @FIXME{this is a cop out. need to add some simple tape drive info.}
720 @end itemize
721
722 @node stylistic conventions
723 @section Stylistic Conventions
724
725 In the examples, @samp{$} represents a typical shell prompt. It
726 precedes lines you should type; to make this more clear, those lines are
727 shown in @kbd{this font}, as opposed to lines which represent the
728 computer's response; those lines are shown in @code{this font}, or
729 sometimes @samp{like this}.
730
731 @c When we have lines which are too long to be
732 @c displayed in any other way, we will show them like this:
733
734 @node basic tar options
735 @section Basic @command{tar} Operations and Options
736
737 @command{tar} can take a wide variety of arguments which specify and define
738 the actions it will have on the particular set of files or the archive.
739 The main types of arguments to @command{tar} fall into one of two classes:
740 operations, and options.
741
742 Some arguments fall into a class called @dfn{operations}; exactly one of
743 these is both allowed and required for any instance of using @command{tar};
744 you may @emph{not} specify more than one. People sometimes speak of
745 @dfn{operating modes}. You are in a particular operating mode when you
746 have specified the operation which specifies it; there are eight
747 operations in total, and thus there are eight operating modes.
748
749 The other arguments fall into the class known as @dfn{options}. You are
750 not required to specify any options, and you are allowed to specify more
751 than one at a time (depending on the way you are using @command{tar} at
752 that time). Some options are used so frequently, and are so useful for
753 helping you type commands more carefully that they are effectively
754 ``required''. We will discuss them in this chapter.
755
756 You can write most of the @command{tar} operations and options in any
757 of three forms: long (mnemonic) form, short form, and old style. Some
758 of the operations and options have no short or ``old'' forms; however,
759 the operations and options which we will cover in this tutorial have
760 corresponding abbreviations. We will indicate those abbreviations
761 appropriately to get you used to seeing them. Note, that the ``old
762 style'' option forms exist in @GNUTAR{} for compatibility with Unix
763 @command{tar}. In this book we present a full discussion of this way
764 of writing options and operations (@pxref{Old Options}), and we discuss
765 the other two styles of writing options (@xref{Long Options}, and
766 @pxref{Short Options}).
767
768 In the examples and in the text of this tutorial, we usually use the
769 long forms of operations and options; but the ``short'' forms produce
770 the same result and can make typing long @command{tar} commands easier.
771 For example, instead of typing
772
773 @smallexample
774 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
775 @end smallexample
776
777 @noindent
778 you can type
779 @smallexample
780 @kbd{tar -c -v -f afiles.tar apple angst aspic}
781 @end smallexample
782
783 @noindent
784 or even
785 @smallexample
786 @kbd{tar -cvf afiles.tar apple angst aspic}
787 @end smallexample
788
789 @noindent
790 For more information on option syntax, see @ref{Advanced tar}. In
791 discussions in the text, when we name an option by its long form, we
792 also give the corresponding short option in parentheses.
793
794 The term, ``option'', can be confusing at times, since ``operations''
795 are often lumped in with the actual, @emph{optional} ``options'' in certain
796 general class statements. For example, we just talked about ``short and
797 long forms of options and operations''. However, experienced @command{tar}
798 users often refer to these by shorthand terms such as, ``short and long
799 options''. This term assumes that the ``operations'' are included, also.
800 Context will help you determine which definition of ``options'' to use.
801
802 Similarly, the term ``command'' can be confusing, as it is often used in
803 two different ways. People sometimes refer to @command{tar} ``commands''.
804 A @command{tar} @dfn{command} is the entire command line of user input
805 which tells @command{tar} what to do --- including the operation, options,
806 and any arguments (file names, pipes, other commands, etc.). However,
807 you will also sometimes hear the term ``the @command{tar} command''. When
808 the word ``command'' is used specifically like this, a person is usually
809 referring to the @command{tar} @emph{operation}, not the whole line.
810 Again, use context to figure out which of the meanings the speaker
811 intends.
812
813 @node frequent operations
814 @section The Three Most Frequently Used Operations
815
816 Here are the three most frequently used operations (both short and long
817 forms), as well as a brief description of their meanings. The rest of
818 this chapter will cover how to use these operations in detail. We will
819 present the rest of the operations in the next chapter.
820
821 @table @option
822 @item --create
823 @itemx -c
824 Create a new @command{tar} archive.
825 @item --list
826 @itemx -t
827 List the contents of an archive.
828 @item --extract
829 @itemx -x
830 Extract one or more members from an archive.
831 @end table
832
833 @node Two Frequent Options
834 @section Two Frequently Used Options
835
836 To understand how to run @command{tar} in the three operating modes listed
837 previously, you also need to understand how to use two of the options to
838 @command{tar}: @option{--file} (which takes an archive file as an argument)
839 and @option{--verbose}. (You are usually not @emph{required} to specify
840 either of these options when you run @command{tar}, but they can be very
841 useful in making things more clear and helping you avoid errors.)
842
843 @menu
844 * file tutorial::
845 * verbose tutorial::
846 * help tutorial::
847 @end menu
848
849 @node file tutorial
850 @unnumberedsubsec The @option{--file} Option
851
852 @table @option
853 @xopindex{file, tutorial}
854 @item --file=@var{archive-name}
855 @itemx -f @var{archive-name}
856 Specify the name of an archive file.
857 @end table
858
859 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
860 use @command{tar}; this option determines the name of the archive file
861 that @command{tar} will work on.
862
863 @vrindex TAPE
864 If you don't specify this argument, then @command{tar} will examine
865 the environment variable @env{TAPE}. If it is set, its value will be
866 used as the archive name. Otherwise, @command{tar} will use the
867 default archive, determined at compile time. Usually it is
868 standard output or some physical tape drive attached to your machine
869 (you can verify what the default is by running @kbd{tar
870 --show-defaults}, @pxref{defaults}). If there is no tape drive
871 attached, or the default is not meaningful, then @command{tar} will
872 print an error message. The error message might look roughly like one
873 of the following:
874
875 @smallexample
876 tar: can't open /dev/rmt8 : No such device or address
877 tar: can't open /dev/rsmt0 : I/O error
878 @end smallexample
879
880 @noindent
881 To avoid confusion, we recommend that you always specify an archive file
882 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
883 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
884 @ref{file}.
885
886 @node verbose tutorial
887 @unnumberedsubsec The @option{--verbose} Option
888
889 @table @option
890 @xopindex{verbose, introduced}
891 @item --verbose
892 @itemx -v
893 Show the files being worked on as @command{tar} is running.
894 @end table
895
896 @option{--verbose} (@option{-v}) shows details about the results of running
897 @command{tar}. This can be especially useful when the results might not be
898 obvious. For example, if you want to see the progress of @command{tar} as
899 it writes files into the archive, you can use the @option{--verbose}
900 option. In the beginning, you may find it useful to use
901 @option{--verbose} at all times; when you are more accustomed to
902 @command{tar}, you will likely want to use it at certain times but not at
903 others. We will use @option{--verbose} at times to help make something
904 clear, and we will give many examples both using and not using
905 @option{--verbose} to show the differences.
906
907 Each instance of @option{--verbose} on the command line increases the
908 verbosity level by one, so if you need more details on the output,
909 specify it twice.
910
911 When reading archives (@option{--list}, @option{--extract},
912 @option{--diff}), @command{tar} by default prints only the names of
913 the members being extracted. Using @option{--verbose} will show a full,
914 @command{ls} style member listing.
915
916 In contrast, when writing archives (@option{--create}, @option{--append},
917 @option{--update}), @command{tar} does not print file names by
918 default. So, a single @option{--verbose} option shows the file names
919 being added to the archive, while two @option{--verbose} options
920 enable the full listing.
921
922 For example, to create an archive in verbose mode:
923
924 @smallexample
925 $ @kbd{tar -cvf afiles.tar apple angst aspic}
926 apple
927 angst
928 aspic
929 @end smallexample
930
931 @noindent
932 Creating the same archive with the verbosity level 2 could give:
933
934 @smallexample
935 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
936 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
937 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
938 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
939 @end smallexample
940
941 @noindent
942 This works equally well using short or long forms of options. Using
943 long forms, you would simply write out the mnemonic form of the option
944 twice, like this:
945
946 @smallexample
947 $ @kbd{tar --create --verbose --verbose @dots{}}
948 @end smallexample
949
950 @noindent
951 Note that you must double the hyphens properly each time.
952
953 Later in the tutorial, we will give examples using @w{@option{--verbose
954 --verbose}}.
955
956 @anchor{verbose member listing}
957 The full output consists of six fields:
958
959 @itemize @bullet
960 @item File type and permissions in symbolic form.
961 These are displayed in the same format as the first column of
962 @command{ls -l} output (@pxref{What information is listed,
963 format=verbose, Verbose listing, fileutils, GNU file utilities}).
964
965 @item Owner name and group separated by a slash character.
966 If these data are not available (for example, when listing a @samp{v7} format
967 archive), numeric @acronym{ID} values are printed instead.
968
969 @item Size of the file, in bytes.
970
971 @item File modification date in ISO 8601 format.
972
973 @item File modification time.
974
975 @item File name.
976 If the name contains any special characters (white space, newlines,
977 etc.) these are displayed in an unambiguous form using so called
978 @dfn{quoting style}. For the detailed discussion of available styles
979 and on how to use them, see @ref{quoting styles}.
980
981 Depending on the file type, the name can be followed by some
982 additional information, described in the following table:
983
984 @table @samp
985 @item -> @var{link-name}
986 The file or archive member is a @dfn{symbolic link} and
987 @var{link-name} is the name of file it links to.
988
989 @item link to @var{link-name}
990 The file or archive member is a @dfn{hard link} and @var{link-name} is
991 the name of file it links to.
992
993 @item --Long Link--
994 The archive member is an old GNU format long link. You will normally
995 not encounter this.
996
997 @item --Long Name--
998 The archive member is an old GNU format long name. You will normally
999 not encounter this.
1000
1001 @item --Volume Header--
1002 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
1003
1004 @item --Continued at byte @var{n}--
1005 Encountered only at the beginning of a multi-volume archive
1006 (@pxref{Using Multiple Tapes}). This archive member is a continuation
1007 from the previous volume. The number @var{n} gives the offset where
1008 the original file was split.
1009
1010 @item unknown file type @var{c}
1011 An archive member of unknown type. @var{c} is the type character from
1012 the archive header. If you encounter such a message, it means that
1013 either your archive contains proprietary member types @GNUTAR{} is not
1014 able to handle, or the archive is corrupted.
1015 @end table
1016
1017 @end itemize
1018
1019 For example, here is an archive listing containing most of the special
1020 suffixes explained above:
1021
1022 @smallexample
1023 @group
1024 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1025 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at byte 32456--
1026 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1027 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1028 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1029 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1030 @end group
1031 @end smallexample
1032
1033 @smallexample
1034 @end smallexample
1035
1036 @node help tutorial
1037 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1038
1039 @table @option
1040 @opindex help
1041 @item --help
1042
1043 The @option{--help} option to @command{tar} prints out a very brief list of
1044 all operations and option available for the current version of
1045 @command{tar} available on your system.
1046 @end table
1047
1048 @node create
1049 @section How to Create Archives
1050 @UNREVISED
1051
1052 @cindex Creation of the archive
1053 @cindex Archive, creation of
1054 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1055 you use to create a @command{tar} archive. We will explain
1056 @option{--create} first because, in order to learn about the other
1057 operations, you will find it useful to have an archive available to
1058 practice on.
1059
1060 To make this easier, in this section you will first create a directory
1061 containing three files. Then, we will show you how to create an
1062 @emph{archive} (inside the new directory). Both the directory, and
1063 the archive are specifically for you to practice on. The rest of this
1064 chapter and the next chapter will show many examples using this
1065 directory and the files you will create: some of those files may be
1066 other directories and other archives.
1067
1068 The three files you will archive in this example are called
1069 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1070 @file{collection.tar}.
1071
1072 This section will proceed slowly, detailing how to use @option{--create}
1073 in @code{verbose} mode, and showing examples using both short and long
1074 forms. In the rest of the tutorial, and in the examples in the next
1075 chapter, we will proceed at a slightly quicker pace. This section
1076 moves more slowly to allow beginning users to understand how
1077 @command{tar} works.
1078
1079 @menu
1080 * prepare for examples::
1081 * Creating the archive::
1082 * create verbose::
1083 * short create::
1084 * create dir::
1085 @end menu
1086
1087 @node prepare for examples
1088 @subsection Preparing a Practice Directory for Examples
1089
1090 To follow along with this and future examples, create a new directory
1091 called @file{practice} containing files called @file{blues}, @file{folk}
1092 and @file{jazz}. The files can contain any information you like:
1093 ideally, they should contain information which relates to their names,
1094 and be of different lengths. Our examples assume that @file{practice}
1095 is a subdirectory of your home directory.
1096
1097 Now @command{cd} to the directory named @file{practice}; @file{practice}
1098 is now your @dfn{working directory}. (@emph{Please note}: Although
1099 the full file name of this directory is
1100 @file{/@var{homedir}/practice}, in our examples we will refer to
1101 this directory as @file{practice}; the @var{homedir} is presumed.)
1102
1103 In general, you should check that the files to be archived exist where
1104 you think they do (in the working directory) by running @command{ls}.
1105 Because you just created the directory and the files and have changed to
1106 that directory, you probably don't need to do that this time.
1107
1108 It is very important to make sure there isn't already a file in the
1109 working directory with the archive name you intend to use (in this case,
1110 @samp{collection.tar}), or that you don't care about its contents.
1111 Whenever you use @samp{create}, @command{tar} will erase the current
1112 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1113 will not tell you if you are about to overwrite an archive unless you
1114 specify an option which does this (@pxref{backup}, for the
1115 information on how to do so). To add files to an existing archive,
1116 you need to use a different option, such as @option{--append} (@option{-r}); see
1117 @ref{append} for information on how to do this.
1118
1119 @node Creating the archive
1120 @subsection Creating the Archive
1121
1122 @xopindex{create, introduced}
1123 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1124 archive named @file{collection.tar}, use the following command:
1125
1126 @smallexample
1127 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1128 @end smallexample
1129
1130 The order of the arguments is not very important, @emph{when using long
1131 option forms}. You could also say:
1132
1133 @smallexample
1134 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1135 @end smallexample
1136
1137 @noindent
1138 However, you can see that this order is harder to understand; this is
1139 why we will list the arguments in the order that makes the commands
1140 easiest to understand (and we encourage you to do the same when you use
1141 @command{tar}, to avoid errors).
1142
1143 Note that the sequence
1144 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1145 If you substituted any other string of characters for
1146 @kbd{collection.tar}, then that string would become the name of the
1147 archive file you create.
1148
1149 The order of the options becomes more important when you begin to use
1150 short forms. With short forms, if you type commands in the wrong order
1151 (even if you type them correctly in all other ways), you may end up with
1152 results you don't expect. For this reason, it is a good idea to get
1153 into the habit of typing options in the order that makes inherent sense.
1154 @xref{short create}, for more information on this.
1155
1156 In this example, you type the command as shown above: @option{--create}
1157 is the operation which creates the new archive
1158 (@file{collection.tar}), and @option{--file} is the option which lets
1159 you give it the name you chose. The files, @file{blues}, @file{folk},
1160 and @file{jazz}, are now members of the archive, @file{collection.tar}
1161 (they are @dfn{file name arguments} to the @option{--create} operation.
1162 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1163 in the archive, they are called @emph{archive members}, not files.
1164 (@pxref{Definitions,members}).
1165
1166 When you create an archive, you @emph{must} specify which files you
1167 want placed in the archive. If you do not specify any archive
1168 members, @GNUTAR{} will complain.
1169
1170 If you now list the contents of the working directory (@command{ls}), you will
1171 find the archive file listed as well as the files you saw previously:
1172
1173 @smallexample
1174 blues folk jazz collection.tar
1175 @end smallexample
1176
1177 @noindent
1178 Creating the archive @samp{collection.tar} did not destroy the copies of
1179 the files in the directory.
1180
1181 Keep in mind that if you don't indicate an operation, @command{tar} will not
1182 run and will prompt you for one. If you don't name any files, @command{tar}
1183 will complain. You must have write access to the working directory,
1184 or else you will not be able to create an archive in that directory.
1185
1186 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1187 an existing archive; it will delete the archive and write a new one.
1188 Use @option{--append} (@option{-r}) instead. @xref{append}.
1189
1190 @node create verbose
1191 @subsection Running @option{--create} with @option{--verbose}
1192
1193 @xopindex{create, using with @option{--verbose}}
1194 @xopindex{verbose, using with @option{--create}}
1195 If you include the @option{--verbose} (@option{-v}) option on the command line,
1196 @command{tar} will list the files it is acting on as it is working. In
1197 verbose mode, the @code{create} example above would appear as:
1198
1199 @smallexample
1200 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1201 blues
1202 folk
1203 jazz
1204 @end smallexample
1205
1206 This example is just like the example we showed which did not use
1207 @option{--verbose}, except that @command{tar} generated the remaining
1208 @iftex
1209 lines (note the different font styles).
1210 @end iftex
1211 @ifinfo
1212 lines.
1213 @end ifinfo
1214
1215 In the rest of the examples in this chapter, we will frequently use
1216 @code{verbose} mode so we can show actions or @command{tar} responses that
1217 you would otherwise not see, and which are important for you to
1218 understand.
1219
1220 @node short create
1221 @subsection Short Forms with @samp{create}
1222
1223 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1224 basic uses of @command{tar}, and you will use it countless times.
1225 Eventually, you will probably want to use abbreviated (or ``short'')
1226 forms of options. A full discussion of the three different forms that
1227 options can take appears in @ref{Styles}; for now, here is what the
1228 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1229 using short option forms:
1230
1231 @smallexample
1232 $ @kbd{tar -cvf collection.tar blues folk jazz}
1233 blues
1234 folk
1235 jazz
1236 @end smallexample
1237
1238 @noindent
1239 As you can see, the system responds the same no matter whether you use
1240 long or short option forms.
1241
1242 @FIXME{i don't like how this is worded:} One difference between using
1243 short and long option forms is that, although the exact placement of
1244 arguments following options is no more specific when using short forms,
1245 it is easier to become confused and make a mistake when using short
1246 forms. For example, suppose you attempted the above example in the
1247 following way:
1248
1249 @smallexample
1250 $ @kbd{tar -cfv collection.tar blues folk jazz}
1251 @end smallexample
1252
1253 @noindent
1254 In this case, @command{tar} will make an archive file called @file{v},
1255 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1256 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1257 is thus taken to be the chosen archive file name. @command{tar} will try
1258 to add a file called @file{collection.tar} to the @file{v} archive file;
1259 if the file @file{collection.tar} did not already exist, @command{tar} will
1260 report an error indicating that this file does not exist. If the file
1261 @file{collection.tar} does already exist (e.g., from a previous command
1262 you may have run), then @command{tar} will add this file to the archive.
1263 Because the @option{-v} option did not get registered, @command{tar} will not
1264 run under @samp{verbose} mode, and will not report its progress.
1265
1266 The end result is that you may be quite confused about what happened,
1267 and possibly overwrite a file. To illustrate this further, we will show
1268 you how an example we showed previously would look using short forms.
1269
1270 This example,
1271
1272 @smallexample
1273 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1274 @end smallexample
1275
1276 @noindent
1277 is confusing as it is. When shown using short forms, however, it
1278 becomes much more so:
1279
1280 @smallexample
1281 $ @kbd{tar blues -c folk -f collection.tar jazz}
1282 @end smallexample
1283
1284 @noindent
1285 It would be very easy to put the wrong string of characters
1286 immediately following the @option{-f}, but doing that could sacrifice
1287 valuable data.
1288
1289 For this reason, we recommend that you pay very careful attention to
1290 the order of options and placement of file and archive names,
1291 especially when using short option forms. Not having the option name
1292 written out mnemonically can affect how well you remember which option
1293 does what, and therefore where different names have to be placed.
1294
1295 @node create dir
1296 @subsection Archiving Directories
1297
1298 @cindex Archiving Directories
1299 @cindex Directories, Archiving
1300 You can archive a directory by specifying its directory name as a
1301 file name argument to @command{tar}. The files in the directory will be
1302 archived relative to the working directory, and the directory will be
1303 re-created along with its contents when the archive is extracted.
1304
1305 To archive a directory, first move to its superior directory. If you
1306 have followed the previous instructions in this tutorial, you should
1307 type:
1308
1309 @smallexample
1310 $ @kbd{cd ..}
1311 $
1312 @end smallexample
1313
1314 @noindent
1315 This will put you into the directory which contains @file{practice},
1316 i.e., your home directory. Once in the superior directory, you can
1317 specify the subdirectory, @file{practice}, as a file name argument. To
1318 store @file{practice} in the new archive file @file{music.tar}, type:
1319
1320 @smallexample
1321 $ @kbd{tar --create --verbose --file=music.tar practice}
1322 @end smallexample
1323
1324 @noindent
1325 @command{tar} should output:
1326
1327 @smallexample
1328 practice/
1329 practice/blues
1330 practice/folk
1331 practice/jazz
1332 practice/collection.tar
1333 @end smallexample
1334
1335 Note that the archive thus created is not in the subdirectory
1336 @file{practice}, but rather in the current working directory---the
1337 directory from which @command{tar} was invoked. Before trying to archive a
1338 directory from its superior directory, you should make sure you have
1339 write access to the superior directory itself, not only the directory
1340 you are trying archive with @command{tar}. For example, you will probably
1341 not be able to store your home directory in an archive by invoking
1342 @command{tar} from the root directory; @xref{absolute}. (Note
1343 also that @file{collection.tar}, the original archive file, has itself
1344 been archived. @command{tar} will accept any file as a file to be
1345 archived, regardless of its content. When @file{music.tar} is
1346 extracted, the archive file @file{collection.tar} will be re-written
1347 into the file system).
1348
1349 If you give @command{tar} a command such as
1350
1351 @smallexample
1352 $ @kbd{tar --create --file=foo.tar .}
1353 @end smallexample
1354
1355 @noindent
1356 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1357 dumped}. This happens because @command{tar} creates the archive
1358 @file{foo.tar} in the current directory before putting any files into
1359 it. Then, when @command{tar} attempts to add all the files in the
1360 directory @file{.} to the archive, it notices that the file
1361 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1362 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1363 will continue in this case, and create the archive
1364 normally, except for the exclusion of that one file. (@emph{Please
1365 note:} Other implementations of @command{tar} may not be so clever;
1366 they will enter an infinite loop when this happens, so you should not
1367 depend on this behavior unless you are certain you are running
1368 @GNUTAR{}. In general, it is wise to always place the archive outside
1369 of the directory being dumped.)
1370
1371 @node list
1372 @section How to List Archives
1373
1374 @opindex list
1375 Frequently, you will find yourself wanting to determine exactly what a
1376 particular archive contains. You can use the @option{--list}
1377 (@option{-t}) operation to get the member names as they currently
1378 appear in the archive, as well as various attributes of the files at
1379 the time they were archived. For example, you can examine the archive
1380 @file{collection.tar} that you created in the last section with the
1381 command,
1382
1383 @smallexample
1384 $ @kbd{tar --list --file=collection.tar}
1385 @end smallexample
1386
1387 @noindent
1388 The output of @command{tar} would then be:
1389
1390 @smallexample
1391 blues
1392 folk
1393 jazz
1394 @end smallexample
1395
1396 @noindent
1397 The archive @file{bfiles.tar} would list as follows:
1398
1399 @smallexample
1400 ./birds
1401 baboon
1402 ./box
1403 @end smallexample
1404
1405 @noindent
1406 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1407 @var{archive-name}}) option just as with @option{--create}
1408 (@option{-c}) to specify the name of the archive.
1409
1410 @xopindex{list, using with @option{--verbose}}
1411 @xopindex{verbose, using with @option{--list}}
1412 If you use the @option{--verbose} (@option{-v}) option with
1413 @option{--list}, then @command{tar} will print out a listing
1414 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1415 forth. This output is described in detail in @ref{verbose member listing}.
1416
1417 If you had used @option{--verbose} (@option{-v}) mode, the example
1418 above would look like:
1419
1420 @smallexample
1421 $ @kbd{tar --list --verbose --file=collection.tar folk}
1422 -rw-r--r-- myself/user 62 1990-05-23 10:55 folk
1423 @end smallexample
1424
1425 @cindex listing member and file names
1426 @anchor{listing member and file names}
1427 It is important to notice that the output of @kbd{tar --list
1428 --verbose} does not necessarily match that produced by @kbd{tar
1429 --create --verbose} while creating the archive. It is because
1430 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1431 prefixes from file names before storing them in the archive
1432 (@xref{absolute}, for more information). In other
1433 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1434 an archive and @dfn{member names} when listing it. Consider this
1435 example:
1436
1437 @smallexample
1438 @group
1439 $ @kbd{tar --create --verbose --file archive /etc/mail}
1440 tar: Removing leading '/' from member names
1441 /etc/mail/
1442 /etc/mail/sendmail.cf
1443 /etc/mail/aliases
1444 $ @kbd{tar --test --file archive}
1445 etc/mail/
1446 etc/mail/sendmail.cf
1447 etc/mail/aliases
1448 @end group
1449 @end smallexample
1450
1451 @opindex show-stored-names
1452 This default behavior can sometimes be inconvenient. You can force
1453 @GNUTAR{} show member names when creating archive by supplying
1454 @option{--show-stored-names} option.
1455
1456 @table @option
1457 @item --show-stored-names
1458 Print member (as opposed to @emph{file}) names when creating the archive.
1459 @end table
1460
1461 @cindex File name arguments, using @option{--list} with
1462 @xopindex{list, using with file name arguments}
1463 You can specify one or more individual member names as arguments when
1464 using @samp{list}. In this case, @command{tar} will only list the
1465 names of members you identify. For example, @w{@kbd{tar --list
1466 --file=afiles.tar apple}} would only print @file{apple}.
1467
1468 Because @command{tar} preserves file names, these must be specified as
1469 they appear in the archive (i.e., relative to the directory from which
1470 the archive was created). Therefore, it is essential when specifying
1471 member names to @command{tar} that you give the exact member names.
1472 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1473 error message something like @samp{tar: birds: Not found in archive},
1474 because there is no member named @file{birds}, only one named
1475 @file{./birds}. While the names @file{birds} and @file{./birds} name
1476 the same file, @emph{member} names by default are compared verbatim.
1477
1478 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1479 with @file{baboon}, because this exact member name is in the archive file
1480 @file{bfiles.tar}. If you are not sure of the exact file name,
1481 use @dfn{globbing patterns}, for example:
1482
1483 @smallexample
1484 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1485 @end smallexample
1486
1487 @noindent
1488 will list all members whose name contains @samp{b}. @xref{wildcards},
1489 for a detailed discussion of globbing patterns and related
1490 @command{tar} command line options.
1491
1492 @menu
1493 * list dir::
1494 @end menu
1495
1496 @node list dir
1497 @unnumberedsubsec Listing the Contents of a Stored Directory
1498
1499 To get information about the contents of an archived directory,
1500 use the directory name as a file name argument in conjunction with
1501 @option{--list} (@option{-t}). To find out file attributes, include the
1502 @option{--verbose} (@option{-v}) option.
1503
1504 For example, to find out about files in the directory @file{practice}, in
1505 the archive file @file{music.tar}, type:
1506
1507 @smallexample
1508 $ @kbd{tar --list --verbose --file=music.tar practice}
1509 @end smallexample
1510
1511 @command{tar} responds:
1512
1513 @smallexample
1514 drwxrwxrwx myself/user 0 1990-05-31 21:49 practice/
1515 -rw-r--r-- myself/user 42 1990-05-21 13:29 practice/blues
1516 -rw-r--r-- myself/user 62 1990-05-23 10:55 practice/folk
1517 -rw-r--r-- myself/user 40 1990-05-21 13:30 practice/jazz
1518 -rw-r--r-- myself/user 10240 1990-05-31 21:49 practice/collection.tar
1519 @end smallexample
1520
1521 When you use a directory name as a file name argument, @command{tar} acts on
1522 all the files (including sub-directories) in that directory.
1523
1524 @node extract
1525 @section How to Extract Members from an Archive
1526 @cindex Extraction
1527 @cindex Retrieving files from an archive
1528 @cindex Resurrecting files from an archive
1529
1530 @opindex extract
1531 Creating an archive is only half the job---there is no point in storing
1532 files in an archive if you can't retrieve them. The act of retrieving
1533 members from an archive so they can be used and manipulated as
1534 unarchived files again is called @dfn{extraction}. To extract files
1535 from an archive, use the @option{--extract} (@option{--get} or
1536 @option{-x}) operation. As with @option{--create}, specify the name
1537 of the archive with @option{--file} (@option{-f}) option. Extracting
1538 an archive does not modify the archive in any way; you can extract it
1539 multiple times if you want or need to.
1540
1541 Using @option{--extract}, you can extract an entire archive, or specific
1542 files. The files can be directories containing other files, or not. As
1543 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1544 long form of the operation without affecting the performance.
1545
1546 @menu
1547 * extracting archives::
1548 * extracting files::
1549 * extract dir::
1550 * extracting untrusted archives::
1551 * failing commands::
1552 @end menu
1553
1554 @node extracting archives
1555 @subsection Extracting an Entire Archive
1556
1557 To extract an entire archive, specify the archive file name only, with
1558 no individual file names as arguments. For example,
1559
1560 @smallexample
1561 $ @kbd{tar -xvf collection.tar}
1562 @end smallexample
1563
1564 @noindent
1565 produces this:
1566
1567 @smallexample
1568 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
1569 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
1570 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
1571 @end smallexample
1572
1573 @node extracting files
1574 @subsection Extracting Specific Files
1575
1576 To extract specific archive members, give their exact member names as
1577 arguments, as printed by @option{--list} (@option{-t}). If you had
1578 mistakenly deleted one of the files you had placed in the archive
1579 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1580 from the archive without changing the archive's structure. Its
1581 contents will be identical to the original file @file{blues} that you
1582 deleted.
1583
1584 First, make sure you are in the @file{practice} directory, and list the
1585 files in the directory. Now, delete the file, @samp{blues}, and list
1586 the files in the directory again.
1587
1588 You can now extract the member @file{blues} from the archive file
1589 @file{collection.tar} like this:
1590
1591 @smallexample
1592 $ @kbd{tar --extract --file=collection.tar blues}
1593 @end smallexample
1594
1595 @noindent
1596 If you list the files in the directory again, you will see that the file
1597 @file{blues} has been restored, with its original permissions, data
1598 modification times, and owner.@footnote{This is only accidentally
1599 true, but not in general. Whereas modification times are always
1600 restored, in most cases, one has to be root for restoring the owner,
1601 and use a special option for restoring permissions. Here, it just
1602 happens that the restoring user is also the owner of the archived
1603 members, and that the current @code{umask} is compatible with original
1604 permissions.} (These parameters will be identical to those which
1605 the file had when you originally placed it in the archive; any changes
1606 you may have made before deleting the file from the file system,
1607 however, will @emph{not} have been made to the archive member.) The
1608 archive file, @samp{collection.tar}, is the same as it was before you
1609 extracted @samp{blues}. You can confirm this by running @command{tar} with
1610 @option{--list} (@option{-t}).
1611
1612 Remember that as with other operations, specifying the exact member
1613 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1614 will fail, because there is no member named @file{birds}. To extract
1615 the member named @file{./birds}, you must specify @w{@kbd{tar
1616 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1617 exact member names, use @option{--list} (@option{-t}) option
1618 (@pxref{list}). You can also extract those members that match a
1619 specific @dfn{globbing pattern}. For example, to extract from
1620 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1621 directory prefix, you could type:
1622
1623 @smallexample
1624 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1625 @end smallexample
1626
1627 @noindent
1628 Here, @option{--wildcards} instructs @command{tar} to treat
1629 command line arguments as globbing patterns and @option{--no-anchored}
1630 informs it that the patterns apply to member names after any @samp{/}
1631 delimiter. The use of globbing patterns is discussed in detail in
1632 @xref{wildcards}.
1633
1634 You can extract a file to standard output by combining the above options
1635 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1636 Output}).
1637
1638 If you give the @option{--verbose} option, then @option{--extract}
1639 will print the names of the archive members as it extracts them.
1640
1641 @node extract dir
1642 @subsection Extracting Files that are Directories
1643
1644 Extracting directories which are members of an archive is similar to
1645 extracting other files. The main difference to be aware of is that if
1646 the extracted directory has the same name as any directory already in
1647 the working directory, then files in the extracted directory will be
1648 placed into the directory of the same name. Likewise, if there are
1649 files in the pre-existing directory with the same names as the members
1650 which you extract, the files from the extracted archive will replace
1651 the files already in the working directory (and possible
1652 subdirectories). This will happen regardless of whether or not the
1653 files in the working directory were more recent than those extracted
1654 (there exist, however, special options that alter this behavior
1655 @pxref{Writing}).
1656
1657 However, if a file was stored with a directory name as part of its file
1658 name, and that directory does not exist under the working directory when
1659 the file is extracted, @command{tar} will create the directory.
1660
1661 We can demonstrate how to use @option{--extract} to extract a directory
1662 file with an example. Change to the @file{practice} directory if you
1663 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1664 go back to the parent directory and extract the archive
1665 @file{music.tar}. You may either extract the entire archive, or you may
1666 extract only the files you just deleted. To extract the entire archive,
1667 don't give any file names as arguments after the archive name
1668 @file{music.tar}. To extract only the files you deleted, use the
1669 following command:
1670
1671 @smallexample
1672 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1673 practice/folk
1674 practice/jazz
1675 @end smallexample
1676
1677 @noindent
1678 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1679 would have displayed more detail about the extracted files, as shown
1680 in the example below:
1681
1682 @smallexample
1683 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1684 -rw-r--r-- me/user 28 1996-10-18 16:31 practice/jazz
1685 -rw-r--r-- me/user 20 1996-09-23 16:44 practice/folk
1686 @end smallexample
1687
1688 @noindent
1689 Because you created the directory with @file{practice} as part of the
1690 file names of each of the files by archiving the @file{practice}
1691 directory as @file{practice}, you must give @file{practice} as part
1692 of the file names when you extract those files from the archive.
1693
1694 @node extracting untrusted archives
1695 @subsection Extracting Archives from Untrusted Sources
1696
1697 Extracting files from archives can overwrite files that already exist.
1698 If you receive an archive from an untrusted source, you should make a
1699 new directory and extract into that directory, so that you don't have
1700 to worry about the extraction overwriting one of your existing files.
1701 For example, if @file{untrusted.tar} came from somewhere else on the
1702 Internet, and you don't necessarily trust its contents, you can
1703 extract it as follows:
1704
1705 @smallexample
1706 $ @kbd{mkdir newdir}
1707 $ @kbd{cd newdir}
1708 $ @kbd{tar -xvf ../untrusted.tar}
1709 @end smallexample
1710
1711 It is also a good practice to examine contents of the archive
1712 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1713 with @option{--verbose} (@option{-v}).
1714
1715 @node failing commands
1716 @subsection Commands That Will Fail
1717
1718 Here are some sample commands you might try which will not work, and why
1719 they won't work.
1720
1721 If you try to use this command,
1722
1723 @smallexample
1724 $ @kbd{tar -xvf music.tar folk jazz}
1725 @end smallexample
1726
1727 @noindent
1728 you will get the following response:
1729
1730 @smallexample
1731 tar: folk: Not found in archive
1732 tar: jazz: Not found in archive
1733 @end smallexample
1734
1735 @noindent
1736 This is because these files were not originally @emph{in} the parent
1737 directory @file{..}, where the archive is located; they were in the
1738 @file{practice} directory, and their file names reflect this:
1739
1740 @smallexample
1741 $ @kbd{tar -tvf music.tar}
1742 practice/blues
1743 practice/folk
1744 practice/jazz
1745 @end smallexample
1746
1747 @FIXME{make sure the above works when going through the examples in
1748 order...}
1749
1750 @noindent
1751 Likewise, if you try to use this command,
1752
1753 @smallexample
1754 $ @kbd{tar -tvf music.tar folk jazz}
1755 @end smallexample
1756
1757 @noindent
1758 you would get a similar response. Members with those names are not in the
1759 archive. You must use the correct member names, or wildcards, in order
1760 to extract the files from the archive.
1761
1762 If you have forgotten the correct names of the files in the archive,
1763 use @w{@kbd{tar --list --verbose}} to list them correctly.
1764
1765 @FIXME{more examples, here? hag thinks it's a good idea.}
1766
1767 @node going further
1768 @section Going Further Ahead in this Manual
1769 @UNREVISED
1770
1771 @FIXME{need to write up a node here about the things that are going to
1772 be in the rest of the manual.}
1773
1774 @node tar invocation
1775 @chapter Invoking @GNUTAR{}
1776
1777 This chapter is about how one invokes the @GNUTAR{}
1778 command, from the command synopsis (@pxref{Synopsis}). There are
1779 numerous options, and many styles for writing them. One mandatory
1780 option specifies the operation @command{tar} should perform
1781 (@pxref{Operation Summary}), other options are meant to detail how
1782 this operation should be performed (@pxref{Option Summary}).
1783 Non-option arguments are not always interpreted the same way,
1784 depending on what the operation is.
1785
1786 You will find in this chapter everything about option styles and rules for
1787 writing them (@pxref{Styles}). On the other hand, operations and options
1788 are fully described elsewhere, in other chapters. Here, you will find
1789 only synthetic descriptions for operations and options, together with
1790 pointers to other parts of the @command{tar} manual.
1791
1792 Some options are so special they are fully described right in this
1793 chapter. They have the effect of inhibiting the normal operation of
1794 @command{tar} or else, they globally alter the amount of feedback the user
1795 receives about what is going on. These are the @option{--help} and
1796 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1797 and @option{--interactive} options (@pxref{interactive}).
1798
1799 @menu
1800 * Synopsis::
1801 * using tar options::
1802 * Styles::
1803 * All Options:: All @command{tar} Options.
1804 * help:: Where to Get Help.
1805 * defaults:: What are the Default Values.
1806 * verbose:: Checking @command{tar} progress.
1807 * checkpoints:: Checkpoints.
1808 * warnings:: Controlling Warning Messages.
1809 * interactive:: Asking for Confirmation During Operations.
1810 * external:: Running External Commands.
1811 @end menu
1812
1813 @node Synopsis
1814 @section General Synopsis of @command{tar}
1815
1816 The @GNUTAR{} program is invoked as either one of:
1817
1818 @smallexample
1819 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1820 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1821 @end smallexample
1822
1823 The second form is for when old options are being used.
1824
1825 You can use @command{tar} to store files in an archive, to extract them from
1826 an archive, and to do other types of archive manipulation. The primary
1827 argument to @command{tar}, which is called the @dfn{operation}, specifies
1828 which action to take. The other arguments to @command{tar} are either
1829 @dfn{options}, which change the way @command{tar} performs an operation,
1830 or file names or archive members, which specify the files or members
1831 @command{tar} is to act on.
1832
1833 You can actually type in arguments in any order, even if in this manual
1834 the options always precede the other arguments, to make examples easier
1835 to understand. Further, the option stating the main operation mode
1836 (the @command{tar} main command) is usually given first.
1837
1838 Each @var{name} in the synopsis above is interpreted as an archive member
1839 name when the main command is one of @option{--compare}
1840 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1841 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1842 @option{--update} (@option{-u}). When naming archive members, you
1843 must give the exact name of the member in the archive, as it is
1844 printed by @option{--list}. For @option{--append} (@option{-r}) and
1845 @option{--create} (@option{-c}), these @var{name} arguments specify
1846 the names of either files or directory hierarchies to place in the archive.
1847 These files or hierarchies should already exist in the file system,
1848 prior to the execution of the @command{tar} command.
1849
1850 @command{tar} interprets relative file names as being relative to the
1851 working directory. @command{tar} will make all file names relative
1852 (by removing leading slashes when archiving or restoring files),
1853 unless you specify otherwise (using the @option{--absolute-names}
1854 option). @xref{absolute}, for more information about
1855 @option{--absolute-names}.
1856
1857 If you give the name of a directory as either a file name or a member
1858 name, then @command{tar} acts recursively on all the files and directories
1859 beneath that directory. For example, the name @file{/} identifies all
1860 the files in the file system to @command{tar}.
1861
1862 The distinction between file names and archive member names is especially
1863 important when shell globbing is used, and sometimes a source of confusion
1864 for newcomers. @xref{wildcards}, for more information about globbing.
1865 The problem is that shells may only glob using existing files in the
1866 file system. Only @command{tar} itself may glob on archive members, so when
1867 needed, you must ensure that wildcard characters reach @command{tar} without
1868 being interpreted by the shell first. Using a backslash before @samp{*}
1869 or @samp{?}, or putting the whole argument between quotes, is usually
1870 sufficient for this.
1871
1872 Even if @var{name}s are often specified on the command line, they
1873 can also be read from a text file in the file system, using the
1874 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1875
1876 If you don't use any file name arguments, @option{--append} (@option{-r}),
1877 @option{--delete} and @option{--concatenate} (@option{--catenate},
1878 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1879 will usually yield a diagnostic and inhibit @command{tar} execution.
1880 The other operations of @command{tar} (@option{--list},
1881 @option{--extract}, @option{--compare}, and @option{--update})
1882 will act on the entire contents of the archive.
1883
1884 @anchor{exit status}
1885 @cindex exit status
1886 @cindex return status
1887 Besides successful exits, @GNUTAR{} may fail for
1888 many reasons. Some reasons correspond to bad usage, that is, when the
1889 @command{tar} command line is improperly written. Errors may be
1890 encountered later, while processing the archive or the files. Some
1891 errors are recoverable, in which case the failure is delayed until
1892 @command{tar} has completed all its work. Some errors are such that
1893 it would be not meaningful, or at least risky, to continue processing:
1894 @command{tar} then aborts processing immediately. All abnormal exits,
1895 whether immediate or delayed, should always be clearly diagnosed on
1896 @code{stderr}, after a line stating the nature of the error.
1897
1898 Possible exit codes of @GNUTAR{} are summarized in the following
1899 table:
1900
1901 @table @asis
1902 @item 0
1903 @samp{Successful termination}.
1904
1905 @item 1
1906 @samp{Some files differ}. If tar was invoked with @option{--compare}
1907 (@option{--diff}, @option{-d}) command line option, this means that
1908 some files in the archive differ from their disk counterparts
1909 (@pxref{compare}). If tar was given @option{--create},
1910 @option{--append} or @option{--update} option, this exit code means
1911 that some files were changed while being archived and so the resulting
1912 archive does not contain the exact copy of the file set.
1913
1914 @item 2
1915 @samp{Fatal error}. This means that some fatal, unrecoverable error
1916 occurred.
1917 @end table
1918
1919 If @command{tar} has invoked a subprocess and that subprocess exited with a
1920 nonzero exit code, @command{tar} exits with that code as well.
1921 This can happen, for example, if @command{tar} was given some
1922 compression option (@pxref{gzip}) and the external compressor program
1923 failed. Another example is @command{rmt} failure during backup to the
1924 remote device (@pxref{Remote Tape Server}).
1925
1926 @node using tar options
1927 @section Using @command{tar} Options
1928
1929 @GNUTAR{} has a total of eight operating modes which
1930 allow you to perform a variety of tasks. You are required to choose
1931 one operating mode each time you employ the @command{tar} program by
1932 specifying one, and only one operation as an argument to the
1933 @command{tar} command (the corresponding options may be found
1934 at @ref{frequent operations} and @ref{Operations}). Depending on
1935 circumstances, you may also wish to customize how the chosen operating
1936 mode behaves. For example, you may wish to change the way the output
1937 looks, or the format of the files that you wish to archive may require
1938 you to do something special in order to make the archive look right.
1939
1940 You can customize and control @command{tar}'s performance by running
1941 @command{tar} with one or more options (such as @option{--verbose}
1942 (@option{-v}), which we used in the tutorial). As we said in the
1943 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1944 their name suggests) optional. Depending on the operating mode, you
1945 may specify one or more options. Different options will have different
1946 effects, but in general they all change details of the operation, such
1947 as archive format, archive name, or level of user interaction. Some
1948 options make sense with all operating modes, while others are
1949 meaningful only with particular modes. You will likely use some
1950 options frequently, while you will only use others infrequently, or
1951 not at all. (A full list of options is available in @pxref{All Options}.)
1952
1953 @vrindex TAR_OPTIONS, environment variable
1954 @anchor{TAR_OPTIONS}
1955 The @env{TAR_OPTIONS} environment variable specifies default options to
1956 be placed in front of any explicit options. For example, if
1957 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1958 if the two options @option{-v} and @option{--unlink-first} had been
1959 specified before any explicit options. Option specifications are
1960 separated by whitespace. A backslash escapes the next character, so it
1961 can be used to specify an option containing whitespace or a backslash.
1962
1963 Note that @command{tar} options are case sensitive. For example, the
1964 options @option{-T} and @option{-t} are different; the first requires an
1965 argument for stating the name of a file providing a list of @var{name}s,
1966 while the second does not require an argument and is another way to
1967 write @option{--list} (@option{-t}).
1968
1969 In addition to the eight operations, there are many options to
1970 @command{tar}, and three different styles for writing both: long (mnemonic)
1971 form, short form, and old style. These styles are discussed below.
1972 Both the options and the operations can be written in any of these three
1973 styles.
1974
1975 @FIXME{menu at end of this node. need to think of an actual outline
1976 for this chapter; probably do that after stuff from chapter 4 is
1977 incorporated.}
1978
1979 @node Styles
1980 @section The Three Option Styles
1981
1982 There are three styles for writing operations and options to the command
1983 line invoking @command{tar}. The different styles were developed at
1984 different times during the history of @command{tar}. These styles will be
1985 presented below, from the most recent to the oldest.
1986
1987 Some options must take an argument@footnote{For example, @option{--file}
1988 (@option{-f}) takes the name of an archive file as an argument. If
1989 you do not supply an archive file name, @command{tar} will use a
1990 default, but this can be confusing; thus, we recommend that you always
1991 supply a specific archive file name.}. Where you @emph{place} the
1992 arguments generally depends on which style of options you choose. We
1993 will detail specific information relevant to each option style in the
1994 sections on the different option styles, below. The differences are
1995 subtle, yet can often be very important; incorrect option placement
1996 can cause you to overwrite a number of important files. We urge you
1997 to note these differences, and only use the option style(s) which
1998 makes the most sense to you until you feel comfortable with the others.
1999
2000 Some options @emph{may} take an argument. Such options may have at
2001 most long and short forms, they do not have old style equivalent. The
2002 rules for specifying an argument for such options are stricter than
2003 those for specifying mandatory arguments. Please, pay special
2004 attention to them.
2005
2006 @menu
2007 * Long Options:: Long Option Style
2008 * Short Options:: Short Option Style
2009 * Old Options:: Old Option Style
2010 * Mixing:: Mixing Option Styles
2011 @end menu
2012
2013 @node Long Options
2014 @subsection Long Option Style
2015
2016 @cindex long options
2017 @cindex options, long style
2018 @cindex options, GNU style
2019 @cindex options, mnemonic names
2020 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2021 dashes in a row, e.g., @option{--list}. The long names are more clear than
2022 their corresponding short or old names. It sometimes happens that a
2023 single long option has many different names which are
2024 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2025 long option names can be given unique abbreviations. For example,
2026 @option{--cre} can be used in place of @option{--create} because there is no
2027 other long option which begins with @samp{cre}. (One way to find
2028 this out is by trying it and seeing what happens; if a particular
2029 abbreviation could represent more than one option, @command{tar} will tell
2030 you that that abbreviation is ambiguous and you'll know that that
2031 abbreviation won't work. You may also choose to run @samp{tar --help}
2032 to see a list of options. Be aware that if you run @command{tar} with a
2033 unique abbreviation for the long name of an option you didn't want to
2034 use, you are stuck; @command{tar} will perform the command as ordered.)
2035
2036 Long options are meant to be obvious and easy to remember, and their
2037 meanings are generally easier to discern than those of their
2038 corresponding short options (see below). For example:
2039
2040 @smallexample
2041 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2042 @end smallexample
2043
2044 @noindent
2045 gives a fairly good set of hints about what the command does, even
2046 for those not fully acquainted with @command{tar}.
2047
2048 @cindex arguments to long options
2049 @cindex long options with mandatory arguments
2050 Long options which require arguments take those arguments
2051 immediately following the option name. There are two ways of
2052 specifying a mandatory argument. It can be separated from the
2053 option name either by an equal sign, or by any amount of
2054 white space characters. For example, the @option{--file} option (which
2055 tells the name of the @command{tar} archive) is given a file such as
2056 @file{archive.tar} as argument by using any of the following notations:
2057 @option{--file=archive.tar} or @option{--file archive.tar}.
2058
2059 @cindex optional arguments to long options
2060 @cindex long options with optional arguments
2061 In contrast, optional arguments must always be introduced using
2062 an equal sign. For example, the @option{--backup} option takes
2063 an optional argument specifying backup type. It must be used
2064 as @option{--backup=@var{backup-type}}.
2065
2066 @node Short Options
2067 @subsection Short Option Style
2068
2069 @cindex short options
2070 @cindex options, short style
2071 @cindex options, traditional
2072 Most options also have a @dfn{short option} name. Short options start with
2073 a single dash, and are followed by a single character, e.g., @option{-t}
2074 (which is equivalent to @option{--list}). The forms are absolutely
2075 identical in function; they are interchangeable.
2076
2077 The short option names are faster to type than long option names.
2078
2079 @cindex arguments to short options
2080 @cindex short options with mandatory arguments
2081 Short options which require arguments take their arguments immediately
2082 following the option, usually separated by white space. It is also
2083 possible to stick the argument right after the short option name, using
2084 no intervening space. For example, you might write @w{@option{-f
2085 archive.tar}} or @option{-farchive.tar} instead of using
2086 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2087 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2088 specific archive, here named @file{archive.tar}.
2089
2090 @cindex optional arguments to short options
2091 @cindex short options with optional arguments
2092 Short options which take optional arguments take their arguments
2093 immediately following the option letter, @emph{without any intervening
2094 white space characters}.
2095
2096 Short options' letters may be clumped together, but you are not
2097 required to do this (as compared to old options; see below). When
2098 short options are clumped as a set, use one (single) dash for them
2099 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2100 such a set is allowed to have an argument@footnote{Clustering many
2101 options, the last of which has an argument, is a rather opaque way to
2102 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2103 even be made helpful enough for considering such usages as invalid.}.
2104
2105 When the options are separated, the argument for each option which requires
2106 an argument directly follows that option, as is usual for Unix programs.
2107 For example:
2108
2109 @smallexample
2110 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2111 @end smallexample
2112
2113 If you reorder short options' locations, be sure to move any arguments
2114 that belong to them. If you do not move the arguments properly, you may
2115 end up overwriting files.
2116
2117 @node Old Options
2118 @subsection Old Option Style
2119 @cindex options, old style
2120 @cindex old option style
2121 @cindex option syntax, traditional
2122
2123 As far as we know, all @command{tar} programs, @acronym{GNU} and
2124 non-@acronym{GNU}, support @dfn{old options}: that is, if the first
2125 argument does not start with @samp{-}, it is assumed to specify option
2126 letters. @GNUTAR{} supports old options not only for historical
2127 reasons, but also because many people are used to them. If the first
2128 argument does not start with a dash, you are announcing the old option
2129 style instead of the short option style; old options are decoded
2130 differently.
2131
2132 Like short options, old options are single letters. However, old options
2133 must be written together as a single clumped set, without spaces separating
2134 them or dashes preceding them. This set
2135 of letters must be the first to appear on the command line, after the
2136 @command{tar} program name and some white space; old options cannot appear
2137 anywhere else. The letter of an old option is exactly the same letter as
2138 the corresponding short option. For example, the old option @samp{t} is
2139 the same as the short option @option{-t}, and consequently, the same as the
2140 long option @option{--list}. So for example, the command @w{@samp{tar
2141 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2142
2143 @cindex arguments to old options
2144 @cindex old options with mandatory arguments
2145 When options that need arguments are given together with the command,
2146 all the associated arguments follow, in the same order as the options.
2147 Thus, the example given previously could also be written in the old
2148 style as follows:
2149
2150 @smallexample
2151 $ @kbd{tar cvbf 20 /dev/rmt0}
2152 @end smallexample
2153
2154 @noindent
2155 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2156 the argument of @option{-f}.
2157
2158 The old style syntax can make it difficult to match
2159 option letters with their corresponding arguments, and is often
2160 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2161 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2162 argument for @option{-f}, and @option{-v} does not have a corresponding
2163 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2164 /dev/rmt0}} is clearer, putting all arguments next to the option they
2165 pertain to.
2166
2167 If you want to reorder the letters in the old option argument, be
2168 sure to reorder any corresponding argument appropriately.
2169
2170 This old way of writing @command{tar} options can surprise even experienced
2171 users. For example, the two commands:
2172
2173 @smallexample
2174 @kbd{tar cfz archive.tar.gz file}
2175 @kbd{tar -cfz archive.tar.gz file}
2176 @end smallexample
2177
2178 @noindent
2179 are quite different. The first example uses @file{archive.tar.gz} as
2180 the value for option @samp{f} and recognizes the option @samp{z}. The
2181 second example, however, uses @file{z} as the value for option
2182 @samp{f} --- probably not what was intended.
2183
2184 This second example could be corrected in many ways, among which the
2185 following are equivalent:
2186
2187 @smallexample
2188 @kbd{tar -czf archive.tar.gz file}
2189 @kbd{tar -cf archive.tar.gz -z file}
2190 @kbd{tar cf archive.tar.gz -z file}
2191 @end smallexample
2192
2193 @node Mixing
2194 @subsection Mixing Option Styles
2195
2196 @cindex options, mixing different styles
2197 All three styles may be intermixed in a single @command{tar} command,
2198 so long as the rules for each style are fully
2199 respected@footnote{Before @GNUTAR{} version 1.11.6,
2200 a bug prevented intermixing old style options with long options in
2201 some cases.}. Old style options and either of the modern styles of
2202 options may be mixed within a single @command{tar} command. However,
2203 old style options must be introduced as the first arguments only,
2204 following the rule for old options (old options must appear directly
2205 after the @command{tar} command and some white space). Modern options
2206 may be given only after all arguments to the old options have been
2207 collected. If this rule is not respected, a modern option might be
2208 falsely interpreted as the value of the argument to one of the old
2209 style options.
2210
2211 For example, all the following commands are wholly equivalent, and
2212 illustrate the many combinations and orderings of option styles.
2213
2214 @smallexample
2215 @kbd{tar --create --file=archive.tar}
2216 @kbd{tar --create -f archive.tar}
2217 @kbd{tar --create -farchive.tar}
2218 @kbd{tar --file=archive.tar --create}
2219 @kbd{tar --file=archive.tar -c}
2220 @kbd{tar -c --file=archive.tar}
2221 @kbd{tar -c -f archive.tar}
2222 @kbd{tar -c -farchive.tar}
2223 @kbd{tar -cf archive.tar}
2224 @kbd{tar -cfarchive.tar}
2225 @kbd{tar -f archive.tar --create}
2226 @kbd{tar -f archive.tar -c}
2227 @kbd{tar -farchive.tar --create}
2228 @kbd{tar -farchive.tar -c}
2229 @kbd{tar c --file=archive.tar}
2230 @kbd{tar c -f archive.tar}
2231 @kbd{tar c -farchive.tar}
2232 @kbd{tar cf archive.tar}
2233 @kbd{tar f archive.tar --create}
2234 @kbd{tar f archive.tar -c}
2235 @kbd{tar fc archive.tar}
2236 @end smallexample
2237
2238 On the other hand, the following commands are @emph{not} equivalent to
2239 the previous set:
2240
2241 @smallexample
2242 @kbd{tar -f -c archive.tar}
2243 @kbd{tar -fc archive.tar}
2244 @kbd{tar -fcarchive.tar}
2245 @kbd{tar -farchive.tarc}
2246 @kbd{tar cfarchive.tar}
2247 @end smallexample
2248
2249 @noindent
2250 These last examples mean something completely different from what the
2251 user intended (judging based on the example in the previous set which
2252 uses long options, whose intent is therefore very clear). The first
2253 four specify that the @command{tar} archive would be a file named
2254 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2255 respectively. The first two examples also specify a single non-option,
2256 @var{name} argument having the value @samp{archive.tar}. The last
2257 example contains only old style option letters (repeating option
2258 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2259 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2260 the first sentence of this paragraph..}
2261
2262 @node All Options
2263 @section All @command{tar} Options
2264
2265 The coming manual sections contain an alphabetical listing of all
2266 @command{tar} operations and options, with brief descriptions and
2267 cross-references to more in-depth explanations in the body of the manual.
2268 They also contain an alphabetically arranged table of the short option
2269 forms with their corresponding long option. You can use this table as
2270 a reference for deciphering @command{tar} commands in scripts.
2271
2272 @menu
2273 * Operation Summary::
2274 * Option Summary::
2275 * Short Option Summary::
2276 @end menu
2277
2278 @node Operation Summary
2279 @subsection Operations
2280
2281 @table @option
2282
2283 @opsummary{append}
2284 @item --append
2285 @itemx -r
2286
2287 Appends files to the end of the archive. @xref{append}.
2288
2289 @opsummary{catenate}
2290 @item --catenate
2291 @itemx -A
2292
2293 Same as @option{--concatenate}. @xref{concatenate}.
2294
2295 @opsummary{compare}
2296 @item --compare
2297 @itemx -d
2298
2299 Compares archive members with their counterparts in the file
2300 system, and reports differences in file size, mode, owner,
2301 modification date and contents. @xref{compare}.
2302
2303 @opsummary{concatenate}
2304 @item --concatenate
2305 @itemx -A
2306
2307 Appends other @command{tar} archives to the end of the archive.
2308 @xref{concatenate}.
2309
2310 @opsummary{create}
2311 @item --create
2312 @itemx -c
2313
2314 Creates a new @command{tar} archive. @xref{create}.
2315
2316 @opsummary{delete}
2317 @item --delete
2318
2319 Deletes members from the archive. Don't try this on an archive on a
2320 tape! @xref{delete}.
2321
2322 @opsummary{diff}
2323 @item --diff
2324 @itemx -d
2325
2326 Same @option{--compare}. @xref{compare}.
2327
2328 @opsummary{extract}
2329 @item --extract
2330 @itemx -x
2331
2332 Extracts members from the archive into the file system. @xref{extract}.
2333
2334 @opsummary{get}
2335 @item --get
2336 @itemx -x
2337
2338 Same as @option{--extract}. @xref{extract}.
2339
2340 @opsummary{list}
2341 @item --list
2342 @itemx -t
2343
2344 Lists the members in an archive. @xref{list}.
2345
2346 @opsummary{update}
2347 @item --update
2348 @itemx -u
2349
2350 Adds files to the end of the archive, but only if they are newer than
2351 their counterparts already in the archive, or if they do not already
2352 exist in the archive. @xref{update}.
2353
2354 @end table
2355
2356 @node Option Summary
2357 @subsection @command{tar} Options
2358
2359 @table @option
2360
2361 @opsummary{absolute-names}
2362 @item --absolute-names
2363 @itemx -P
2364
2365 Normally when creating an archive, @command{tar} strips an initial
2366 @samp{/} from member names, and when extracting from an archive @command{tar}
2367 treats names specially if they have initial @samp{/} or internal
2368 @samp{..}. This option disables that behavior. @xref{absolute}.
2369
2370 @opsummary{after-date}
2371 @item --after-date
2372
2373 (See @option{--newer}, @pxref{after})
2374
2375 @opsummary{anchored}
2376 @item --anchored
2377 A pattern must match an initial subsequence of the name's components.
2378 @xref{controlling pattern-matching}.
2379
2380 @opsummary{atime-preserve}
2381 @item --atime-preserve
2382 @itemx --atime-preserve=replace
2383 @itemx --atime-preserve=system
2384
2385 Attempt to preserve the access time of files when reading them. This
2386 option currently is effective only on files that you own, unless you
2387 have superuser privileges.
2388
2389 @option{--atime-preserve=replace} remembers the access time of a file
2390 before reading it, and then restores the access time afterwards. This
2391 may cause problems if other programs are reading the file at the same
2392 time, as the times of their accesses will be lost. On most platforms
2393 restoring the access time also requires @command{tar} to restore the
2394 data modification time too, so this option may also cause problems if
2395 other programs are writing the file at the same time (@command{tar} attempts
2396 to detect this situation, but cannot do so reliably due to race
2397 conditions). Worse, on most platforms restoring the access time also
2398 updates the status change time, which means that this option is
2399 incompatible with incremental backups.
2400
2401 @option{--atime-preserve=system} avoids changing time stamps on files,
2402 without interfering with time stamp updates
2403 caused by other programs, so it works better with incremental backups.
2404 However, it requires a special @code{O_NOATIME} option from the
2405 underlying operating and file system implementation, and it also requires
2406 that searching directories does not update their access times. As of
2407 this writing (November 2005) this works only with Linux, and only with
2408 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2409 way to know whether this feature actually works. Sometimes
2410 @command{tar} knows that it does not work, and if you use
2411 @option{--atime-preserve=system} then @command{tar} complains and
2412 exits right away. But other times @command{tar} might think that the
2413 option works when it actually does not.
2414
2415 Currently @option{--atime-preserve} with no operand defaults to
2416 @option{--atime-preserve=replace}, but this may change in the future
2417 as support for @option{--atime-preserve=system} improves.
2418
2419 If your operating or file system does not support
2420 @option{--atime-preserve=@-system}, you might be able to preserve access
2421 times reliably by using the @command{mount} command. For example,
2422 you can mount the file system read-only, or access the file system via
2423 a read-only loopback mount, or use the @samp{noatime} mount option
2424 available on some systems. However, mounting typically requires
2425 superuser privileges and can be a pain to manage.
2426
2427 @opsummary{auto-compress}
2428 @item --auto-compress
2429 @itemx -a
2430
2431 During a @option{--create} operation, enables automatic compressed
2432 format recognition based on the archive suffix. The effect of this
2433 option is cancelled by @option{--no-auto-compress}. @xref{gzip}.
2434
2435 @opsummary{backup}
2436 @item --backup=@var{backup-type}
2437
2438 Rather than deleting files from the file system, @command{tar} will
2439 back them up using simple or numbered backups, depending upon
2440 @var{backup-type}. @xref{backup}.
2441
2442 @opsummary{block-number}
2443 @item --block-number
2444 @itemx -R
2445
2446 With this option present, @command{tar} prints error messages for read errors
2447 with the block number in the archive file. @xref{block-number}.
2448
2449 @opsummary{blocking-factor}
2450 @item --blocking-factor=@var{blocking}
2451 @itemx -b @var{blocking}
2452
2453 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2454 record. @xref{Blocking Factor}.
2455
2456 @opsummary{bzip2}
2457 @item --bzip2
2458 @itemx -j
2459
2460 This option tells @command{tar} to read or write archives through
2461 @code{bzip2}. @xref{gzip}.
2462
2463 @opsummary{check-device}
2464 @item --check-device
2465 Check device numbers when creating a list of modified files for
2466 incremental archiving. This is the default. @xref{device numbers},
2467 for a detailed description.
2468
2469 @opsummary{checkpoint}
2470 @item --checkpoint[=@var{number}]
2471
2472 This option directs @command{tar} to print periodic checkpoint
2473 messages as it reads through the archive. It is intended for when you
2474 want a visual indication that @command{tar} is still running, but
2475 don't want to see @option{--verbose} output. You can also instruct
2476 @command{tar} to execute a list of actions on each checkpoint, see
2477 @option{--checkpoint-action} below. For a detailed description, see
2478 @ref{checkpoints}.
2479
2480 @opsummary{checkpoint-action}
2481 @item --checkpoint-action=@var{action}
2482 Instruct @command{tar} to execute an action upon hitting a
2483 breakpoint. Here we give only a brief outline. @xref{checkpoints},
2484 for a complete description.
2485
2486 The @var{action} argument can be one of the following:
2487
2488 @table @asis
2489 @item bell
2490 Produce an audible bell on the console.
2491
2492 @item dot
2493 @itemx .
2494 Print a single dot on the standard listing stream.
2495
2496 @item echo
2497 Display a textual message on the standard error, with the status and
2498 number of the checkpoint. This is the default.
2499
2500 @item echo=@var{string}
2501 Display @var{string} on the standard error. Before output, the string
2502 is subject to meta-character expansion.
2503
2504 @item exec=@var{command}
2505 Execute the given @var{command}.
2506
2507 @item sleep=@var{time}
2508 Wait for @var{time} seconds.
2509
2510 @item ttyout=@var{string}
2511 Output @var{string} on the current console (@file{/dev/tty}).
2512 @end table
2513
2514 Several @option{--checkpoint-action} options can be specified. The
2515 supplied actions will be executed in order of their appearance in the
2516 command line.
2517
2518 Using @option{--checkpoint-action} without @option{--checkpoint}
2519 assumes default checkpoint frequency of one checkpoint per 10 records.
2520
2521 @opsummary{check-links}
2522 @item --check-links
2523 @itemx -l
2524 If this option was given, @command{tar} will check the number of links
2525 dumped for each processed file. If this number does not match the
2526 total number of hard links for the file, a warning message will be
2527 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2528 synonym for @option{--one-file-system}. The current semantics, which
2529 complies to UNIX98, was introduced with version
2530 1.15.91. @xref{Changes}, for more information.}.
2531
2532 @xref{hard links}.
2533
2534 @opsummary{compress}
2535 @opsummary{uncompress}
2536 @item --compress
2537 @itemx --uncompress
2538 @itemx -Z
2539
2540 @command{tar} will use the @command{compress} program when reading or
2541 writing the archive. This allows you to directly act on archives
2542 while saving space. @xref{gzip}.
2543
2544 @opsummary{confirmation}
2545 @item --confirmation
2546
2547 (See @option{--interactive}.) @xref{interactive}.
2548
2549 @opsummary{delay-directory-restore}
2550 @item --delay-directory-restore
2551
2552 Delay setting modification times and permissions of extracted
2553 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2554
2555 @opsummary{dereference}
2556 @item --dereference
2557 @itemx -h
2558
2559 When reading or writing a file to be archived, @command{tar} accesses
2560 the file that a symbolic link points to, rather than the symlink
2561 itself. @xref{dereference}.
2562
2563 @opsummary{directory}
2564 @item --directory=@var{dir}
2565 @itemx -C @var{dir}
2566
2567 When this option is specified, @command{tar} will change its current directory
2568 to @var{dir} before performing any operations. When this option is used
2569 during archive creation, it is order sensitive. @xref{directory}.
2570
2571 @opsummary{exclude}
2572 @item --exclude=@var{pattern}
2573
2574 When performing operations, @command{tar} will skip files that match
2575 @var{pattern}. @xref{exclude}.
2576
2577 @opsummary{exclude-backups}
2578 @item --exclude-backups
2579 Exclude backup and lock files. @xref{exclude,, exclude-backups}.
2580
2581 @opsummary{exclude-from}
2582 @item --exclude-from=@var{file}
2583 @itemx -X @var{file}
2584
2585 Similar to @option{--exclude}, except @command{tar} will use the list of
2586 patterns in the file @var{file}. @xref{exclude}.
2587
2588 @opsummary{exclude-caches}
2589 @item --exclude-caches
2590
2591 Exclude from dump any directory containing a valid cache directory
2592 tag file, but still dump the directory node and the tag file itself.
2593
2594 @xref{exclude,, exclude-caches}.
2595
2596 @opsummary{exclude-caches-under}
2597 @item --exclude-caches-under
2598
2599 Exclude from dump any directory containing a valid cache directory
2600 tag file, but still dump the directory node itself.
2601
2602 @xref{exclude}.
2603
2604 @opsummary{exclude-caches-all}
2605 @item --exclude-caches-all
2606
2607 Exclude from dump any directory containing a valid cache directory
2608 tag file. @xref{exclude}.
2609
2610 @opsummary{exclude-tag}
2611 @item --exclude-tag=@var{file}
2612
2613 Exclude from dump any directory containing file named @var{file}, but
2614 dump the directory node and @var{file} itself. @xref{exclude,, exclude-tag}.
2615
2616 @opsummary{exclude-tag-under}
2617 @item --exclude-tag-under=@var{file}
2618
2619 Exclude from dump the contents of any directory containing file
2620 named @var{file}, but dump the directory node itself. @xref{exclude,,
2621 exclude-tag-under}.
2622
2623 @opsummary{exclude-tag-all}
2624 @item --exclude-tag-all=@var{file}
2625
2626 Exclude from dump any directory containing file named @var{file}.
2627 @xref{exclude,,exclude-tag-all}.
2628
2629 @opsummary{exclude-vcs}
2630 @item --exclude-vcs
2631
2632 Exclude from dump directories and files, that are internal for some
2633 widely used version control systems.
2634
2635 @xref{exclude,,exclude-vcs}.
2636
2637 @opsummary{file}
2638 @item --file=@var{archive}
2639 @itemx -f @var{archive}
2640
2641 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2642 performs operations on, rather than @command{tar}'s compilation dependent
2643 default. @xref{file tutorial}.
2644
2645 @opsummary{files-from}
2646 @item --files-from=@var{file}
2647 @itemx -T @var{file}
2648
2649 @command{tar} will use the contents of @var{file} as a list of archive members
2650 or files to operate on, in addition to those specified on the
2651 command-line. @xref{files}.
2652
2653 @opsummary{force-local}
2654 @item --force-local
2655
2656 Forces @command{tar} to interpret the file name given to @option{--file}
2657 as a local file, even if it looks like a remote tape drive name.
2658 @xref{local and remote archives}.
2659
2660 @opsummary{format}
2661 @item --format=@var{format}
2662 @itemx -H @var{format}
2663
2664 Selects output archive format. @var{Format} may be one of the
2665 following:
2666
2667 @table @samp
2668 @item v7
2669 Creates an archive that is compatible with Unix V7 @command{tar}.
2670
2671 @item oldgnu
2672 Creates an archive that is compatible with GNU @command{tar} version
2673 1.12 or earlier.
2674
2675 @item gnu
2676 Creates archive in GNU tar 1.13 format. Basically it is the same as
2677 @samp{oldgnu} with the only difference in the way it handles long
2678 numeric fields.
2679
2680 @item ustar
2681 Creates a @acronym{POSIX.1-1988} compatible archive.
2682
2683 @item posix
2684 Creates a @acronym{POSIX.1-2001 archive}.
2685
2686 @end table
2687
2688 @xref{Formats}, for a detailed discussion of these formats.
2689
2690 @opsummary{full-time}
2691 @item --full-time
2692 This option instructs @command{tar} to print file times to their full
2693 resolution. Usually this means 1-second resolution, but that depends
2694 on the underlying file system. The @option{--full-time} option takes
2695 effect only when detailed output (verbosity level 2 or higher) has
2696 been requested using the @option{--verbose} option, e.g., when listing
2697 or extracting archives:
2698
2699 @smallexample
2700 $ @kbd{tar -t -v --full-time -f archive.tar}
2701 @end smallexample
2702
2703 @noindent
2704 or, when creating an archive:
2705
2706 @smallexample
2707 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2708 @end smallexample
2709
2710 Notice, thar when creating the archive you need to specify
2711 @option{--verbose} twice to get a detailed output (@pxref{verbose
2712 tutorial}).
2713
2714 @opsummary{group}
2715 @item --group=@var{group}
2716
2717 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2718 rather than the group from the source file. @var{group} can specify a
2719 symbolic name, or a numeric @acronym{ID}, or both as
2720 @var{name}:@var{id}. @xref{override}.
2721
2722 Also see the comments for the @option{--owner=@var{user}} option.
2723
2724 @opsummary{gzip}
2725 @opsummary{gunzip}
2726 @opsummary{ungzip}
2727 @item --gzip
2728 @itemx --gunzip
2729 @itemx --ungzip
2730 @itemx -z
2731
2732 This option tells @command{tar} to read or write archives through
2733 @command{gzip}, allowing @command{tar} to directly operate on several
2734 kinds of compressed archives transparently. @xref{gzip}.
2735
2736 @opsummary{hard-dereference}
2737 @item --hard-dereference
2738 When creating an archive, dereference hard links and store the files
2739 they refer to, instead of creating usual hard link members.
2740
2741 @xref{hard links}.
2742
2743 @opsummary{help}
2744 @item --help
2745 @itemx -?
2746
2747 @command{tar} will print out a short message summarizing the operations and
2748 options to @command{tar} and exit. @xref{help}.
2749
2750 @opsummary{ignore-case}
2751 @item --ignore-case
2752 Ignore case when matching member or file names with
2753 patterns. @xref{controlling pattern-matching}.
2754
2755 @opsummary{ignore-command-error}
2756 @item --ignore-command-error
2757 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2758
2759 @opsummary{ignore-failed-read}
2760 @item --ignore-failed-read
2761
2762 Do not exit unsuccessfully merely because an unreadable file was encountered.
2763 @xref{Ignore Failed Read}.
2764
2765 @opsummary{ignore-zeros}
2766 @item --ignore-zeros
2767 @itemx -i
2768
2769 With this option, @command{tar} will ignore zeroed blocks in the
2770 archive, which normally signals EOF. @xref{Reading}.
2771
2772 @opsummary{incremental}
2773 @item --incremental
2774 @itemx -G
2775
2776 Informs @command{tar} that it is working with an old
2777 @acronym{GNU}-format incremental backup archive. It is intended
2778 primarily for backwards compatibility only. @xref{Incremental Dumps},
2779 for a detailed discussion of incremental archives.
2780
2781 @opsummary{index-file}
2782 @item --index-file=@var{file}
2783
2784 Send verbose output to @var{file} instead of to standard output.
2785
2786 @opsummary{info-script}
2787 @opsummary{new-volume-script}
2788 @item --info-script=@var{command}
2789 @itemx --new-volume-script=@var{command}
2790 @itemx -F @var{command}
2791
2792 When @command{tar} is performing multi-tape backups, @var{command} is run
2793 at the end of each tape. If it exits with nonzero status,
2794 @command{tar} fails immediately. @xref{info-script}, for a detailed
2795 discussion of this feature.
2796
2797 @opsummary{interactive}
2798 @item --interactive
2799 @itemx --confirmation
2800 @itemx -w
2801
2802 Specifies that @command{tar} should ask the user for confirmation before
2803 performing potentially destructive options, such as overwriting files.
2804 @xref{interactive}.
2805
2806 @opsummary{keep-newer-files}
2807 @item --keep-newer-files
2808
2809 Do not replace existing files that are newer than their archive copies
2810 when extracting files from an archive.
2811
2812 @opsummary{keep-old-files}
2813 @item --keep-old-files
2814 @itemx -k
2815
2816 Do not overwrite existing files when extracting files from an
2817 archive. Return error if such files exist. See also
2818 @ref{--skip-old-files}.
2819
2820 @xref{Keep Old Files}.
2821
2822 @opsummary{label}
2823 @item --label=@var{name}
2824 @itemx -V @var{name}
2825
2826 When creating an archive, instructs @command{tar} to write @var{name}
2827 as a name record in the archive. When extracting or listing archives,
2828 @command{tar} will only operate on archives that have a label matching
2829 the pattern specified in @var{name}. @xref{Tape Files}.
2830
2831 @opsummary{level}
2832 @item --level=@var{n}
2833 Force incremental backup of level @var{n}. As of @GNUTAR version
2834 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2835 file, thereby forcing the level 0 dump. Other values of @var{n} are
2836 effectively ignored. @xref{--level=0}, for details and examples.
2837
2838 The use of this option is valid only in conjunction with the
2839 @option{--listed-incremental} option. @xref{Incremental Dumps},
2840 for a detailed description.
2841
2842 @opsummary{listed-incremental}
2843 @item --listed-incremental=@var{snapshot-file}
2844 @itemx -g @var{snapshot-file}
2845
2846 During a @option{--create} operation, specifies that the archive that
2847 @command{tar} creates is a new @acronym{GNU}-format incremental
2848 backup, using @var{snapshot-file} to determine which files to backup.
2849 With other operations, informs @command{tar} that the archive is in
2850 incremental format. @xref{Incremental Dumps}.
2851
2852 @opsummary{lzip}
2853 @item --lzip
2854
2855 This option tells @command{tar} to read or write archives through
2856 @command{lzip}. @xref{gzip}.
2857
2858 @opsummary{lzma}
2859 @item --lzma
2860
2861 This option tells @command{tar} to read or write archives through
2862 @command{lzma}. @xref{gzip}.
2863
2864 @item --lzop
2865
2866 This option tells @command{tar} to read or write archives through
2867 @command{lzop}. @xref{gzip}.
2868
2869 @opsummary{mode}
2870 @item --mode=@var{permissions}
2871
2872 When adding files to an archive, @command{tar} will use
2873 @var{permissions} for the archive members, rather than the permissions
2874 from the files. @var{permissions} can be specified either as an octal
2875 number or as symbolic permissions, like with
2876 @command{chmod}. @xref{override}.
2877
2878 @opsummary{mtime}
2879 @item --mtime=@var{date}
2880
2881 When adding files to an archive, @command{tar} will use @var{date} as
2882 the modification time of members when creating archives, instead of
2883 their actual modification times. The value of @var{date} can be
2884 either a textual date representation (@pxref{Date input formats}) or a
2885 name of the existing file, starting with @samp{/} or @samp{.}. In the
2886 latter case, the modification time of that file is used. @xref{override}.
2887
2888 @opsummary{multi-volume}
2889 @item --multi-volume
2890 @itemx -M
2891
2892 Informs @command{tar} that it should create or otherwise operate on a
2893 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2894
2895 @opsummary{new-volume-script}
2896 @item --new-volume-script
2897
2898 (see @option{--info-script})
2899
2900 @opsummary{newer}
2901 @item --newer=@var{date}
2902 @itemx --after-date=@var{date}
2903 @itemx -N
2904
2905 When creating an archive, @command{tar} will only add files that have changed
2906 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2907 is taken to be the name of a file whose data modification time specifies
2908 the date. @xref{after}.
2909
2910 @opsummary{newer-mtime}
2911 @item --newer-mtime=@var{date}
2912
2913 Like @option{--newer}, but add only files whose
2914 contents have changed (as opposed to just @option{--newer}, which will
2915 also back up files for which any status information has
2916 changed). @xref{after}.
2917
2918 @opsummary{no-anchored}
2919 @item --no-anchored
2920 An exclude pattern can match any subsequence of the name's components.
2921 @xref{controlling pattern-matching}.
2922
2923 @opsummary{no-auto-compress}
2924 @item --no-auto-compress
2925
2926 Disables automatic compressed format recognition based on the archive
2927 suffix. @xref{--auto-compress}. @xref{gzip}.
2928
2929 @opsummary{no-check-device}
2930 @item --no-check-device
2931 Do not check device numbers when creating a list of modified files
2932 for incremental archiving. @xref{device numbers}, for
2933 a detailed description.
2934
2935 @opsummary{no-delay-directory-restore}
2936 @item --no-delay-directory-restore
2937
2938 Modification times and permissions of extracted
2939 directories are set when all files from this directory have been
2940 extracted. This is the default.
2941 @xref{Directory Modification Times and Permissions}.
2942
2943 @opsummary{no-ignore-case}
2944 @item --no-ignore-case
2945 Use case-sensitive matching.
2946 @xref{controlling pattern-matching}.
2947
2948 @opsummary{no-ignore-command-error}
2949 @item --no-ignore-command-error
2950 Print warnings about subprocesses that terminated with a nonzero exit
2951 code. @xref{Writing to an External Program}.
2952
2953 @opsummary{no-null}
2954 @item --no-null
2955
2956 If the @option{--null} option was given previously, this option
2957 cancels its effect, so that any following @option{--files-from}
2958 options will expect their file lists to be newline-terminated.
2959
2960 @opsummary{no-overwrite-dir}
2961 @item --no-overwrite-dir
2962
2963 Preserve metadata of existing directories when extracting files
2964 from an archive. @xref{Overwrite Old Files}.
2965
2966 @opsummary{no-quote-chars}
2967 @item --no-quote-chars=@var{string}
2968 Remove characters listed in @var{string} from the list of quoted
2969 characters set by the previous @option{--quote-chars} option
2970 (@pxref{quoting styles}).
2971
2972 @opsummary{no-recursion}
2973 @item --no-recursion
2974
2975 With this option, @command{tar} will not recurse into directories.
2976 @xref{recurse}.
2977
2978 @opsummary{no-same-owner}
2979 @item --no-same-owner
2980 @itemx -o
2981
2982 When extracting an archive, do not attempt to preserve the owner
2983 specified in the @command{tar} archive. This the default behavior
2984 for ordinary users.
2985
2986 @opsummary{no-same-permissions}
2987 @item --no-same-permissions
2988
2989 When extracting an archive, subtract the user's umask from files from
2990 the permissions specified in the archive. This is the default behavior
2991 for ordinary users.
2992
2993 @opsummary{no-seek}
2994 @item --no-seek
2995
2996 The archive media does not support seeks to arbitrary
2997 locations. Usually @command{tar} determines automatically whether
2998 the archive can be seeked or not. Use this option to disable this
2999 mechanism.
3000
3001 @opsummary{no-unquote}
3002 @item --no-unquote
3003 Treat all input file or member names literally, do not interpret
3004 escape sequences. @xref{input name quoting}.
3005
3006 @opsummary{no-wildcards}
3007 @item --no-wildcards
3008 Do not use wildcards.
3009 @xref{controlling pattern-matching}.
3010
3011 @opsummary{no-wildcards-match-slash}
3012 @item --no-wildcards-match-slash
3013 Wildcards do not match @samp{/}.
3014 @xref{controlling pattern-matching}.
3015
3016 @opsummary{null}
3017 @item --null
3018
3019 When @command{tar} is using the @option{--files-from} option, this option
3020 instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
3021 @command{tar} can correctly work with file names that contain newlines.
3022 @xref{nul}.
3023
3024 @opsummary{numeric-owner}
3025 @item --numeric-owner
3026
3027 This option will notify @command{tar} that it should use numeric user
3028 and group IDs when creating a @command{tar} file, rather than names.
3029 @xref{Attributes}.
3030
3031 @item -o
3032 The function of this option depends on the action @command{tar} is
3033 performing. When extracting files, @option{-o} is a synonym for
3034 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3035 restoring ownership of files being extracted.
3036
3037 When creating an archive, it is a synonym for
3038 @option{--old-archive}. This behavior is for compatibility
3039 with previous versions of @GNUTAR{}, and will be
3040 removed in future releases.
3041
3042 @xref{Changes}, for more information.
3043
3044 @opsummary{occurrence}
3045 @item --occurrence[=@var{number}]
3046
3047 This option can be used in conjunction with one of the subcommands
3048 @option{--delete}, @option{--diff}, @option{--extract} or
3049 @option{--list} when a list of files is given either on the command
3050 line or via @option{-T} option.
3051
3052 This option instructs @command{tar} to process only the @var{number}th
3053 occurrence of each named file. @var{Number} defaults to 1, so
3054
3055 @smallexample
3056 tar -x -f archive.tar --occurrence filename
3057 @end smallexample
3058
3059 @noindent
3060 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3061 and will terminate without scanning to the end of the archive.
3062
3063 @opsummary{old-archive}
3064 @item --old-archive
3065 Synonym for @option{--format=v7}.
3066
3067 @opsummary{one-file-system}
3068 @item --one-file-system
3069 Used when creating an archive. Prevents @command{tar} from recursing into
3070 directories that are on different file systems from the current
3071 directory.
3072
3073 @opsummary{overwrite}
3074 @item --overwrite
3075
3076 Overwrite existing files and directory metadata when extracting files
3077 from an archive. @xref{Overwrite Old Files}.
3078
3079 @opsummary{overwrite-dir}
3080 @item --overwrite-dir
3081
3082 Overwrite the metadata of existing directories when extracting files
3083 from an archive. @xref{Overwrite Old Files}.
3084
3085 @opsummary{owner}
3086 @item --owner=@var{user}
3087
3088 Specifies that @command{tar} should use @var{user} as the owner of members
3089 when creating archives, instead of the user associated with the source
3090 file. @var{user} can specify a symbolic name, or a numeric
3091 @acronym{ID}, or both as @var{name}:@var{id}.
3092 @xref{override}.
3093
3094 This option does not affect extraction from archives.
3095
3096 @opsummary{pax-option}
3097 @item --pax-option=@var{keyword-list}
3098 This option enables creation of the archive in @acronym{POSIX.1-2001}
3099 format (@pxref{posix}) and modifies the way @command{tar} handles the
3100 extended header keywords. @var{Keyword-list} is a comma-separated
3101 list of keyword options. @xref{PAX keywords}, for a detailed
3102 discussion.
3103
3104 @opsummary{portability}
3105 @item --portability
3106 @itemx --old-archive
3107 Synonym for @option{--format=v7}.
3108
3109 @opsummary{posix}
3110 @item --posix
3111 Same as @option{--format=posix}.
3112
3113 @opsummary{preserve}
3114 @item --preserve
3115
3116 Synonymous with specifying both @option{--preserve-permissions} and
3117 @option{--same-order}. @xref{Setting Access Permissions}.
3118
3119 @opsummary{preserve-order}
3120 @item --preserve-order
3121
3122 (See @option{--same-order}; @pxref{Reading}.)
3123
3124 @opsummary{preserve-permissions}
3125 @opsummary{same-permissions}
3126 @item --preserve-permissions
3127 @itemx --same-permissions
3128 @itemx -p
3129
3130 When @command{tar} is extracting an archive, it normally subtracts the
3131 users' umask from the permissions specified in the archive and uses
3132 that number as the permissions to create the destination file.
3133 Specifying this option instructs @command{tar} that it should use the
3134 permissions directly from the archive. @xref{Setting Access Permissions}.
3135
3136 @opsummary{quote-chars}
3137 @item --quote-chars=@var{string}
3138 Always quote characters from @var{string}, even if the selected
3139 quoting style would not quote them (@pxref{quoting styles}).
3140
3141 @opsummary{quoting-style}
3142 @item --quoting-style=@var{style}
3143 Set quoting style to use when printing member and file names
3144 (@pxref{quoting styles}). Valid @var{style} values are:
3145 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3146 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3147 style is @code{escape}, unless overridden while configuring the
3148 package.
3149
3150 @opsummary{read-full-records}
3151 @item --read-full-records
3152 @itemx -B
3153
3154 Specifies that @command{tar} should reblock its input, for reading
3155 from pipes on systems with buggy implementations. @xref{Reading}.
3156
3157 @opsummary{record-size}
3158 @item --record-size=@var{size}[@var{suf}]
3159
3160 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3161 archive. The argument can be suffixed with a @dfn{size suffix}, e.g.
3162 @option{--record-size=10K} for 10 Kilobytes. @xref{size-suffixes},
3163 for a list of valid suffixes. @xref{Blocking Factor}, for a detailed
3164 description of this option.
3165
3166 @opsummary{recursion}
3167 @item --recursion
3168
3169 With this option, @command{tar} recurses into directories (default).
3170 @xref{recurse}.
3171
3172 @opsummary{recursive-unlink}
3173 @item --recursive-unlink
3174
3175 Remove existing
3176 directory hierarchies before extracting directories of the same name
3177 from the archive. @xref{Recursive Unlink}.
3178
3179 @opsummary{remove-files}
3180 @item --remove-files
3181
3182 Directs @command{tar} to remove the source file from the file system after
3183 appending it to an archive. @xref{remove files}.
3184
3185 @opsummary{restrict}
3186 @item --restrict
3187
3188 Disable use of some potentially harmful @command{tar} options.
3189 Currently this option disables shell invocation from multi-volume menu
3190 (@pxref{Using Multiple Tapes}).
3191
3192 @opsummary{rmt-command}
3193 @item --rmt-command=@var{cmd}
3194
3195 Notifies @command{tar} that it should use @var{cmd} instead of
3196 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3197
3198 @opsummary{rsh-command}
3199 @item --rsh-command=@var{cmd}
3200
3201 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3202 devices. @xref{Device}.
3203
3204 @opsummary{same-order}
3205 @item --same-order
3206 @itemx --preserve-order
3207 @itemx -s
3208
3209 This option is an optimization for @command{tar} when running on machines with
3210 small amounts of memory. It informs @command{tar} that the list of file
3211 arguments has already been sorted to match the order of files in the
3212 archive. @xref{Reading}.
3213
3214 @opsummary{same-owner}
3215 @item --same-owner
3216
3217 When extracting an archive, @command{tar} will attempt to preserve the owner
3218 specified in the @command{tar} archive with this option present.
3219 This is the default behavior for the superuser; this option has an
3220 effect only for ordinary users. @xref{Attributes}.
3221
3222 @opsummary{same-permissions}
3223 @item --same-permissions
3224
3225 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3226
3227 @opsummary{seek}
3228 @item --seek
3229 @itemx -n
3230
3231 Assume that the archive media supports seeks to arbitrary
3232 locations. Usually @command{tar} determines automatically whether
3233 the archive can be seeked or not. This option is intended for use
3234 in cases when such recognition fails. It takes effect only if the
3235 archive is open for reading (e.g. with @option{--list} or
3236 @option{--extract} options).
3237
3238 @opsummary{show-defaults}
3239 @item --show-defaults
3240
3241 Displays the default options used by @command{tar} and exits
3242 successfully. This option is intended for use in shell scripts.
3243 Here is an example of what you can see using this option:
3244
3245 @smallexample
3246 $ @kbd{tar --show-defaults}
3247 --format=gnu -f- -b20 --quoting-style=escape
3248 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3249 @end smallexample
3250
3251 @noindent
3252 Notice, that this option outputs only one line. The example output
3253 above has been split to fit page boundaries.
3254
3255 @opsummary{show-omitted-dirs}
3256 @item --show-omitted-dirs
3257
3258 Instructs @command{tar} to mention the directories it is skipping when
3259 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3260
3261 @opsummary{show-transformed-names}
3262 @opsummary{show-stored-names}
3263 @item --show-transformed-names
3264 @itemx --show-stored-names
3265
3266 Display file or member names after applying any transformations
3267 (@pxref{transform}). In particular, when used in conjunction with one of
3268 the archive creation operations it instructs @command{tar} to list the
3269 member names stored in the archive, as opposed to the actual file
3270 names. @xref{listing member and file names}.
3271
3272 @opsummary{skip-old-files}
3273 @item --skip-old-files
3274
3275 Do not overwrite existing files when extracting files from an
3276 archive. @xref{Keep Old Files}.
3277
3278 This option differs from @option{--keep-old-files} in that it does not
3279 treat such files as an error, instead it just silently avoids
3280 overwriting them.
3281
3282 The @option{--warning=existing-file} option can be used together with
3283 this option to produce warning messages about existing old files
3284 (@pxref{warnings}).
3285
3286 @opsummary{sparse}
3287 @item --sparse
3288 @itemx -S
3289
3290 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3291 sparse files efficiently. @xref{sparse}.
3292
3293 @opsummary{sparse-version}
3294 @item --sparse-version=@var{version}
3295
3296 Specifies the @dfn{format version} to use when archiving sparse
3297 files. Implies @option{--sparse}. @xref{sparse}. For the description
3298 of the supported sparse formats, @xref{Sparse Formats}.
3299
3300 @opsummary{starting-file}
3301 @item --starting-file=@var{name}
3302 @itemx -K @var{name}
3303
3304 This option affects extraction only; @command{tar} will skip extracting
3305 files in the archive until it finds one that matches @var{name}.
3306 @xref{Scarce}.
3307
3308 @opsummary{strip-components}
3309 @item --strip-components=@var{number}
3310 Strip given @var{number} of leading components from file names before
3311 extraction. For example, if archive @file{archive.tar} contained
3312 @file{/some/file/name}, then running
3313
3314 @smallexample
3315 tar --extract --file archive.tar --strip-components=2
3316 @end smallexample
3317
3318 @noindent
3319 would extract this file to file @file{name}.
3320
3321 @opsummary{suffix}
3322 @item --suffix=@var{suffix}
3323
3324 Alters the suffix @command{tar} uses when backing up files from the default
3325 @samp{~}. @xref{backup}.
3326
3327 @opsummary{tape-length}
3328 @item --tape-length=@var{num}[@var{suf}]
3329 @itemx -L @var{num}[@var{suf}]
3330
3331 Specifies the length of tapes that @command{tar} is writing as being
3332 @w{@var{num} x 1024} bytes long. If optional @var{suf} is given, it
3333 specifies a multiplicative factor to be used instead of 1024. For
3334 example, @samp{-L2M} means 2 megabytes. @xref{size-suffixes}, for a
3335 list of allowed suffixes. @xref{Using Multiple Tapes}, for a detailed
3336 discussion of this option.
3337
3338 @opsummary{test-label}
3339 @item --test-label
3340
3341 Reads the volume label. If an argument is specified, test whether it
3342 matches the volume label. @xref{--test-label option}.
3343
3344 @opsummary{to-command}
3345 @item --to-command=@var{command}
3346
3347 During extraction @command{tar} will pipe extracted files to the
3348 standard input of @var{command}. @xref{Writing to an External Program}.
3349
3350 @opsummary{to-stdout}
3351 @item --to-stdout
3352 @itemx -O
3353
3354 During extraction, @command{tar} will extract files to stdout rather
3355 than to the file system. @xref{Writing to Standard Output}.
3356
3357 @opsummary{totals}
3358 @item --totals[=@var{signo}]
3359
3360 Displays the total number of bytes transferred when processing an
3361 archive. If an argument is given, these data are displayed on
3362 request, when signal @var{signo} is delivered to @command{tar}.
3363 @xref{totals}.
3364
3365 @opsummary{touch}
3366 @item --touch
3367 @itemx -m
3368
3369 Sets the data modification time of extracted files to the extraction time,
3370 rather than the data modification time stored in the archive.
3371 @xref{Data Modification Times}.
3372
3373 @opsummary{transform}
3374 @opsummary{xform}
3375 @item --transform=@var{sed-expr}
3376 @itemx --xform=@var{sed-expr}
3377 Transform file or member names using @command{sed} replacement expression
3378 @var{sed-expr}. For example,
3379
3380 @smallexample
3381 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3382 @end smallexample
3383
3384 @noindent
3385 will add to @file{archive} files from the current working directory,
3386 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3387 discussion, @xref{transform}.
3388
3389 To see transformed member names in verbose listings, use
3390 @option{--show-transformed-names} option
3391 (@pxref{show-transformed-names}).
3392
3393 @opsummary{uncompress}
3394 @item --uncompress
3395
3396 (See @option{--compress}, @pxref{gzip})
3397
3398 @opsummary{ungzip}
3399 @item --ungzip
3400
3401 (See @option{--gzip}, @pxref{gzip})
3402
3403 @opsummary{unlink-first}
3404 @item --unlink-first
3405 @itemx -U
3406
3407 Directs @command{tar} to remove the corresponding file from the file
3408 system before extracting it from the archive. @xref{Unlink First}.
3409
3410 @opsummary{unquote}
3411 @item --unquote
3412 Enable unquoting input file or member names (default). @xref{input
3413 name quoting}.
3414
3415 @opsummary{use-compress-program}
3416 @item --use-compress-program=@var{prog}
3417 @itemx -I=@var{prog}
3418
3419 Instructs @command{tar} to access the archive through @var{prog}, which is
3420 presumed to be a compression program of some sort. @xref{gzip}.
3421
3422 @opsummary{utc}
3423 @item --utc
3424
3425 Display file modification dates in @acronym{UTC}. This option implies
3426 @option{--verbose}.
3427
3428 @opsummary{verbose}
3429 @item --verbose
3430 @itemx -v
3431
3432 Specifies that @command{tar} should be more verbose about the
3433 operations it is performing. This option can be specified multiple
3434 times for some operations to increase the amount of information displayed.
3435 @xref{verbose}.
3436
3437 @opsummary{verify}
3438 @item --verify
3439 @itemx -W
3440
3441 Verifies that the archive was correctly written when creating an
3442 archive. @xref{verify}.
3443
3444 @opsummary{version}
3445 @item --version
3446
3447 Print information about the program's name, version, origin and legal
3448 status, all on standard output, and then exit successfully.
3449 @xref{help}.
3450
3451 @opsummary{volno-file}
3452 @item --volno-file=@var{file}
3453
3454 Used in conjunction with @option{--multi-volume}. @command{tar} will
3455 keep track of which volume of a multi-volume archive it is working in
3456 @var{file}. @xref{volno-file}.
3457
3458 @opsummary{warning}
3459 @item --warning=@var{keyword}
3460
3461 Enable or disable warning messages identified by @var{keyword}. The
3462 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3463 @xref{warnings}.
3464
3465 @opsummary{wildcards}
3466 @item --wildcards
3467 Use wildcards when matching member names with patterns.
3468 @xref{controlling pattern-matching}.
3469
3470 @opsummary{wildcards-match-slash}
3471 @item --wildcards-match-slash
3472 Wildcards match @samp{/}.
3473 @xref{controlling pattern-matching}.
3474
3475 @opsummary{xz}
3476 @item --xz
3477 @itemx -J
3478 Use @command{xz} for compressing or decompressing the archives. @xref{gzip}.
3479
3480 @end table
3481
3482 @node Short Option Summary
3483 @subsection Short Options Cross Reference
3484
3485 Here is an alphabetized list of all of the short option forms, matching
3486 them with the equivalent long option.
3487
3488 @multitable @columnfractions 0.20 0.80
3489 @headitem Short Option @tab Reference
3490
3491 @item -A @tab @ref{--concatenate}.
3492
3493 @item -B @tab @ref{--read-full-records}.
3494
3495 @item -C @tab @ref{--directory}.
3496
3497 @item -F @tab @ref{--info-script}.
3498
3499 @item -G @tab @ref{--incremental}.
3500
3501 @item -J @tab @ref{--xz}.
3502
3503 @item -K @tab @ref{--starting-file}.
3504
3505 @item -L @tab @ref{--tape-length}.
3506
3507 @item -M @tab @ref{--multi-volume}.
3508
3509 @item -N @tab @ref{--newer}.
3510
3511 @item -O @tab @ref{--to-stdout}.
3512
3513 @item -P @tab @ref{--absolute-names}.
3514
3515 @item -R @tab @ref{--block-number}.
3516
3517 @item -S @tab @ref{--sparse}.
3518
3519 @item -T @tab @ref{--files-from}.
3520
3521 @item -U @tab @ref{--unlink-first}.
3522
3523 @item -V @tab @ref{--label}.
3524
3525 @item -W @tab @ref{--verify}.
3526
3527 @item -X @tab @ref{--exclude-from}.
3528
3529 @item -Z @tab @ref{--compress}.
3530
3531 @item -b @tab @ref{--blocking-factor}.
3532
3533 @item -c @tab @ref{--create}.
3534
3535 @item -d @tab @ref{--compare}.
3536
3537 @item -f @tab @ref{--file}.
3538
3539 @item -g @tab @ref{--listed-incremental}.
3540
3541 @item -h @tab @ref{--dereference}.
3542
3543 @item -i @tab @ref{--ignore-zeros}.
3544
3545 @item -j @tab @ref{--bzip2}.
3546
3547 @item -k @tab @ref{--keep-old-files}.
3548
3549 @item -l @tab @ref{--check-links}.
3550
3551 @item -m @tab @ref{--touch}.
3552
3553 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3554 @ref{--portability}.
3555
3556 The latter usage is deprecated. It is retained for compatibility with
3557 the earlier versions of @GNUTAR{}. In future releases
3558 @option{-o} will be equivalent to @option{--no-same-owner} only.
3559
3560 @item -p @tab @ref{--preserve-permissions}.
3561
3562 @item -r @tab @ref{--append}.
3563
3564 @item -s @tab @ref{--same-order}.
3565
3566 @item -t @tab @ref{--list}.
3567
3568 @item -u @tab @ref{--update}.
3569
3570 @item -v @tab @ref{--verbose}.
3571
3572 @item -w @tab @ref{--interactive}.
3573
3574 @item -x @tab @ref{--extract}.
3575
3576 @item -z @tab @ref{--gzip}.
3577
3578 @end multitable
3579
3580 @node help
3581 @section @GNUTAR{} documentation
3582
3583 @cindex Getting program version number
3584 @opindex version
3585 @cindex Version of the @command{tar} program
3586 Being careful, the first thing is really checking that you are using
3587 @GNUTAR{}, indeed. The @option{--version} option
3588 causes @command{tar} to print information about its name, version,
3589 origin and legal status, all on standard output, and then exit
3590 successfully. For example, @w{@samp{tar --version}} might print:
3591
3592 @smallexample
3593 tar (GNU tar) @value{VERSION}
3594 Copyright (C) 2013 Free Software Foundation, Inc.
3595 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3596 This is free software: you are free to change and redistribute it.
3597 There is NO WARRANTY, to the extent permitted by law.
3598
3599 Written by John Gilmore and Jay Fenlason.
3600 @end smallexample
3601
3602 @noindent
3603 The first occurrence of @samp{tar} in the result above is the program
3604 name in the package (for example, @command{rmt} is another program),
3605 while the second occurrence of @samp{tar} is the name of the package
3606 itself, containing possibly many programs. The package is currently
3607 named @samp{tar}, after the name of the main program it
3608 contains@footnote{There are plans to merge the @command{cpio} and
3609 @command{tar} packages into a single one which would be called
3610 @code{paxutils}. So, who knows if, one of this days, the
3611 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3612 paxutils) 3.2}}.}.
3613
3614 @cindex Obtaining help
3615 @cindex Listing all @command{tar} options
3616 @xopindex{help, introduction}
3617 Another thing you might want to do is checking the spelling or meaning
3618 of some particular @command{tar} option, without resorting to this
3619 manual, for once you have carefully read it. @GNUTAR{}
3620 has a short help feature, triggerable through the
3621 @option{--help} option. By using this option, @command{tar} will
3622 print a usage message listing all available options on standard
3623 output, then exit successfully, without doing anything else and
3624 ignoring all other options. Even if this is only a brief summary, it
3625 may be several screens long. So, if you are not using some kind of
3626 scrollable window, you might prefer to use something like:
3627
3628 @smallexample
3629 $ @kbd{tar --help | less}
3630 @end smallexample
3631
3632 @noindent
3633 presuming, here, that you like using @command{less} for a pager. Other
3634 popular pagers are @command{more} and @command{pg}. If you know about some
3635 @var{keyword} which interests you and do not want to read all the
3636 @option{--help} output, another common idiom is doing:
3637
3638 @smallexample
3639 tar --help | grep @var{keyword}
3640 @end smallexample
3641
3642 @noindent
3643 for getting only the pertinent lines. Notice, however, that some
3644 @command{tar} options have long description lines and the above
3645 command will list only the first of them.
3646
3647 The exact look of the option summary displayed by @kbd{tar --help} is
3648 configurable. @xref{Configuring Help Summary}, for a detailed description.
3649
3650 @opindex usage
3651 If you only wish to check the spelling of an option, running @kbd{tar
3652 --usage} may be a better choice. This will display a terse list of
3653 @command{tar} options without accompanying explanations.
3654
3655 The short help output is quite succinct, and you might have to get
3656 back to the full documentation for precise points. If you are reading
3657 this paragraph, you already have the @command{tar} manual in some
3658 form. This manual is available in a variety of forms from
3659 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3660 distribution, provided you have @TeX{} already installed somewhere,
3661 and a laser printer around. Just configure the distribution, execute
3662 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3663 usual way (contact your local guru to know how). If @GNUTAR{}
3664 has been conveniently installed at your place, this
3665 manual is also available in interactive, hypertextual form as an Info
3666 file. Just call @w{@samp{info tar}} or, if you do not have the
3667 @command{info} program handy, use the Info reader provided within
3668 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3669
3670 There is currently no @code{man} page for @GNUTAR{}.
3671 If you observe such a @code{man} page on the system you are running,
3672 either it does not belong to @GNUTAR{}, or it has not
3673 been produced by @acronym{GNU}. Some package maintainers convert
3674 @kbd{tar --help} output to a man page, using @command{help2man}. In
3675 any case, please bear in mind that the authoritative source of
3676 information about @GNUTAR{} is this Texinfo documentation.
3677
3678 @node defaults
3679 @section Obtaining @GNUTAR{} default values
3680
3681 @opindex show-defaults
3682 @GNUTAR{} has some predefined defaults that are used when you do not
3683 explicitly specify another values. To obtain a list of such
3684 defaults, use @option{--show-defaults} option. This will output the
3685 values in the form of @command{tar} command line options:
3686
3687 @smallexample
3688 @group
3689 $ @kbd{tar --show-defaults}
3690 --format=gnu -f- -b20 --quoting-style=escape
3691 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3692 @end group
3693 @end smallexample
3694
3695 @noindent
3696 Notice, that this option outputs only one line. The example output above
3697 has been split to fit page boundaries.
3698
3699 @noindent
3700 The above output shows that this version of @GNUTAR{} defaults to
3701 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3702 output as the archive, if no @option{--file} option has been given
3703 (@pxref{file tutorial}), the default blocking factor is 20
3704 (@pxref{Blocking Factor}). It also shows the default locations where
3705 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3706
3707 @node verbose
3708 @section Checking @command{tar} progress
3709
3710 Typically, @command{tar} performs most operations without reporting any
3711 information to the user except error messages. When using @command{tar}
3712 with many options, particularly ones with complicated or
3713 difficult-to-predict behavior, it is possible to make serious mistakes.
3714 @command{tar} provides several options that make observing @command{tar}
3715 easier. These options cause @command{tar} to print information as it
3716 progresses in its job, and you might want to use them just for being
3717 more careful about what is going on, or merely for entertaining
3718 yourself. If you have encountered a problem when operating on an
3719 archive, however, you may need more information than just an error
3720 message in order to solve the problem. The following options can be
3721 helpful diagnostic tools.
3722
3723 @cindex Verbose operation
3724 @opindex verbose
3725 Normally, the @option{--list} (@option{-t}) command to list an archive
3726 prints just the file names (one per line) and the other commands are
3727 silent. When used with most operations, the @option{--verbose}
3728 (@option{-v}) option causes @command{tar} to print the name of each
3729 file or archive member as it is processed. This and the other options
3730 which make @command{tar} print status information can be useful in
3731 monitoring @command{tar}.
3732
3733 With @option{--create} or @option{--extract}, @option{--verbose} used
3734 once just prints the names of the files or members as they are processed.
3735 Using it twice causes @command{tar} to print a longer listing
3736 (@xref{verbose member listing}, for the description) for each member.
3737 Since @option{--list} already prints the names of the members,
3738 @option{--verbose} used once with @option{--list} causes @command{tar}
3739 to print an @samp{ls -l} type listing of the files in the archive.
3740 The following examples both extract members with long list output:
3741
3742 @smallexample
3743 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3744 $ @kbd{tar xvvf archive.tar}
3745 @end smallexample
3746
3747 Verbose output appears on the standard output except when an archive is
3748 being written to the standard output, as with @samp{tar --create
3749 --file=- --verbose} (@samp{tar cvf -}, or even @samp{tar cv}---if the
3750 installer let standard output be the default archive). In that case
3751 @command{tar} writes verbose output to the standard error stream.
3752
3753 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3754 verbose output to @var{file} rather than to standard output or standard
3755 error.
3756
3757 @anchor{totals}
3758 @cindex Obtaining total status information
3759 @opindex totals
3760 The @option{--totals} option causes @command{tar} to print on the
3761 standard error the total amount of bytes transferred when processing
3762 an archive. When creating or appending to an archive, this option
3763 prints the number of bytes written to the archive and the average
3764 speed at which they have been written, e.g.:
3765
3766 @smallexample
3767 @group
3768 $ @kbd{tar -c -f archive.tar --totals /home}
3769 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3770 @end group
3771 @end smallexample
3772
3773 When reading an archive, this option displays the number of bytes
3774 read:
3775
3776 @smallexample
3777 @group
3778 $ @kbd{tar -x -f archive.tar --totals}
3779 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3780 @end group
3781 @end smallexample
3782
3783 Finally, when deleting from an archive, the @option{--totals} option
3784 displays both numbers plus number of bytes removed from the archive:
3785
3786 @smallexample
3787 @group
3788 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3789 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3790 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3791 Total bytes deleted: 1474048
3792 @end group
3793 @end smallexample
3794
3795 You can also obtain this information on request. When
3796 @option{--totals} is used with an argument, this argument is
3797 interpreted as a symbolic name of a signal, upon delivery of which the
3798 statistics is to be printed:
3799
3800 @table @option
3801 @item --totals=@var{signo}
3802 Print statistics upon delivery of signal @var{signo}. Valid arguments
3803 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3804 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3805 accepted.
3806 @end table
3807
3808 Both forms of @option{--totals} option can be used simultaneously.
3809 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3810 extract all members from its default archive and print statistics
3811 after finishing the extraction, as well as when receiving signal
3812 @code{SIGUSR1}.
3813
3814 @anchor{Progress information}
3815 @cindex Progress information
3816 The @option{--checkpoint} option prints an occasional message
3817 as @command{tar} reads or writes the archive. It is designed for
3818 those who don't need the more detailed (and voluminous) output of
3819 @option{--block-number} (@option{-R}), but do want visual confirmation
3820 that @command{tar} is actually making forward progress. By default it
3821 prints a message each 10 records read or written. This can be changed
3822 by giving it a numeric argument after an equal sign:
3823
3824 @smallexample
3825 $ @kbd{tar -c --checkpoint=1000} /var
3826 tar: Write checkpoint 1000
3827 tar: Write checkpoint 2000
3828 tar: Write checkpoint 3000
3829 @end smallexample
3830
3831 This example shows the default checkpoint message used by
3832 @command{tar}. If you place a dot immediately after the equal
3833 sign, it will print a @samp{.} at each checkpoint@footnote{This is
3834 actually a shortcut for @option{--checkpoint=@var{n}
3835 --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
3836
3837 @smallexample
3838 $ @kbd{tar -c --checkpoint=.1000} /var
3839 ...
3840 @end smallexample
3841
3842 The @option{--checkpoint} option provides a flexible mechanism for
3843 executing arbitrary actions upon hitting checkpoints, see the next
3844 section (@pxref{checkpoints}), for more information on it.
3845
3846 @opindex show-omitted-dirs
3847 @anchor{show-omitted-dirs}
3848 The @option{--show-omitted-dirs} option, when reading an archive---with
3849 @option{--list} or @option{--extract}, for example---causes a message
3850 to be printed for each directory in the archive which is skipped.
3851 This happens regardless of the reason for skipping: the directory might
3852 not have been named on the command line (implicitly or explicitly),
3853 it might be excluded by the use of the
3854 @option{--exclude=@var{pattern}} option, or some other reason.
3855
3856 @opindex block-number
3857 @cindex Block number where error occurred
3858 @anchor{block-number}
3859 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3860 every message it would normally produce, the block number within the
3861 archive where the message was triggered. Also, supplementary messages
3862 are triggered when reading blocks full of NULs, or when hitting end of
3863 file on the archive. As of now, if the archive is properly terminated
3864 with a NUL block, the reading of the file may stop before end of file
3865 is met, so the position of end of file will not usually show when
3866 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3867 drains the archive before exiting when reading the
3868 archive from a pipe.
3869
3870 @cindex Error message, block number of
3871 This option is especially useful when reading damaged archives, since
3872 it helps pinpoint the damaged sections. It can also be used with
3873 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3874 choose among several backup tapes when retrieving a file later, in
3875 favor of the tape where the file appears earliest (closest to the
3876 front of the tape). @xref{backup}.
3877
3878 @node checkpoints
3879 @section Checkpoints
3880 @cindex checkpoints, defined
3881 @opindex checkpoint
3882 @opindex checkpoint-action
3883
3884 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
3885 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
3886 from the archive (a @dfn{read checkpoint}). Checkpoints allow to
3887 periodically execute arbitrary actions.
3888
3889 The checkpoint facility is enabled using the following option:
3890
3891 @table @option
3892 @xopindex{checkpoint, defined}
3893 @item --checkpoint[=@var{n}]
3894 Schedule checkpoints before writing or reading each @var{n}th record.
3895 The default value for @var{n} is 10.
3896 @end table
3897
3898 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
3899 These actions include: pausing, displaying textual messages, and
3900 executing arbitrary external programs. Actions are defined using
3901 the @option{--checkpoint-action} option.
3902
3903 @table @option
3904 @xopindex{checkpoint-action, defined}
3905 @item --checkpoint-action=@var{action}
3906 Execute an @var{action} at each checkpoint.
3907 @end table
3908
3909 @cindex @code{echo}, checkpoint action
3910 The simplest value of @var{action} is @samp{echo}. It instructs
3911 @command{tar} to display the default message on the standard error
3912 stream upon arriving at each checkpoint. The default message is (in
3913 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
3914 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
3915 Here, @var{n} represents ordinal number of the checkpoint.
3916
3917 In another locales, translated versions of this message are used.
3918
3919 This is the default action, so running:
3920
3921 @smallexample
3922 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
3923 @end smallexample
3924
3925 @noindent
3926 is equivalent to:
3927
3928 @smallexample
3929 $ @kbd{tar -c --checkpoint=1000} /var
3930 @end smallexample
3931
3932 The @samp{echo} action also allows to supply a customized message.
3933 You do so by placing an equals sign and the message right after it,
3934 e.g.:
3935
3936 @smallexample
3937 --checkpoint-action="echo=Hit %s checkpoint #%u"
3938 @end smallexample
3939
3940 The @samp{%s} and @samp{%u} in the above example are
3941 @dfn{meta-characters}. The @samp{%s} meta-character is replaced with
3942 the @dfn{type} of the checkpoint: @samp{write} or
3943 @samp{read} (or a corresponding translated version in locales other
3944 than @acronym{POSIX}). The @samp{%u} meta-character is replaced with
3945 the ordinal number of the checkpoint. Thus, the above example could
3946 produce the following output when used with the @option{--create}
3947 option:
3948
3949 @smallexample
3950 tar: Hit write checkpoint #10
3951 tar: Hit write checkpoint #20
3952 tar: Hit write checkpoint #30
3953 @end smallexample
3954
3955 Aside from meta-character expansion, the message string is subject to
3956 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
3957 replaced with their corresponding @acronym{ASCII} characters
3958 (@pxref{escape sequences}). E.g. the following action will produce an
3959 audible bell and the message described above at each checkpoint:
3960
3961 @smallexample
3962 --checkpoint-action='echo=\aHit %s checkpoint #%u'
3963 @end smallexample
3964
3965 @cindex @code{bell}, checkpoint action
3966 There is also a special action which produces an audible signal:
3967 @samp{bell}. It is not equivalent to @samp{echo='\a'}, because
3968 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
3969 whereas @samp{echo='\a'} sends it to the standard error.
3970
3971 @cindex @code{ttyout}, checkpoint action
3972 The @samp{ttyout=@var{string}} action outputs @var{string} to
3973 @file{/dev/tty}, so it can be used even if the standard output is
3974 redirected elsewhere. The @var{string} is subject to the same
3975 modifications as with @samp{echo} action. In contrast to the latter,
3976 @samp{ttyout} does not prepend @command{tar} executable name to the
3977 string, nor does it output a newline after it. For example, the
3978 following action will print the checkpoint message at the same screen
3979 line, overwriting any previous message:
3980
3981 @smallexample
3982 --checkpoint-action="ttyout=\rHit %s checkpoint #%u"
3983 @end smallexample
3984
3985 @cindex @code{dot}, checkpoint action
3986 Another available checkpoint action is @samp{dot} (or @samp{.}). It
3987 instructs @command{tar} to print a single dot on the standard listing
3988 stream, e.g.:
3989
3990 @smallexample
3991 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
3992 ...
3993 @end smallexample
3994
3995 For compatibility with previous @GNUTAR{} versions, this action can
3996 be abbreviated by placing a dot in front of the checkpoint frequency,
3997 as shown in the previous section.
3998
3999 @cindex @code{sleep}, checkpoint action
4000 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
4001 amount of seconds. The following example will stop for 30 seconds at each
4002 checkpoint:
4003
4004 @smallexample
4005 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
4006 @end smallexample
4007
4008 @anchor{checkpoint exec}
4009 @cindex @code{exec}, checkpoint action
4010 Finally, the @code{exec} action executes a given external command.
4011 For example:
4012
4013 @smallexample
4014 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4015 @end smallexample
4016
4017 The supplied command can be any valid command invocation, with or
4018 without additional command line arguments. If it does contain
4019 arguments, don't forget to quote it to prevent it from being split by
4020 the shell. @xref{external, Running External Commands}, for more detail.
4021
4022 The command gets a copy of @command{tar}'s environment plus the
4023 following variables:
4024
4025 @table @env
4026 @vrindex TAR_VERSION, checkpoint script environment
4027 @item TAR_VERSION
4028 @GNUTAR{} version number.
4029
4030 @vrindex TAR_ARCHIVE, checkpoint script environment
4031 @item TAR_ARCHIVE
4032 The name of the archive @command{tar} is processing.
4033
4034 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4035 @item TAR_BLOCKING_FACTOR
4036 Current blocking factor (@pxref{Blocking}).
4037
4038 @vrindex TAR_CHECKPOINT, checkpoint script environment
4039 @item TAR_CHECKPOINT
4040 Number of the checkpoint.
4041
4042 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4043 @item TAR_SUBCOMMAND
4044 A short option describing the operation @command{tar} is executing.
4045 @xref{Operations}, for a complete list of subcommand options.
4046
4047 @vrindex TAR_FORMAT, checkpoint script environment
4048 @item TAR_FORMAT
4049 Format of the archive being processed. @xref{Formats}, for a complete
4050 list of archive format names.
4051 @end table
4052
4053 These environment variables can also be passed as arguments to the
4054 command, provided that they are properly escaped, for example:
4055
4056 @smallexample
4057 @kbd{tar -c -f arc.tar \
4058 --checkpoint-action='exec=/sbin/cpoint $TAR_FILENAME'}
4059 @end smallexample
4060
4061 @noindent
4062 Notice single quotes to prevent variable names from being expanded by
4063 the shell when invoking @command{tar}.
4064
4065 Any number of actions can be defined, by supplying several
4066 @option{--checkpoint-action} options in the command line. For
4067 example, the command below displays two messages, pauses
4068 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4069
4070 @example
4071 @group
4072 $ @kbd{tar -c -f arc.tar \
4073 --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4074 --checkpoint-action='echo=Sleeping for 30 seconds' \
4075 --checkpoint-action='sleep=30' \
4076 --checkpoint-action='exec=/sbin/cpoint'}
4077 @end group
4078 @end example
4079
4080 This example also illustrates the fact that
4081 @option{--checkpoint-action} can be used without
4082 @option{--checkpoint}. In this case, the default checkpoint frequency
4083 (at each 10th record) is assumed.
4084
4085 @node warnings
4086 @section Controlling Warning Messages
4087
4088 Sometimes, while performing the requested task, @GNUTAR{} notices
4089 some conditions that are not exactly errors, but which the user
4090 should be aware of. When this happens, @command{tar} issues a
4091 @dfn{warning message} describing the condition. Warning messages
4092 are output to the standard error and they do not affect the exit
4093 code of @command{tar} command.
4094
4095 @xopindex{warning, explained}
4096 @GNUTAR{} allows the user to suppress some or all of its warning
4097 messages:
4098
4099 @table @option
4100 @item --warning=@var{keyword}
4101 Control display of the warning messages identified by @var{keyword}.
4102 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4103 suppressed. Otherwise, they are enabled.
4104
4105 Multiple @option{--warning} messages accumulate.
4106
4107 The tables below list allowed values for @var{keyword} along with the
4108 warning messages they control.
4109 @end table
4110
4111 @subheading Keywords controlling @command{tar} operation
4112 @table @asis
4113 @kwindex all
4114 @item all
4115 Enable all warning messages. This is the default.
4116 @kwindex none
4117 @item none
4118 Disable all warning messages.
4119 @kwindex filename-with-nuls
4120 @cindex @samp{file name read contains nul character}, warning message
4121 @item filename-with-nuls
4122 @samp{%s: file name read contains nul character}
4123 @kwindex alone-zero-block
4124 @cindex @samp{A lone zero block at}, warning message
4125 @item alone-zero-block
4126 @samp{A lone zero block at %s}
4127 @end table
4128
4129 @subheading Keywords applicable for @command{tar --create}
4130 @table @asis
4131 @kwindex cachedir
4132 @cindex @samp{contains a cache directory tag}, warning message
4133 @item cachedir
4134 @samp{%s: contains a cache directory tag %s; %s}
4135 @kwindex file-shrank
4136 @cindex @samp{File shrank by %s bytes}, warning message
4137 @item file-shrank
4138 @samp{%s: File shrank by %s bytes; padding with zeros}
4139 @kwindex xdev
4140 @cindex @samp{file is on a different filesystem}, warning message
4141 @item xdev
4142 @samp{%s: file is on a different filesystem; not dumped}
4143 @kwindex file-ignored
4144 @cindex @samp{Unknown file type; file ignored}, warning message
4145 @cindex @samp{socket ignored}, warning message
4146 @cindex @samp{door ignored}, warning message
4147 @item file-ignored
4148 @samp{%s: Unknown file type; file ignored}
4149 @*@samp{%s: socket ignored}
4150 @*@samp{%s: door ignored}
4151 @kwindex file-unchanged
4152 @cindex @samp{file is unchanged; not dumped}, warning message
4153 @item file-unchanged
4154 @samp{%s: file is unchanged; not dumped}
4155 @kwindex ignore-archive
4156 @cindex @samp{file is the archive; not dumped}, warning message
4157 @kwindex ignore-archive
4158 @cindex @samp{file is the archive; not dumped}, warning message
4159 @item ignore-archive
4160 @samp{%s: file is the archive; not dumped}
4161 @kwindex file-removed
4162 @cindex @samp{File removed before we read it}, warning message
4163 @item file-removed
4164 @samp{%s: File removed before we read it}
4165 @kwindex file-changed
4166 @cindex @samp{file changed as we read it}, warning message
4167 @item file-changed
4168 @samp{%s: file changed as we read it}
4169 @end table
4170
4171 @subheading Keywords applicable for @command{tar --extract}
4172 @table @asis
4173 @kwindex timestamp
4174 @cindex @samp{implausibly old time stamp %s}, warning message
4175 @cindex @samp{time stamp %s is %s s in the future}, warning message
4176 @item timestamp
4177 @samp{%s: implausibly old time stamp %s}
4178 @*@samp{%s: time stamp %s is %s s in the future}
4179 @kwindex contiguous-cast
4180 @cindex @samp{Extracting contiguous files as regular files}, warning message
4181 @item contiguous-cast
4182 @samp{Extracting contiguous files as regular files}
4183 @kwindex symlink-cast
4184 @cindex @samp{Attempting extraction of symbolic links as hard links}, warning message
4185 @item symlink-cast
4186 @samp{Attempting extraction of symbolic links as hard links}
4187 @kwindex unknown-cast
4188 @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
4189 @item unknown-cast
4190 @samp{%s: Unknown file type '%c', extracted as normal file}
4191 @kwindex ignore-newer
4192 @cindex @samp{Current %s is newer or same age}, warning message
4193 @item ignore-newer
4194 @samp{Current %s is newer or same age}
4195 @kwindex unknown-keyword
4196 @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
4197 @item unknown-keyword
4198 @samp{Ignoring unknown extended header keyword '%s'}
4199 @kwindex decompress-program
4200 @item decompress-program
4201 Controls verbose description of failures occurring when trying to run
4202 alternative decompressor programs (@pxref{alternative decompression
4203 programs}). This warning is disabled by default (unless
4204 @option{--verbose} is used). A common example of what you can get
4205 when using this warning is:
4206
4207 @smallexample
4208 $ @kbd{tar --warning=decompress-program -x -f archive.Z}
4209 tar (child): cannot run compress: No such file or directory
4210 tar (child): trying gzip
4211 @end smallexample
4212
4213 This means that @command{tar} first tried to decompress
4214 @file{archive.Z} using @command{compress}, and, when that
4215 failed, switched to @command{gzip}.
4216 @end table
4217
4218 @subheading Keywords controlling incremental extraction:
4219 @table @asis
4220 @kwindex rename-directory
4221 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4222 @cindex @samp{%s: Directory has been renamed}, warning message
4223 @item rename-directory
4224 @samp{%s: Directory has been renamed from %s}
4225 @*@samp{%s: Directory has been renamed}
4226 @kwindex new-directory
4227 @cindex @samp{%s: Directory is new}, warning message
4228 @item new-directory
4229 @samp{%s: Directory is new}
4230 @kwindex xdev
4231 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4232 @item xdev
4233 @samp{%s: directory is on a different device: not purging}
4234 @kwindex bad-dumpdir
4235 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4236 @item bad-dumpdir
4237 @samp{Malformed dumpdir: 'X' never used}
4238 @end table
4239
4240 @node interactive
4241 @section Asking for Confirmation During Operations
4242 @cindex Interactive operation
4243
4244 Typically, @command{tar} carries out a command without stopping for
4245 further instructions. In some situations however, you may want to
4246 exclude some files and archive members from the operation (for instance
4247 if disk or storage space is tight). You can do this by excluding
4248 certain files automatically (@pxref{Choosing}), or by performing
4249 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4250 @command{tar} also accepts @option{--confirmation} for this option.
4251
4252 @opindex interactive
4253 When the @option{--interactive} (@option{-w}) option is specified, before
4254 reading, writing, or deleting files, @command{tar} first prints a message
4255 for each such file, telling what operation it intends to take, then asks
4256 for confirmation on the terminal. The actions which require
4257 confirmation include adding a file to the archive, extracting a file
4258 from the archive, deleting a file from the archive, and deleting a file
4259 from disk. To confirm the action, you must type a line of input
4260 beginning with @samp{y}. If your input line begins with anything other
4261 than @samp{y}, @command{tar} skips that file.
4262
4263 If @command{tar} is reading the archive from the standard input,
4264 @command{tar} opens the file @file{/dev/tty} to support the interactive
4265 communications.
4266
4267 Verbose output is normally sent to standard output, separate from
4268 other error messages. However, if the archive is produced directly
4269 on standard output, then verbose output is mixed with errors on
4270 @code{stderr}. Producing the archive on standard output may be used
4271 as a way to avoid using disk space, when the archive is soon to be
4272 consumed by another process reading it, say. Some people felt the need
4273 of producing an archive on stdout, still willing to segregate between
4274 verbose output and error output. A possible approach would be using a
4275 named pipe to receive the archive, and having the consumer process to
4276 read from that named pipe. This has the advantage of letting standard
4277 output free to receive verbose output, all separate from errors.
4278
4279 @node external
4280 @section Running External Commands
4281
4282 Certain @GNUTAR{} operations imply running external commands that you
4283 supply on the command line. One of such operations is checkpointing,
4284 described above (@pxref{checkpoint exec}). Another example of this
4285 feature is the @option{-I} option, which allows you to supply the
4286 program to use for compressing or decompressing the archive
4287 (@pxref{use-compress-program}).
4288
4289 Whenever such operation is requested, @command{tar} first splits the
4290 supplied command into words much like the shell does. It then treats
4291 the first word as the name of the program or the shell script to execute
4292 and the rest of words as its command line arguments. The program,
4293 unless given as an absolute file name, is searched in the shell's
4294 @env{PATH}.
4295
4296 Any additional information is normally supplied to external commands
4297 in environment variables, specific to each particular operation. For
4298 example, the @option{--checkpoint-action=exec} option, defines the
4299 @env{TAR_ARCHIVE} variable to the name of the archive being worked
4300 upon. You can, should the need be, use these variables in the
4301 command line of the external command. For example:
4302
4303 @smallexample
4304 $ @kbd{tar -x -f archive.tar \
4305 --checkpoint=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'}
4306 @end smallexample
4307
4308 @noindent
4309 This command prints for each checkpoint its number and the name of the
4310 archive, using the same output line on the screen.
4311
4312 Notice the use of single quotes to prevent variable names from being
4313 expanded by the shell when invoking @command{tar}.
4314
4315 @node operations
4316 @chapter @GNUTAR{} Operations
4317
4318 @menu
4319 * Basic tar::
4320 * Advanced tar::
4321 * create options::
4322 * extract options::
4323 * backup::
4324 * Applications::
4325 * looking ahead::
4326 @end menu
4327
4328 @node Basic tar
4329 @section Basic @GNUTAR{} Operations
4330
4331 The basic @command{tar} operations, @option{--create} (@option{-c}),
4332 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4333 @option{-x}), are currently presented and described in the tutorial
4334 chapter of this manual. This section provides some complementary notes
4335 for these operations.
4336
4337 @table @option
4338 @xopindex{create, complementary notes}
4339 @item --create
4340 @itemx -c
4341
4342 Creating an empty archive would have some kind of elegance. One can
4343 initialize an empty archive and later use @option{--append}
4344 (@option{-r}) for adding all members. Some applications would not
4345 welcome making an exception in the way of adding the first archive
4346 member. On the other hand, many people reported that it is
4347 dangerously too easy for @command{tar} to destroy a magnetic tape with
4348 an empty archive@footnote{This is well described in @cite{Unix-haters
4349 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4350 Books, ISBN 1-56884-203-1.}. The two most common errors are:
4351
4352 @enumerate
4353 @item
4354 Mistakingly using @code{create} instead of @code{extract}, when the
4355 intent was to extract the full contents of an archive. This error
4356 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4357 the QWERTY keyboard. Instead of being unpacked, the archive then
4358 gets wholly destroyed. When users speak about @dfn{exploding} an
4359 archive, they usually mean something else :-).
4360
4361 @item
4362 Forgetting the argument to @code{file}, when the intent was to create
4363 an archive with a single file in it. This error is likely because a
4364 tired user can easily add the @kbd{f} key to the cluster of option
4365 letters, by the mere force of habit, without realizing the full
4366 consequence of doing so. The usual consequence is that the single
4367 file, which was meant to be saved, is rather destroyed.
4368 @end enumerate
4369
4370 So, recognizing the likelihood and the catastrophic nature of these
4371 errors, @GNUTAR{} now takes some distance from elegance, and
4372 cowardly refuses to create an archive when @option{--create} option is
4373 given, there are no arguments besides options, and
4374 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
4375 around the cautiousness of @GNUTAR{} and nevertheless create an
4376 archive with nothing in it, one may still use, as the value for the
4377 @option{--files-from} option, a file with no names in it, as shown in
4378 the following commands:
4379
4380 @smallexample
4381 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4382 @kbd{tar -cf empty-archive.tar -T /dev/null}
4383 @end smallexample
4384
4385 @xopindex{extract, complementary notes}
4386 @item --extract
4387 @itemx --get
4388 @itemx -x
4389
4390 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4391
4392 @item @option{--list} (@option{-t})
4393
4394 @GNUTAR{} now shows dates as @samp{1996-08-30},
4395 while it used to show them as @samp{Aug 30 1996}. Preferably,
4396 people should get used to ISO 8601 dates. Local American dates should
4397 be made available again with full date localization support, once
4398 ready. In the meantime, programs not being localizable for dates
4399 should prefer international dates, that's really the way to go.
4400
4401 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4402 are curious, it contains a detailed explanation of the ISO 8601 standard.
4403
4404 @end table
4405
4406 @node Advanced tar
4407 @section Advanced @GNUTAR{} Operations
4408
4409 Now that you have learned the basics of using @GNUTAR{}, you may want
4410 to learn about further ways in which @command{tar} can help you.
4411
4412 This chapter presents five, more advanced operations which you probably
4413 won't use on a daily basis, but which serve more specialized functions.
4414 We also explain the different styles of options and why you might want
4415 to use one or another, or a combination of them in your @command{tar}
4416 commands. Additionally, this chapter includes options which allow you to
4417 define the output from @command{tar} more carefully, and provide help and
4418 error correction in special circumstances.
4419
4420 @FIXME{check this after the chapter is actually revised to make sure
4421 it still introduces the info in the chapter correctly : ).}
4422
4423 @menu
4424 * Operations::
4425 * append::
4426 * update::
4427 * concatenate::
4428 * delete::
4429 * compare::
4430 @end menu
4431
4432 @node Operations
4433 @subsection The Five Advanced @command{tar} Operations
4434
4435 @cindex basic operations
4436 In the last chapter, you learned about the first three operations to
4437 @command{tar}. This chapter presents the remaining five operations to
4438 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4439 @option{--delete}, and @option{--compare}.
4440
4441 You are not likely to use these operations as frequently as those
4442 covered in the last chapter; however, since they perform specialized
4443 functions, they are quite useful when you do need to use them. We
4444 will give examples using the same directory and files that you created
4445 in the last chapter. As you may recall, the directory is called
4446 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4447 and the two archive files you created are
4448 @samp{collection.tar} and @samp{music.tar}.
4449
4450 We will also use the archive files @samp{afiles.tar} and
4451 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
4452 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4453 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4454
4455 Unless we state otherwise, all practicing you do and examples you follow
4456 in this chapter will take place in the @file{practice} directory that
4457 you created in the previous chapter; see @ref{prepare for examples}.
4458 (Below in this section, we will remind you of the state of the examples
4459 where the last chapter left them.)
4460
4461 The five operations that we will cover in this chapter are:
4462
4463 @table @option
4464 @item --append
4465 @itemx -r
4466 Add new entries to an archive that already exists.
4467 @item --update
4468 @itemx -u
4469 Add more recent copies of archive members to the end of an archive, if
4470 they exist.
4471 @item --concatenate
4472 @itemx --catenate
4473 @itemx -A
4474 Add one or more pre-existing archives to the end of another archive.
4475 @item --delete
4476 Delete items from an archive (does not work on tapes).
4477 @item --compare
4478 @itemx --diff
4479 @itemx -d
4480 Compare archive members to their counterparts in the file system.
4481 @end table
4482
4483 @node append
4484 @subsection How to Add Files to Existing Archives: @option{--append}
4485
4486 @cindex appending files to existing archive
4487 @opindex append
4488 If you want to add files to an existing archive, you don't need to
4489 create a new archive; you can use @option{--append} (@option{-r}).
4490 The archive must already exist in order to use @option{--append}. (A
4491 related operation is the @option{--update} operation; you can use this
4492 to add newer versions of archive members to an existing archive. To learn how to
4493 do this with @option{--update}, @pxref{update}.)
4494
4495 If you use @option{--append} to add a file that has the same name as an
4496 archive member to an archive containing that archive member, then the
4497 old member is not deleted. What does happen, however, is somewhat
4498 complex. @command{tar} @emph{allows} you to have infinite number of files
4499 with the same name. Some operations treat these same-named members no
4500 differently than any other set of archive members: for example, if you
4501 view an archive with @option{--list} (@option{-t}), you will see all
4502 of those members listed, with their data modification times, owners, etc.
4503
4504 Other operations don't deal with these members as perfectly as you might
4505 prefer; if you were to use @option{--extract} to extract the archive,
4506 only the most recently added copy of a member with the same name as
4507 other members would end up in the working directory. This is because
4508 @option{--extract} extracts an archive in the order the members appeared
4509 in the archive; the most recently archived members will be extracted
4510 last. Additionally, an extracted member will @emph{replace} a file of
4511 the same name which existed in the directory already, and @command{tar}
4512 will not prompt you about this@footnote{Unless you give it
4513 @option{--keep-old-files} (or @option{--skip-old-files}) option, or
4514 the disk copy is newer than the one in the archive and you invoke
4515 @command{tar} with @option{--keep-newer-files} option.}. Thus, only
4516 the most recently archived member will end up being extracted, as it
4517 will replace the one extracted before it, and so on.
4518
4519 @cindex extracting @var{n}th copy of the file
4520 @xopindex{occurrence, described}
4521 There exists a special option that allows you to get around this
4522 behavior and extract (or list) only a particular copy of the file.
4523 This is @option{--occurrence} option. If you run @command{tar} with
4524 this option, it will extract only the first copy of the file. You
4525 may also give this option an argument specifying the number of
4526 copy to be extracted. Thus, for example if the archive
4527 @file{archive.tar} contained three copies of file @file{myfile}, then
4528 the command
4529
4530 @smallexample
4531 tar --extract --file archive.tar --occurrence=2 myfile
4532 @end smallexample
4533
4534 @noindent
4535 would extract only the second copy. @xref{Option
4536 Summary,---occurrence}, for the description of @option{--occurrence}
4537 option.
4538
4539 @FIXME{ hag -- you might want to incorporate some of the above into the
4540 MMwtSN node; not sure. i didn't know how to make it simpler...
4541
4542 There are a few ways to get around this. Xref to Multiple Members
4543 with the Same Name, maybe.}
4544
4545 @cindex Members, replacing with other members
4546 @cindex Replacing members with other members
4547 @xopindex{delete, using before --append}
4548 If you want to replace an archive member, use @option{--delete} to
4549 delete the member you want to remove from the archive, and then use
4550 @option{--append} to add the member you want to be in the archive. Note
4551 that you can not change the order of the archive; the most recently
4552 added member will still appear last. In this sense, you cannot truly
4553 ``replace'' one member with another. (Replacing one member with another
4554 will not work on certain types of media, such as tapes; see @ref{delete}
4555 and @ref{Media}, for more information.)
4556
4557 @menu
4558 * appending files:: Appending Files to an Archive
4559 * multiple::
4560 @end menu
4561
4562 @node appending files
4563 @subsubsection Appending Files to an Archive
4564 @cindex Adding files to an Archive
4565 @cindex Appending files to an Archive
4566 @cindex Archives, Appending files to
4567 @opindex append
4568
4569 The simplest way to add a file to an already existing archive is the
4570 @option{--append} (@option{-r}) operation, which writes specified
4571 files into the archive whether or not they are already among the
4572 archived files.
4573
4574 When you use @option{--append}, you @emph{must} specify file name
4575 arguments, as there is no default. If you specify a file that already
4576 exists in the archive, another copy of the file will be added to the
4577 end of the archive. As with other operations, the member names of the
4578 newly added files will be exactly the same as their names given on the
4579 command line. The @option{--verbose} (@option{-v}) option will print
4580 out the names of the files as they are written into the archive.
4581
4582 @option{--append} cannot be performed on some tape drives, unfortunately,
4583 due to deficiencies in the formats those tape drives use. The archive
4584 must be a valid @command{tar} archive, or else the results of using this
4585 operation will be unpredictable. @xref{Media}.
4586
4587 To demonstrate using @option{--append} to add a file to an archive,
4588 create a file called @file{rock} in the @file{practice} directory.
4589 Make sure you are in the @file{practice} directory. Then, run the
4590 following @command{tar} command to add @file{rock} to
4591 @file{collection.tar}:
4592
4593 @smallexample
4594 $ @kbd{tar --append --file=collection.tar rock}
4595 @end smallexample
4596
4597 @noindent
4598 If you now use the @option{--list} (@option{-t}) operation, you will see that
4599 @file{rock} has been added to the archive:
4600
4601 @smallexample
4602 $ @kbd{tar --list --file=collection.tar}
4603 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
4604 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
4605 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
4606 -rw-r--r-- me/user 20 1996-09-23 16:44 rock
4607 @end smallexample
4608
4609 @node multiple
4610 @subsubsection Multiple Members with the Same Name
4611 @cindex members, multiple
4612 @cindex multiple members
4613
4614 You can use @option{--append} (@option{-r}) to add copies of files
4615 which have been updated since the archive was created. (However, we
4616 do not recommend doing this since there is another @command{tar}
4617 option called @option{--update}; @xref{update}, for more information.
4618 We describe this use of @option{--append} here for the sake of
4619 completeness.) When you extract the archive, the older version will
4620 be effectively lost. This works because files are extracted from an
4621 archive in the order in which they were archived. Thus, when the
4622 archive is extracted, a file archived later in time will replace a
4623 file of the same name which was archived earlier, even though the
4624 older version of the file will remain in the archive unless you delete
4625 all versions of the file.
4626
4627 Supposing you change the file @file{blues} and then append the changed
4628 version to @file{collection.tar}. As you saw above, the original
4629 @file{blues} is in the archive @file{collection.tar}. If you change the
4630 file and append the new version of the file to the archive, there will
4631 be two copies in the archive. When you extract the archive, the older
4632 version of the file will be extracted first, and then replaced by the
4633 newer version when it is extracted.
4634
4635 You can append the new, changed copy of the file @file{blues} to the
4636 archive in this way:
4637
4638 @smallexample
4639 $ @kbd{tar --append --verbose --file=collection.tar blues}
4640 blues
4641 @end smallexample
4642
4643 @noindent
4644 Because you specified the @option{--verbose} option, @command{tar} has
4645 printed the name of the file being appended as it was acted on. Now
4646 list the contents of the archive:
4647
4648 @smallexample
4649 $ @kbd{tar --list --verbose --file=collection.tar}
4650 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
4651 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
4652 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
4653 -rw-r--r-- me/user 20 1996-09-23 16:44 rock
4654 -rw-r--r-- me/user 58 1996-10-24 18:30 blues
4655 @end smallexample
4656
4657 @noindent
4658 The newest version of @file{blues} is now at the end of the archive
4659 (note the different creation dates and file sizes). If you extract
4660 the archive, the older version of the file @file{blues} will be
4661 replaced by the newer version. You can confirm this by extracting
4662 the archive and running @samp{ls} on the directory.
4663
4664 If you wish to extract the first occurrence of the file @file{blues}
4665 from the archive, use @option{--occurrence} option, as shown in
4666 the following example:
4667
4668 @smallexample
4669 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4670 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
4671 @end smallexample
4672
4673 @xref{Writing}, for more information on @option{--extract} and
4674 see @ref{Option Summary, --occurrence}, for a description of
4675 @option{--occurrence} option.
4676
4677 @node update
4678 @subsection Updating an Archive
4679 @cindex Updating an archive
4680 @opindex update
4681
4682 In the previous section, you learned how to use @option{--append} to
4683 add a file to an existing archive. A related operation is
4684 @option{--update} (@option{-u}). The @option{--update} operation
4685 updates a @command{tar} archive by comparing the date of the specified
4686 archive members against the date of the file with the same name. If
4687 the file has been modified more recently than the archive member, then
4688 the newer version of the file is added to the archive (as with
4689 @option{--append}).
4690
4691 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4692 The operation will fail.
4693
4694 @FIXME{other examples of media on which --update will fail? need to ask
4695 charles and/or mib/thomas/dave shevett..}
4696
4697 Both @option{--update} and @option{--append} work by adding to the end
4698 of the archive. When you extract a file from the archive, only the
4699 version stored last will wind up in the file system, unless you use
4700 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4701
4702 @menu
4703 * how to update::
4704 @end menu
4705
4706 @node how to update
4707 @subsubsection How to Update an Archive Using @option{--update}
4708 @opindex update
4709
4710 You must use file name arguments with the @option{--update}
4711 (@option{-u}) operation. If you don't specify any files,
4712 @command{tar} won't act on any files and won't tell you that it didn't
4713 do anything (which may end up confusing you).
4714
4715 @c note: the above parenthetical added because in fact, this
4716 @c behavior just confused the author. :-)
4717
4718 To see the @option{--update} option at work, create a new file,
4719 @file{classical}, in your practice directory, and some extra text to the
4720 file @file{blues}, using any text editor. Then invoke @command{tar} with
4721 the @samp{update} operation and the @option{--verbose} (@option{-v})
4722 option specified, using the names of all the files in the @file{practice}
4723 directory as file name arguments:
4724
4725 @smallexample
4726 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4727 blues
4728 classical
4729 $
4730 @end smallexample
4731
4732 @noindent
4733 Because we have specified verbose mode, @command{tar} prints out the names
4734 of the files it is working on, which in this case are the names of the
4735 files that needed to be updated. If you run @samp{tar --list} and look
4736 at the archive, you will see @file{blues} and @file{classical} at its
4737 end. There will be a total of two versions of the member @samp{blues};
4738 the one at the end will be newer and larger, since you added text before
4739 updating it.
4740
4741 The reason @command{tar} does not overwrite the older file when updating
4742 it is because writing to the middle of a section of tape is a difficult
4743 process. Tapes are not designed to go backward. @xref{Media}, for more
4744 information about tapes.
4745
4746 @option{--update} (@option{-u}) is not suitable for performing backups for two
4747 reasons: it does not change directory content entries, and it
4748 lengthens the archive every time it is used. The @GNUTAR{}
4749 options intended specifically for backups are more
4750 efficient. If you need to run backups, please consult @ref{Backups}.
4751
4752 @node concatenate
4753 @subsection Combining Archives with @option{--concatenate}
4754
4755 @cindex Adding archives to an archive
4756 @cindex Concatenating Archives
4757 @opindex concatenate
4758 @opindex catenate
4759 @c @cindex @option{-A} described
4760 Sometimes it may be convenient to add a second archive onto the end of
4761 an archive rather than adding individual files to the archive. To add
4762 one or more archives to the end of another archive, you should use the
4763 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4764
4765 To use @option{--concatenate}, give the first archive with
4766 @option{--file} option and name the rest of archives to be
4767 concatenated on the command line. The members, and their member
4768 names, will be copied verbatim from those archives to the first
4769 one@footnote{This can cause multiple members to have the same name. For
4770 information on how this affects reading the archive, see @ref{multiple}.}.
4771 The new, concatenated archive will be called by the same name as the
4772 one given with the @option{--file} option. As usual, if you omit
4773 @option{--file}, @command{tar} will use the value of the environment
4774 variable @env{TAPE}, or, if this has not been set, the default archive name.
4775
4776 @FIXME{There is no way to specify a new name...}
4777
4778 To demonstrate how @option{--concatenate} works, create two small archives
4779 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4780 files from @file{practice}:
4781
4782 @smallexample
4783 $ @kbd{tar -cvf bluesrock.tar blues rock}
4784 blues
4785 rock
4786 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4787 folk
4788 jazz
4789 @end smallexample
4790
4791 @noindent
4792 If you like, You can run @samp{tar --list} to make sure the archives
4793 contain what they are supposed to:
4794
4795 @smallexample
4796 $ @kbd{tar -tvf bluesrock.tar}
4797 -rw-r--r-- melissa/user 105 1997-01-21 19:42 blues
4798 -rw-r--r-- melissa/user 33 1997-01-20 15:34 rock
4799 $ @kbd{tar -tvf jazzfolk.tar}
4800 -rw-r--r-- melissa/user 20 1996-09-23 16:44 folk
4801 -rw-r--r-- melissa/user 65 1997-01-30 14:15 jazz
4802 @end smallexample
4803
4804 We can concatenate these two archives with @command{tar}:
4805
4806 @smallexample
4807 $ @kbd{cd ..}
4808 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4809 @end smallexample
4810
4811 If you now list the contents of the @file{bluesrock.tar}, you will see
4812 that now it also contains the archive members of @file{jazzfolk.tar}:
4813
4814 @smallexample
4815 $ @kbd{tar --list --file=bluesrock.tar}
4816 blues
4817 rock
4818 folk
4819 jazz
4820 @end smallexample
4821
4822 When you use @option{--concatenate}, the source and target archives must
4823 already exist and must have been created using compatible format
4824 parameters. Notice, that @command{tar} does not check whether the
4825 archives it concatenates have compatible formats, it does not
4826 even check if the files are really tar archives.
4827
4828 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4829 tape drives, due to deficiencies in the formats those tape drives use.
4830
4831 @cindex @code{concatenate} vs @command{cat}
4832 @cindex @command{cat} vs @code{concatenate}
4833 It may seem more intuitive to you to want or try to use @command{cat} to
4834 concatenate two archives instead of using the @option{--concatenate}
4835 operation; after all, @command{cat} is the utility for combining files.
4836
4837 However, @command{tar} archives incorporate an end-of-file marker which
4838 must be removed if the concatenated archives are to be read properly as
4839 one archive. @option{--concatenate} removes the end-of-archive marker
4840 from the target archive before each new archive is appended. If you use
4841 @command{cat} to combine the archives, the result will not be a valid
4842 @command{tar} format archive. If you need to retrieve files from an
4843 archive that was added to using the @command{cat} utility, use the
4844 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4845 information on dealing with archives improperly combined using the
4846 @command{cat} shell utility.
4847
4848 @node delete
4849 @subsection Removing Archive Members Using @option{--delete}
4850 @cindex Deleting files from an archive
4851 @cindex Removing files from an archive
4852
4853 @opindex delete
4854 You can remove members from an archive by using the @option{--delete}
4855 option. Specify the name of the archive with @option{--file}
4856 (@option{-f}) and then specify the names of the members to be deleted;
4857 if you list no member names, nothing will be deleted. The
4858 @option{--verbose} option will cause @command{tar} to print the names
4859 of the members as they are deleted. As with @option{--extract}, you
4860 must give the exact member names when using @samp{tar --delete}.
4861 @option{--delete} will remove all versions of the named file from the
4862 archive. The @option{--delete} operation can run very slowly.
4863
4864 Unlike other operations, @option{--delete} has no short form.
4865
4866 @cindex Tapes, using @option{--delete} and
4867 @cindex Deleting from tape archives
4868 This operation will rewrite the archive. You can only use
4869 @option{--delete} on an archive if the archive device allows you to
4870 write to any point on the media, such as a disk; because of this, it
4871 does not work on magnetic tapes. Do not try to delete an archive member
4872 from a magnetic tape; the action will not succeed, and you will be
4873 likely to scramble the archive and damage your tape. There is no safe
4874 way (except by completely re-writing the archive) to delete files from
4875 most kinds of magnetic tape. @xref{Media}.
4876
4877 To delete all versions of the file @file{blues} from the archive
4878 @file{collection.tar} in the @file{practice} directory, make sure you
4879 are in that directory, and then,
4880
4881 @smallexample
4882 $ @kbd{tar --list --file=collection.tar}
4883 blues
4884 folk
4885 jazz
4886 rock
4887 $ @kbd{tar --delete --file=collection.tar blues}
4888 $ @kbd{tar --list --file=collection.tar}
4889 folk
4890 jazz
4891 rock
4892 @end smallexample
4893
4894 @FIXME{Check if the above listing is actually produced after running
4895 all the examples on collection.tar.}
4896
4897 The @option{--delete} option has been reported to work properly when
4898 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4899
4900 @node compare
4901 @subsection Comparing Archive Members with the File System
4902 @cindex Verifying the currency of an archive
4903
4904 @opindex compare
4905 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4906 specified archive members against files with the same names, and then
4907 reports differences in file size, mode, owner, modification date and
4908 contents. You should @emph{only} specify archive member names, not file
4909 names. If you do not name any members, then @command{tar} will compare the
4910 entire archive. If a file is represented in the archive but does not
4911 exist in the file system, @command{tar} reports a difference.
4912
4913 You have to specify the record size of the archive when modifying an
4914 archive with a non-default record size.
4915
4916 @command{tar} ignores files in the file system that do not have
4917 corresponding members in the archive.
4918
4919 The following example compares the archive members @file{rock},
4920 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4921 files of the same name in the file system. (Note that there is no file,
4922 @file{funk}; @command{tar} will report an error message.)
4923
4924 @smallexample
4925 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4926 rock
4927 blues
4928 tar: funk not found in archive
4929 @end smallexample
4930
4931 The spirit behind the @option{--compare} (@option{--diff},
4932 @option{-d}) option is to check whether the archive represents the
4933 current state of files on disk, more than validating the integrity of
4934 the archive media. For this latter goal, see @ref{verify}.
4935
4936 @node create options
4937 @section Options Used by @option{--create}
4938
4939 @xopindex{create, additional options}
4940 The previous chapter described the basics of how to use
4941 @option{--create} (@option{-c}) to create an archive from a set of files.
4942 @xref{create}. This section described advanced options to be used with
4943 @option{--create}.
4944
4945 @menu
4946 * override:: Overriding File Metadata.
4947 * Ignore Failed Read::
4948 @end menu
4949
4950 @node override
4951 @subsection Overriding File Metadata
4952
4953 As described above, a @command{tar} archive keeps, for each member it contains,
4954 its @dfn{metadata}, such as modification time, mode and ownership of
4955 the file. @GNUTAR{} allows to replace these data with other values
4956 when adding files to the archive. The options described in this
4957 section affect creation of archives of any type. For POSIX archives,
4958 see also @ref{PAX keywords}, for additional ways of controlling
4959 metadata, stored in the archive.
4960
4961 @table @option
4962 @opindex mode
4963 @item --mode=@var{permissions}
4964
4965 When adding files to an archive, @command{tar} will use
4966 @var{permissions} for the archive members, rather than the permissions
4967 from the files. @var{permissions} can be specified either as an octal
4968 number or as symbolic permissions, like with
4969 @command{chmod} (@xref{File permissions, Permissions, File
4970 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4971 also has useful information for those not being overly familiar with
4972 the UNIX permission system). Using latter syntax allows for
4973 more flexibility. For example, the value @samp{a+rw} adds read and write
4974 permissions for everybody, while retaining executable bits on directories
4975 or on any other file already marked as executable:
4976
4977 @smallexample
4978 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4979 @end smallexample
4980
4981 @item --mtime=@var{date}
4982 @opindex mtime
4983
4984 When adding files to an archive, @command{tar} will use @var{date} as
4985 the modification time of members when creating archives, instead of
4986 their actual modification times. The argument @var{date} can be
4987 either a textual date representation in almost arbitrary format
4988 (@pxref{Date input formats}) or a name of an existing file, starting
4989 with @samp{/} or @samp{.}. In the latter case, the modification time
4990 of that file will be used.
4991
4992 The following example will set the modification date to 00:00:00,
4993 January 1, 1970:
4994
4995 @smallexample
4996 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4997 @end smallexample
4998
4999 @noindent
5000 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
5001 will try to convert the specified date back to its textual
5002 representation and compare it with the one given with
5003 @option{--mtime} options. If the two dates differ, @command{tar} will
5004 print a warning saying what date it will use. This is to help user
5005 ensure he is using the right date.
5006
5007 For example:
5008
5009 @smallexample
5010 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
5011 tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
5012 13:06:29.152478
5013 @dots{}
5014 @end smallexample
5015
5016 @item --owner=@var{user}
5017 @opindex owner
5018
5019 Specifies that @command{tar} should use @var{user} as the owner of members
5020 when creating archives, instead of the user associated with the source
5021 file.
5022
5023 If @var{user} contains a colon, it is taken to be of the form
5024 @var{name}:@var{id} where a nonempty @var{name} specifies the user
5025 name and a nonempty @var{id} specifies the decimal numeric user
5026 @acronym{ID}. If @var{user} does not contain a colon, it is taken to
5027 be a user number if it is one or more decimal digits; otherwise it is
5028 taken to be a user name.
5029
5030 If a name is given but no number, the number is inferred from the
5031 current host's user database if possible, and the file's user number
5032 is used otherwise. If a number is given but no name, the name is
5033 inferred from the number if possible, and an empty name is used
5034 otherwise. If both name and number are given, the user database is
5035 not consulted, and the name and number need not be valid on the
5036 current host.
5037
5038 There is no value indicating a missing number, and @samp{0} usually means
5039 @code{root}. Some people like to force @samp{0} as the value to offer in
5040 their distributions for the owner of files, because the @code{root} user is
5041 anonymous anyway, so that might as well be the owner of anonymous
5042 archives. For example:
5043
5044 @smallexample
5045 $ @kbd{tar -c -f archive.tar --owner=0 .}
5046 @end smallexample
5047
5048 @noindent
5049 or:
5050
5051 @smallexample
5052 $ @kbd{tar -c -f archive.tar --owner=root .}
5053 @end smallexample
5054
5055 @item --group=@var{group}
5056 @opindex group
5057
5058 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
5059 rather than the group from the source file. As with @option{--owner},
5060 the argument @var{group} can be an existing group symbolic name, or a
5061 decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
5062 @end table
5063
5064 @node Ignore Failed Read
5065 @subsection Ignore Fail Read
5066
5067 @table @option
5068 @item --ignore-failed-read
5069 @opindex ignore-failed-read
5070 Do not exit with nonzero on unreadable files or directories.
5071 @end table
5072
5073 @node extract options
5074 @section Options Used by @option{--extract}
5075 @cindex options for use with @option{--extract}
5076
5077 @xopindex{extract, additional options}
5078 The previous chapter showed how to use @option{--extract} to extract
5079 an archive into the file system. Various options cause @command{tar} to
5080 extract more information than just file contents, such as the owner,
5081 the permissions, the modification date, and so forth. This section
5082 presents options to be used with @option{--extract} when certain special
5083 considerations arise. You may review the information presented in
5084 @ref{extract} for more basic information about the
5085 @option{--extract} operation.
5086
5087 @menu
5088 * Reading:: Options to Help Read Archives
5089 * Writing:: Changing How @command{tar} Writes Files
5090 * Scarce:: Coping with Scarce Resources
5091 @end menu
5092
5093 @node Reading
5094 @subsection Options to Help Read Archives
5095 @cindex Options when reading archives
5096
5097 @cindex Reading incomplete records
5098 @cindex Records, incomplete
5099 @opindex read-full-records
5100 Normally, @command{tar} will request data in full record increments from
5101 an archive storage device. If the device cannot return a full record,
5102 @command{tar} will report an error. However, some devices do not always
5103 return full records, or do not require the last record of an archive to
5104 be padded out to the next record boundary. To keep reading until you
5105 obtain a full record, or to accept an incomplete record if it contains
5106 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5107 in conjunction with the @option{--extract} or @option{--list} operations.
5108 @xref{Blocking}.
5109
5110 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5111 @command{tar} reads an archive from standard input, or from a remote
5112 machine. This is because on @acronym{BSD} Unix systems, attempting to read a
5113 pipe returns however much happens to be in the pipe, even if it is
5114 less than was requested. If this option were not enabled, @command{tar}
5115 would fail as soon as it read an incomplete record from the pipe.
5116
5117 If you're not sure of the blocking factor of an archive, you can
5118 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5119 @option{--blocking-factor=@var{512-size}} (@option{-b
5120 @var{512-size}}), using a blocking factor larger than what the archive
5121 uses. This lets you avoid having to determine the blocking factor
5122 of an archive. @xref{Blocking Factor}.
5123
5124 @menu
5125 * read full records::
5126 * Ignore Zeros::
5127 @end menu
5128
5129 @node read full records
5130 @unnumberedsubsubsec Reading Full Records
5131
5132 @FIXME{need sentence or so of intro here}
5133
5134 @table @option
5135 @opindex read-full-records
5136 @item --read-full-records
5137 @item -B
5138 Use in conjunction with @option{--extract} (@option{--get},
5139 @option{-x}) to read an archive which contains incomplete records, or
5140 one which has a blocking factor less than the one specified.
5141 @end table
5142
5143 @node Ignore Zeros
5144 @unnumberedsubsubsec Ignoring Blocks of Zeros
5145
5146 @cindex End-of-archive blocks, ignoring
5147 @cindex Ignoring end-of-archive blocks
5148 @opindex ignore-zeros
5149 Normally, @command{tar} stops reading when it encounters a block of zeros
5150 between file entries (which usually indicates the end of the archive).
5151 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5152 completely read an archive which contains a block of zeros before the
5153 end (i.e., a damaged archive, or one that was created by concatenating
5154 several archives together).
5155
5156 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
5157 versions of @command{tar} write garbage after the end-of-archive entry,
5158 since that part of the media is never supposed to be read. @GNUTAR{}
5159 does not write after the end of an archive, but seeks to
5160 maintain compatibility among archiving utilities.
5161
5162 @table @option
5163 @item --ignore-zeros
5164 @itemx -i
5165 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
5166 encountered while reading an archive. Use in conjunction with
5167 @option{--extract} or @option{--list}.
5168 @end table
5169
5170 @node Writing
5171 @subsection Changing How @command{tar} Writes Files
5172 @UNREVISED
5173
5174 @FIXME{Introductory paragraph}
5175
5176 @menu
5177 * Dealing with Old Files::
5178 * Overwrite Old Files::
5179 * Keep Old Files::
5180 * Keep Newer Files::
5181 * Unlink First::
5182 * Recursive Unlink::
5183 * Data Modification Times::
5184 * Setting Access Permissions::
5185 * Directory Modification Times and Permissions::
5186 * Writing to Standard Output::
5187 * Writing to an External Program::
5188 * remove files::
5189 @end menu
5190
5191 @node Dealing with Old Files
5192 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
5193
5194 @xopindex{overwrite-dir, introduced}
5195 When extracting files, if @command{tar} discovers that the extracted
5196 file already exists, it normally replaces the file by removing it before
5197 extracting it, to prevent confusion in the presence of hard or symbolic
5198 links. (If the existing file is a symbolic link, it is removed, not
5199 followed.) However, if a directory cannot be removed because it is
5200 nonempty, @command{tar} normally overwrites its metadata (ownership,
5201 permission, etc.). The @option{--overwrite-dir} option enables this
5202 default behavior. To be more cautious and preserve the metadata of
5203 such a directory, use the @option{--no-overwrite-dir} option.
5204
5205 @cindex Overwriting old files, prevention
5206 @xopindex{keep-old-files, introduced}
5207 To be even more cautious and prevent existing files from being replaced, use
5208 the @option{--keep-old-files} (@option{-k}) option. It causes
5209 @command{tar} to refuse to replace or update a file that already
5210 exists, i.e., a file with the same name as an archive member prevents
5211 extraction of that archive member. Instead, it reports an error. For
5212 example:
5213
5214 @example
5215 $ @kbd{ls}
5216 blues
5217 $ @kbd{tar -x -k -f archive.tar}
5218 tar: blues: Cannot open: File exists
5219 tar: Exiting with failure status due to previous errors
5220 @end example
5221
5222 @xopindex{skip-old-files, introduced}
5223 If you wish to preserve old files untouched, but don't want
5224 @command{tar} to treat them as errors, use the
5225 @option{--skip-old-files} option. This option causes @command{tar} to
5226 silently skip extracting over existing files.
5227
5228 @xopindex{overwrite, introduced}
5229 To be more aggressive about altering existing files, use the
5230 @option{--overwrite} option. It causes @command{tar} to overwrite
5231 existing files and to follow existing symbolic links when extracting.
5232
5233 @cindex Protecting old files
5234 Some people argue that @GNUTAR{} should not hesitate
5235 to overwrite files with other files when extracting. When extracting
5236 a @command{tar} archive, they expect to see a faithful copy of the
5237 state of the file system when the archive was created. It is debatable
5238 that this would always be a proper behavior. For example, suppose one
5239 has an archive in which @file{usr/local} is a link to
5240 @file{usr/local2}. Since then, maybe the site removed the link and
5241 renamed the whole hierarchy from @file{/usr/local2} to
5242 @file{/usr/local}. Such things happen all the time. I guess it would
5243 not be welcome at all that @GNUTAR{} removes the
5244 whole hierarchy just to make room for the link to be reinstated
5245 (unless it @emph{also} simultaneously restores the full
5246 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
5247 able to remove a whole hierarchy to reestablish a symbolic link, for
5248 example, but @emph{only if} @option{--recursive-unlink} is specified
5249 to allow this behavior. In any case, single files are silently
5250 removed.
5251
5252 @xopindex{unlink-first, introduced}
5253 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
5254 some cases by causing @command{tar} to remove files unconditionally
5255 before extracting them.
5256
5257 @node Overwrite Old Files
5258 @unnumberedsubsubsec Overwrite Old Files
5259
5260 @table @option
5261 @opindex overwrite
5262 @item --overwrite
5263 Overwrite existing files and directory metadata when extracting files
5264 from an archive.
5265
5266 This causes @command{tar} to write extracted files into the file system without
5267 regard to the files already on the system; i.e., files with the same
5268 names as archive members are overwritten when the archive is extracted.
5269 It also causes @command{tar} to extract the ownership, permissions,
5270 and time stamps onto any preexisting files or directories.
5271 If the name of a corresponding file name is a symbolic link, the file
5272 pointed to by the symbolic link will be overwritten instead of the
5273 symbolic link itself (if this is possible). Moreover, special devices,
5274 empty directories and even symbolic links are automatically removed if
5275 they are in the way of extraction.
5276
5277 Be careful when using the @option{--overwrite} option, particularly when
5278 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
5279 can change the contents, ownership or permissions of any file on your
5280 system. Also, many systems do not take kindly to overwriting files that
5281 are currently being executed.
5282
5283 @opindex overwrite-dir
5284 @item --overwrite-dir
5285 Overwrite the metadata of directories when extracting files from an
5286 archive, but remove other files before extracting.
5287 @end table
5288
5289 @node Keep Old Files
5290 @unnumberedsubsubsec Keep Old Files
5291
5292 @GNUTAR{} provides two options to control its actions in a situation
5293 when it is about to extract a file which already exists on disk.
5294
5295 @table @option
5296 @opindex keep-old-files
5297 @item --keep-old-files
5298 @itemx -k
5299 Do not replace existing files from archive. When such a file is
5300 encountered, @command{tar} issues an error message. Upon end of
5301 extraction, @command{tar} exits with code 2 (@pxref{exit status}).
5302
5303 @item --skip-old-files
5304 Do not replace existing files from archive, but do not treat that
5305 as error. Such files are silently skipped and do not affect
5306 @command{tar} exit status.
5307
5308 Additional verbosity can be obtained using @option{--warning=existing-file}
5309 together with that option (@pxref{warnings}).
5310 @end table
5311
5312 @node Keep Newer Files
5313 @unnumberedsubsubsec Keep Newer Files
5314
5315 @table @option
5316 @opindex keep-newer-files
5317 @item --keep-newer-files
5318 Do not replace existing files that are newer than their archive
5319 copies. This option is meaningless with @option{--list} (@option{-t}).
5320 @end table
5321
5322 @node Unlink First
5323 @unnumberedsubsubsec Unlink First
5324
5325 @table @option
5326 @opindex unlink-first
5327 @item --unlink-first
5328 @itemx -U
5329 Remove files before extracting over them.
5330 This can make @command{tar} run a bit faster if you know in advance
5331 that the extracted files all need to be removed. Normally this option
5332 slows @command{tar} down slightly, so it is disabled by default.
5333 @end table
5334
5335 @node Recursive Unlink
5336 @unnumberedsubsubsec Recursive Unlink
5337
5338 @table @option
5339 @opindex recursive-unlink
5340 @item --recursive-unlink
5341 When this option is specified, try removing files and directory hierarchies
5342 before extracting over them. @emph{This is a dangerous option!}
5343 @end table
5344
5345 If you specify the @option{--recursive-unlink} option,
5346 @command{tar} removes @emph{anything} that keeps you from extracting a file
5347 as far as current permissions will allow it. This could include removal
5348 of the contents of a full directory hierarchy.
5349
5350 @node Data Modification Times
5351 @unnumberedsubsubsec Setting Data Modification Times
5352
5353 @cindex Data modification times of extracted files
5354 @cindex Modification times of extracted files
5355 Normally, @command{tar} sets the data modification times of extracted
5356 files to the corresponding times recorded for the files in the archive, but
5357 limits the permissions of extracted files by the current @code{umask}
5358 setting.
5359
5360 To set the data modification times of extracted files to the time when
5361 the files were extracted, use the @option{--touch} (@option{-m}) option in
5362 conjunction with @option{--extract} (@option{--get}, @option{-x}).
5363
5364 @table @option
5365 @opindex touch
5366 @item --touch
5367 @itemx -m
5368 Sets the data modification time of extracted archive members to the time
5369 they were extracted, not the time recorded for them in the archive.
5370 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
5371 @end table
5372
5373 @node Setting Access Permissions
5374 @unnumberedsubsubsec Setting Access Permissions
5375
5376 @cindex Permissions of extracted files
5377 @cindex Modes of extracted files
5378 To set the modes (access permissions) of extracted files to those
5379 recorded for those files in the archive, use @option{--same-permissions}
5380 in conjunction with the @option{--extract} (@option{--get},
5381 @option{-x}) operation.
5382
5383 @table @option
5384 @opindex preserve-permissions
5385 @opindex same-permissions
5386 @item --preserve-permissions
5387 @itemx --same-permissions
5388 @c @itemx --ignore-umask
5389 @itemx -p
5390 Set modes of extracted archive members to those recorded in the
5391 archive, instead of current umask settings. Use in conjunction with
5392 @option{--extract} (@option{--get}, @option{-x}).
5393 @end table
5394
5395 @node Directory Modification Times and Permissions
5396 @unnumberedsubsubsec Directory Modification Times and Permissions
5397
5398 After successfully extracting a file member, @GNUTAR{} normally
5399 restores its permissions and modification times, as described in the
5400 previous sections. This cannot be done for directories, because
5401 after extracting a directory @command{tar} will almost certainly
5402 extract files into that directory and this will cause the directory
5403 modification time to be updated. Moreover, restoring that directory
5404 permissions may not permit file creation within it. Thus, restoring
5405 directory permissions and modification times must be delayed at least
5406 until all files have been extracted into that directory. @GNUTAR{}
5407 restores directories using the following approach.
5408
5409 The extracted directories are created with the mode specified in the
5410 archive, as modified by the umask of the user, which gives sufficient
5411 permissions to allow file creation. The meta-information about the
5412 directory is recorded in the temporary list of directories. When
5413 preparing to extract next archive member, @GNUTAR{} checks if the
5414 directory prefix of this file contains the remembered directory. If
5415 it does not, the program assumes that all files have been extracted
5416 into that directory, restores its modification time and permissions
5417 and removes its entry from the internal list. This approach allows
5418 to correctly restore directory meta-information in the majority of
5419 cases, while keeping memory requirements sufficiently small. It is
5420 based on the fact, that most @command{tar} archives use the predefined
5421 order of members: first the directory, then all the files and
5422 subdirectories in that directory.
5423
5424 However, this is not always true. The most important exception are
5425 incremental archives (@pxref{Incremental Dumps}). The member order in
5426 an incremental archive is reversed: first all directory members are
5427 stored, followed by other (non-directory) members. So, when extracting
5428 from incremental archives, @GNUTAR{} alters the above procedure. It
5429 remembers all restored directories, and restores their meta-data
5430 only after the entire archive has been processed. Notice, that you do
5431 not need to specify any special options for that, as @GNUTAR{}
5432 automatically detects archives in incremental format.
5433
5434 There may be cases, when such processing is required for normal archives
5435 too. Consider the following example:
5436
5437 @smallexample
5438 @group
5439 $ @kbd{tar --no-recursion -cvf archive \
5440 foo foo/file1 bar bar/file foo/file2}
5441 foo/
5442 foo/file1
5443 bar/
5444 bar/file
5445 foo/file2
5446 @end group
5447 @end smallexample
5448
5449 During the normal operation, after encountering @file{bar}
5450 @GNUTAR{} will assume that all files from the directory @file{foo}
5451 were already extracted and will therefore restore its timestamp and
5452 permission bits. However, after extracting @file{foo/file2} the
5453 directory timestamp will be offset again.
5454
5455 To correctly restore directory meta-information in such cases, use
5456 the @option{--delay-directory-restore} command line option:
5457
5458 @table @option
5459 @opindex delay-directory-restore
5460 @item --delay-directory-restore
5461 Delays restoring of the modification times and permissions of extracted
5462 directories until the end of extraction. This way, correct
5463 meta-information is restored even if the archive has unusual member
5464 ordering.
5465
5466 @opindex no-delay-directory-restore
5467 @item --no-delay-directory-restore
5468 Cancel the effect of the previous @option{--delay-directory-restore}.
5469 Use this option if you have used @option{--delay-directory-restore} in
5470 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
5471 temporarily disable it.
5472 @end table
5473
5474 @node Writing to Standard Output
5475 @unnumberedsubsubsec Writing to Standard Output
5476
5477 @cindex Writing extracted files to standard output
5478 @cindex Standard output, writing extracted files to
5479 To write the extracted files to the standard output, instead of
5480 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
5481 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
5482 extracting files to send them through a pipe, and do not need to
5483 preserve them in the file system. If you extract multiple members,
5484 they appear on standard output concatenated, in the order they are
5485 found in the archive.
5486
5487 @table @option
5488 @opindex to-stdout
5489 @item --to-stdout
5490 @itemx -O
5491 Writes files to the standard output. Use only in conjunction with
5492 @option{--extract} (@option{--get}, @option{-x}). When this option is
5493 used, instead of creating the files specified, @command{tar} writes
5494 the contents of the files extracted to its standard output. This may
5495 be useful if you are only extracting the files in order to send them
5496 through a pipe. This option is meaningless with @option{--list}
5497 (@option{-t}).
5498 @end table
5499
5500 This can be useful, for example, if you have a tar archive containing
5501 a big file and don't want to store the file on disk before processing
5502 it. You can use a command like this:
5503
5504 @smallexample
5505 tar -xOzf foo.tgz bigfile | process
5506 @end smallexample
5507
5508 or even like this if you want to process the concatenation of the files:
5509
5510 @smallexample
5511 tar -xOzf foo.tgz bigfile1 bigfile2 | process
5512 @end smallexample
5513
5514 However, @option{--to-command} may be more convenient for use with
5515 multiple files. See the next section.
5516
5517 @node Writing to an External Program
5518 @unnumberedsubsubsec Writing to an External Program
5519
5520 You can instruct @command{tar} to send the contents of each extracted
5521 file to the standard input of an external program:
5522
5523 @table @option
5524 @opindex to-command
5525 @item --to-command=@var{command}
5526 Extract files and pipe their contents to the standard input of
5527 @var{command}. When this option is used, instead of creating the
5528 files specified, @command{tar} invokes @var{command} and pipes the
5529 contents of the files to its standard output. The @var{command} may
5530 contain command line arguments (see @ref{external, Running External Commands},
5531 for more detail).
5532
5533 Notice, that @var{command} is executed once for each regular file
5534 extracted. Non-regular files (directories, etc.) are ignored when this
5535 option is used.
5536 @end table
5537
5538 The command can obtain the information about the file it processes
5539 from the following environment variables:
5540
5541 @table @env
5542 @vrindex TAR_FILETYPE, to-command environment
5543 @item TAR_FILETYPE
5544 Type of the file. It is a single letter with the following meaning:
5545
5546 @multitable @columnfractions 0.10 0.90
5547 @item f @tab Regular file
5548 @item d @tab Directory
5549 @item l @tab Symbolic link
5550 @item h @tab Hard link
5551 @item b @tab Block device
5552 @item c @tab Character device
5553 @end multitable
5554
5555 Currently only regular files are supported.
5556
5557 @vrindex TAR_MODE, to-command environment
5558 @item TAR_MODE
5559 File mode, an octal number.
5560
5561 @vrindex TAR_FILENAME, to-command environment
5562 @item TAR_FILENAME
5563 The name of the file.
5564
5565 @vrindex TAR_REALNAME, to-command environment
5566 @item TAR_REALNAME
5567 Name of the file as stored in the archive.
5568
5569 @vrindex TAR_UNAME, to-command environment
5570 @item TAR_UNAME
5571 Name of the file owner.
5572
5573 @vrindex TAR_GNAME, to-command environment
5574 @item TAR_GNAME
5575 Name of the file owner group.
5576
5577 @vrindex TAR_ATIME, to-command environment
5578 @item TAR_ATIME
5579 Time of last access. It is a decimal number, representing seconds
5580 since the Epoch. If the archive provides times with nanosecond
5581 precision, the nanoseconds are appended to the timestamp after a
5582 decimal point.
5583
5584 @vrindex TAR_MTIME, to-command environment
5585 @item TAR_MTIME
5586 Time of last modification.
5587
5588 @vrindex TAR_CTIME, to-command environment
5589 @item TAR_CTIME
5590 Time of last status change.
5591
5592 @vrindex TAR_SIZE, to-command environment
5593 @item TAR_SIZE
5594 Size of the file.
5595
5596 @vrindex TAR_UID, to-command environment
5597 @item TAR_UID
5598 UID of the file owner.
5599
5600 @vrindex TAR_GID, to-command environment
5601 @item TAR_GID
5602 GID of the file owner.
5603 @end table
5604
5605 Additionally, the following variables contain information about
5606 tar mode and the archive being processed:
5607
5608 @table @env
5609 @vrindex TAR_VERSION, to-command environment
5610 @item TAR_VERSION
5611 @GNUTAR{} version number.
5612
5613 @vrindex TAR_ARCHIVE, to-command environment
5614 @item TAR_ARCHIVE
5615 The name of the archive @command{tar} is processing.
5616
5617 @vrindex TAR_BLOCKING_FACTOR, to-command environment
5618 @item TAR_BLOCKING_FACTOR
5619 Current blocking factor (@pxref{Blocking}).
5620
5621 @vrindex TAR_VOLUME, to-command environment
5622 @item TAR_VOLUME
5623 Ordinal number of the volume @command{tar} is processing.
5624
5625 @vrindex TAR_FORMAT, to-command environment
5626 @item TAR_FORMAT
5627 Format of the archive being processed. @xref{Formats}, for a complete
5628 list of archive format names.
5629 @end table
5630
5631 These variables are defined prior to executing the command, so you can
5632 pass them as arguments, if you prefer. For example, if the command
5633 @var{proc} takes the member name and size as its arguments, then you
5634 could do:
5635
5636 @smallexample
5637 $ @kbd{tar -x -f archive.tar \
5638 --to-command='proc $TAR_FILENAME $TAR_SIZE'}
5639 @end smallexample
5640
5641 @noindent
5642 Notice single quotes to prevent variable names from being expanded by
5643 the shell when invoking @command{tar}.
5644
5645 If @var{command} exits with a non-0 status, @command{tar} will print
5646 an error message similar to the following:
5647
5648 @smallexample
5649 tar: 2345: Child returned status 1
5650 @end smallexample
5651
5652 Here, @samp{2345} is the PID of the finished process.
5653
5654 If this behavior is not wanted, use @option{--ignore-command-error}:
5655
5656 @table @option
5657 @opindex ignore-command-error
5658 @item --ignore-command-error
5659 Ignore exit codes of subprocesses. Notice that if the program
5660 exits on signal or otherwise terminates abnormally, the error message
5661 will be printed even if this option is used.
5662
5663 @opindex no-ignore-command-error
5664 @item --no-ignore-command-error
5665 Cancel the effect of any previous @option{--ignore-command-error}
5666 option. This option is useful if you have set
5667 @option{--ignore-command-error} in @env{TAR_OPTIONS}
5668 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
5669 @end table
5670
5671 @node remove files
5672 @unnumberedsubsubsec Removing Files
5673
5674 @FIXME{The section is too terse. Something more to add? An example,
5675 maybe?}
5676
5677 @table @option
5678 @opindex remove-files
5679 @item --remove-files
5680 Remove files after adding them to the archive.
5681 @end table
5682
5683 @node Scarce
5684 @subsection Coping with Scarce Resources
5685 @UNREVISED
5686
5687 @cindex Small memory
5688 @cindex Running out of space
5689
5690 @menu
5691 * Starting File::
5692 * Same Order::
5693 @end menu
5694
5695 @node Starting File
5696 @unnumberedsubsubsec Starting File
5697
5698 @table @option
5699 @opindex starting-file
5700 @item --starting-file=@var{name}
5701 @itemx -K @var{name}
5702 Starts an operation in the middle of an archive. Use in conjunction
5703 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5704 @end table
5705
5706 @cindex Middle of the archive, starting in the
5707 If a previous attempt to extract files failed due to lack of disk
5708 space, you can use @option{--starting-file=@var{name}} (@option{-K
5709 @var{name}}) to start extracting only after member @var{name} of the
5710 archive. This assumes, of course, that there is now free space, or
5711 that you are now extracting into a different file system. (You could
5712 also choose to suspend @command{tar}, remove unnecessary files from
5713 the file system, and then resume the same @command{tar} operation.
5714 In this case, @option{--starting-file} is not necessary.) See also
5715 @ref{interactive}, and @ref{exclude}.
5716
5717 @node Same Order
5718 @unnumberedsubsubsec Same Order
5719
5720 @table @option
5721 @cindex Large lists of file names on small machines
5722 @opindex same-order
5723 @opindex preserve-order
5724 @item --same-order
5725 @itemx --preserve-order
5726 @itemx -s
5727 To process large lists of file names on machines with small amounts of
5728 memory. Use in conjunction with @option{--compare} (@option{--diff},
5729 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5730 (@option{--get}, @option{-x}).
5731 @end table
5732
5733 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5734 names to be listed or extracted is sorted in the same order as the
5735 files in the archive. This allows a large list of names to be used,
5736 even on a small machine that would not otherwise be able to hold all
5737 the names in memory at the same time. Such a sorted list can easily be
5738 created by running @samp{tar -t} on the archive and editing its output.
5739
5740 This option is probably never needed on modern computer systems.
5741
5742 @node backup
5743 @section Backup options
5744
5745 @cindex backup options
5746
5747 @GNUTAR{} offers options for making backups of files
5748 before writing new versions. These options control the details of
5749 these backups. They may apply to the archive itself before it is
5750 created or rewritten, as well as individual extracted members. Other
5751 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5752 and @command{mv}, for example) offer similar options.
5753
5754 Backup options may prove unexpectedly useful when extracting archives
5755 containing many members having identical name, or when extracting archives
5756 on systems having file name limitations, making different members appear
5757 as having similar names through the side-effect of name truncation.
5758 @FIXME{This is true only if we have a good scheme for truncated backup names,
5759 which I'm not sure at all: I suspect work is needed in this area.}
5760 When any existing file is backed up before being overwritten by extraction,
5761 then clashing files are automatically be renamed to be unique, and the
5762 true name is kept for only the last file of a series of clashing files.
5763 By using verbose mode, users may track exactly what happens.
5764
5765 At the detail level, some decisions are still experimental, and may
5766 change in the future, we are waiting comments from our users. So, please
5767 do not learn to depend blindly on the details of the backup features.
5768 For example, currently, directories themselves are never renamed through
5769 using these options, so, extracting a file over a directory still has
5770 good chances to fail. Also, backup options apply to created archives,
5771 not only to extracted members. For created archives, backups will not
5772 be attempted when the archive is a block or character device, or when it
5773 refers to a remote file.
5774
5775 For the sake of simplicity and efficiency, backups are made by renaming old
5776 files prior to creation or extraction, and not by copying. The original
5777 name is restored if the file creation fails. If a failure occurs after a
5778 partial extraction of a file, both the backup and the partially extracted
5779 file are kept.
5780
5781 @table @samp
5782 @item --backup[=@var{method}]
5783 @opindex backup
5784 @vindex VERSION_CONTROL
5785 @cindex backups
5786 Back up files that are about to be overwritten or removed.
5787 Without this option, the original versions are destroyed.
5788
5789 Use @var{method} to determine the type of backups made.
5790 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5791 environment variable. And if @env{VERSION_CONTROL} is not set,
5792 use the @samp{existing} method.
5793
5794 @vindex version-control @r{Emacs variable}
5795 This option corresponds to the Emacs variable @samp{version-control};
5796 the same values for @var{method} are accepted as in Emacs. This option
5797 also allows more descriptive names. The valid @var{method}s are:
5798
5799 @table @samp
5800 @item t
5801 @itemx numbered
5802 @cindex numbered @r{backup method}
5803 Always make numbered backups.
5804
5805 @item nil
5806 @itemx existing
5807 @cindex existing @r{backup method}
5808 Make numbered backups of files that already have them, simple backups
5809 of the others.
5810
5811 @item never
5812 @itemx simple
5813 @cindex simple @r{backup method}
5814 Always make simple backups.
5815
5816 @end table
5817
5818 @item --suffix=@var{suffix}
5819 @opindex suffix
5820 @cindex backup suffix
5821 @vindex SIMPLE_BACKUP_SUFFIX
5822 Append @var{suffix} to each backup file made with @option{--backup}. If this
5823 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5824 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5825 set, the default is @samp{~}, just as in Emacs.
5826
5827 @end table
5828
5829 @node Applications
5830 @section Notable @command{tar} Usages
5831 @UNREVISED
5832
5833 @FIXME{Using Unix file linking capability to recreate directory
5834 structures---linking files into one subdirectory and then
5835 @command{tar}ring that directory.}
5836
5837 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5838
5839 @findex uuencode
5840 You can easily use archive files to transport a group of files from
5841 one system to another: put all relevant files into an archive on one
5842 computer system, transfer the archive to another system, and extract
5843 the contents there. The basic transfer medium might be magnetic tape,
5844 Internet FTP, or even electronic mail (though you must encode the
5845 archive with @command{uuencode} in order to transport it properly by
5846 mail). Both machines do not have to use the same operating system, as
5847 long as they both support the @command{tar} program.
5848
5849 For example, here is how you might copy a directory's contents from
5850 one disk to another, while preserving the dates, modes, owners and
5851 link-structure of all the files therein. In this case, the transfer
5852 medium is a @dfn{pipe}:
5853
5854 @smallexample
5855 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5856 @end smallexample
5857
5858 @noindent
5859 You can avoid subshells by using @option{-C} option:
5860
5861 @smallexample
5862 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5863 @end smallexample
5864
5865 @noindent
5866 The command also works using long option forms:
5867
5868 @smallexample
5869 @group
5870 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5871 | (cd targetdir; tar --extract --file=-)}
5872 @end group
5873 @end smallexample
5874
5875 @noindent
5876 or
5877
5878 @smallexample
5879 @group
5880 $ @kbd{tar --directory sourcedir --create --file=- . \
5881 | tar --directory targetdir --extract --file=-}
5882 @end group
5883 @end smallexample
5884
5885 @noindent
5886 This is one of the easiest methods to transfer a @command{tar} archive.
5887
5888 @node looking ahead
5889 @section Looking Ahead: The Rest of this Manual
5890
5891 You have now seen how to use all eight of the operations available to
5892 @command{tar}, and a number of the possible options. The next chapter
5893 explains how to choose and change file and archive names, how to use
5894 files to store names of other files which you can then call as
5895 arguments to @command{tar} (this can help you save time if you expect to
5896 archive the same list of files a number of times), and so forth.
5897 @FIXME{in case it's not obvious, i'm making this up in some sense
5898 based on my limited memory of what the next chapter *really* does. i
5899 just wanted to flesh out this final section a little bit so i'd
5900 remember to stick it in here. :-)}
5901
5902 If there are too many files to conveniently list on the command line,
5903 you can list the names in a file, and @command{tar} will read that file.
5904 @xref{files}.
5905
5906 There are various ways of causing @command{tar} to skip over some files,
5907 and not archive them. @xref{Choosing}.
5908
5909 @node Backups
5910 @chapter Performing Backups and Restoring Files
5911 @cindex backups
5912
5913 @GNUTAR{} is distributed along with the scripts for performing backups
5914 and restores. Even if there is a good chance those scripts may be
5915 satisfying to you, they are not the only scripts or methods available for doing
5916 backups and restore. You may well create your own, or use more
5917 sophisticated packages dedicated to that purpose.
5918
5919 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5920 Automatic Network Disk Archiver), a backup system developed by James
5921 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5922 This is free software, and it is available from @uref{http://www.amanda.org}.
5923
5924 @FIXME{
5925
5926 Here is a possible plan for a future documentation about the backuping
5927 scripts which are provided within the @GNUTAR{}
5928 distribution.
5929
5930 @itemize @bullet
5931 @item dumps
5932 @itemize @minus
5933 @item what are dumps
5934 @item different levels of dumps
5935 @itemize +
5936 @item full dump = dump everything
5937 @item level 1, level 2 dumps etc
5938 A level @var{n} dump dumps everything changed since the last level
5939 @var{n}-1 dump (?)
5940 @end itemize
5941 @item how to use scripts for dumps (ie, the concept)
5942 @itemize +
5943 @item scripts to run after editing backup specs (details)
5944 @end itemize
5945 @item Backup Specs, what is it.
5946 @itemize +
5947 @item how to customize
5948 @item actual text of script [/sp/dump/backup-specs]
5949 @end itemize
5950 @item Problems
5951 @itemize +
5952 @item rsh doesn't work
5953 @item rtape isn't installed
5954 @item (others?)
5955 @end itemize
5956 @item the @option{--incremental} option of tar
5957 @item tapes
5958 @itemize +
5959 @item write protection
5960 @item types of media, different sizes and types, useful for different things
5961 @item files and tape marks
5962 one tape mark between files, two at end.
5963 @item positioning the tape
5964 MT writes two at end of write,
5965 backspaces over one when writing again.
5966 @end itemize
5967 @end itemize
5968 @end itemize
5969 }
5970
5971 This chapter documents both the provided shell scripts and @command{tar}
5972 options which are more specific to usage as a backup tool.
5973
5974 To @dfn{back up} a file system means to create archives that contain
5975 all the files in that file system. Those archives can then be used to
5976 restore any or all of those files (for instance if a disk crashes or a
5977 file is accidentally deleted). File system @dfn{backups} are also
5978 called @dfn{dumps}.
5979
5980 @menu
5981 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5982 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5983 * Backup Levels:: Levels of Backups
5984 * Backup Parameters:: Setting Parameters for Backups and Restoration
5985 * Scripted Backups:: Using the Backup Scripts
5986 * Scripted Restoration:: Using the Restore Script
5987 @end menu
5988
5989 @node Full Dumps
5990 @section Using @command{tar} to Perform Full Dumps
5991 @UNREVISED
5992
5993 @cindex full dumps
5994 @cindex dumps, full
5995
5996 @cindex corrupted archives
5997 Full dumps should only be made when no other people or programs
5998 are modifying files in the file system. If files are modified while
5999 @command{tar} is making the backup, they may not be stored properly in
6000 the archive, in which case you won't be able to restore them if you
6001 have to. (Files not being modified are written with no trouble, and do
6002 not corrupt the entire archive.)
6003
6004 You will want to use the @option{--label=@var{archive-label}}
6005 (@option{-V @var{archive-label}}) option to give the archive a
6006 volume label, so you can tell what this archive is even if the label
6007 falls off the tape, or anything like that.
6008
6009 Unless the file system you are dumping is guaranteed to fit on
6010 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
6011 Make sure you have enough tapes on hand to complete the backup.
6012
6013 If you want to dump each file system separately you will need to use
6014 the @option{--one-file-system} option to prevent
6015 @command{tar} from crossing file system boundaries when storing
6016 (sub)directories.
6017
6018 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
6019 option is not needed, since this is a complete copy of everything in
6020 the file system, and a full restore from this backup would only be
6021 done onto a completely
6022 empty disk.
6023
6024 Unless you are in a hurry, and trust the @command{tar} program (and your
6025 tapes), it is a good idea to use the @option{--verify} (@option{-W})
6026 option, to make sure your files really made it onto the dump properly.
6027 This will also detect cases where the file was modified while (or just
6028 after) it was being archived. Not all media (notably cartridge tapes)
6029 are capable of being verified, unfortunately.
6030
6031 @node Incremental Dumps
6032 @section Using @command{tar} to Perform Incremental Dumps
6033
6034 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
6035 stores additional metadata so that exact state of the file system
6036 can be restored when extracting the archive.
6037
6038 @GNUTAR{} currently offers two options for handling incremental
6039 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
6040 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
6041
6042 @xopindex{listed-incremental, described}
6043 The option @option{--listed-incremental} instructs tar to operate on
6044 an incremental archive with additional metadata stored in a standalone
6045 file, called a @dfn{snapshot file}. The purpose of this file is to help
6046 determine which files have been changed, added or deleted since the
6047 last backup, so that the next incremental backup will contain only
6048 modified files. The name of the snapshot file is given as an argument
6049 to the option:
6050
6051 @table @option
6052 @item --listed-incremental=@var{file}
6053 @itemx -g @var{file}
6054 Handle incremental backups with snapshot data in @var{file}.
6055 @end table
6056
6057 To create an incremental backup, you would use
6058 @option{--listed-incremental} together with @option{--create}
6059 (@pxref{create}). For example:
6060
6061 @smallexample
6062 $ @kbd{tar --create \
6063 --file=archive.1.tar \
6064 --listed-incremental=/var/log/usr.snar \
6065 /usr}
6066 @end smallexample
6067
6068 This will create in @file{archive.1.tar} an incremental backup of
6069 the @file{/usr} file system, storing additional metadata in the file
6070 @file{/var/log/usr.snar}. If this file does not exist, it will be
6071 created. The created archive will then be a @dfn{level 0 backup};
6072 please see the next section for more on backup levels.
6073
6074 Otherwise, if the file @file{/var/log/usr.snar} exists, it
6075 determines which files are modified. In this case only these files will be
6076 stored in the archive. Suppose, for example, that after running the
6077 above command, you delete file @file{/usr/doc/old} and create
6078 directory @file{/usr/local/db} with the following contents:
6079
6080 @smallexample
6081 $ @kbd{ls /usr/local/db}
6082 /usr/local/db/data
6083 /usr/local/db/index
6084 @end smallexample
6085
6086 Some time later you create another incremental backup. You will
6087 then see:
6088
6089 @smallexample
6090 $ @kbd{tar --create \
6091 --file=archive.2.tar \
6092 --listed-incremental=/var/log/usr.snar \
6093 /usr}
6094 tar: usr/local/db: Directory is new
6095 usr/local/db/
6096 usr/local/db/data
6097 usr/local/db/index
6098 @end smallexample
6099
6100 @noindent
6101 The created archive @file{archive.2.tar} will contain only these
6102 three members. This archive is called a @dfn{level 1 backup}. Notice
6103 that @file{/var/log/usr.snar} will be updated with the new data, so if
6104 you plan to create more @samp{level 1} backups, it is necessary to
6105 create a working copy of the snapshot file before running
6106 @command{tar}. The above example will then be modified as follows:
6107
6108 @smallexample
6109 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
6110 $ @kbd{tar --create \
6111 --file=archive.2.tar \
6112 --listed-incremental=/var/log/usr.snar-1 \
6113 /usr}
6114 @end smallexample
6115
6116 @anchor{--level=0}
6117 @xopindex{level, described}
6118 You can force @samp{level 0} backups either by removing the snapshot
6119 file before running @command{tar}, or by supplying the
6120 @option{--level=0} option, e.g.:
6121
6122 @smallexample
6123 $ @kbd{tar --create \
6124 --file=archive.2.tar \
6125 --listed-incremental=/var/log/usr.snar-0 \
6126 --level=0 \
6127 /usr}
6128 @end smallexample
6129
6130 Incremental dumps depend crucially on time stamps, so the results are
6131 unreliable if you modify a file's time stamps during dumping (e.g.,
6132 with the @option{--atime-preserve=replace} option), or if you set the clock
6133 backwards.
6134
6135 @anchor{device numbers}
6136 @cindex Device numbers, using in incremental backups
6137 Metadata stored in snapshot files include device numbers, which,
6138 obviously are supposed to be non-volatile values. However, it turns
6139 out that @acronym{NFS} devices have undependable values when an automounter
6140 gets in the picture. This can lead to a great deal of spurious
6141 redumping in incremental dumps, so it is somewhat useless to compare
6142 two @acronym{NFS} devices numbers over time. The solution implemented
6143 currently is to consider all @acronym{NFS} devices as being equal
6144 when it comes to comparing directories; this is fairly gross, but
6145 there does not seem to be a better way to go.
6146
6147 Apart from using @acronym{NFS}, there are a number of cases where
6148 relying on device numbers can cause spurious redumping of unmodified
6149 files. For example, this occurs when archiving @acronym{LVM} snapshot
6150 volumes. To avoid this, use @option{--no-check-device} option:
6151
6152 @table @option
6153 @xopindex{no-check-device, described}
6154 @item --no-check-device
6155 Do not rely on device numbers when preparing a list of changed files
6156 for an incremental dump.
6157
6158 @xopindex{check-device, described}
6159 @item --check-device
6160 Use device numbers when preparing a list of changed files
6161 for an incremental dump. This is the default behavior. The purpose
6162 of this option is to undo the effect of the @option{--no-check-device}
6163 if it was given in @env{TAR_OPTIONS} environment variable
6164 (@pxref{TAR_OPTIONS}).
6165 @end table
6166
6167 There is also another way to cope with changing device numbers. It is
6168 described in detail in @ref{Fixing Snapshot Files}.
6169
6170 Note that incremental archives use @command{tar} extensions and may
6171 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6172
6173 @xopindex{listed-incremental, using with @option{--extract}}
6174 @xopindex{extract, using with @option{--listed-incremental}}
6175 To extract from the incremental dumps, use
6176 @option{--listed-incremental} together with @option{--extract}
6177 option (@pxref{extracting files}). In this case, @command{tar} does
6178 not need to access snapshot file, since all the data necessary for
6179 extraction are stored in the archive itself. So, when extracting, you
6180 can give whatever argument to @option{--listed-incremental}, the usual
6181 practice is to use @option{--listed-incremental=/dev/null}.
6182 Alternatively, you can use @option{--incremental}, which needs no
6183 arguments. In general, @option{--incremental} (@option{-G}) can be
6184 used as a shortcut for @option{--listed-incremental} when listing or
6185 extracting incremental backups (for more information regarding this
6186 option, @pxref{incremental-op}).
6187
6188 When extracting from the incremental backup @GNUTAR{} attempts to
6189 restore the exact state the file system had when the archive was
6190 created. In particular, it will @emph{delete} those files in the file
6191 system that did not exist in their directories when the archive was
6192 created. If you have created several levels of incremental files,
6193 then in order to restore the exact contents the file system had when
6194 the last level was created, you will need to restore from all backups
6195 in turn. Continuing our example, to restore the state of @file{/usr}
6196 file system, one would do@footnote{Notice, that since both archives
6197 were created without @option{-P} option (@pxref{absolute}), these
6198 commands should be run from the root file system.}:
6199
6200 @smallexample
6201 $ @kbd{tar --extract \
6202 --listed-incremental=/dev/null \
6203 --file archive.1.tar}
6204 $ @kbd{tar --extract \
6205 --listed-incremental=/dev/null \
6206 --file archive.2.tar}
6207 @end smallexample
6208
6209 To list the contents of an incremental archive, use @option{--list}
6210 (@pxref{list}), as usual. To obtain more information about the
6211 archive, use @option{--listed-incremental} or @option{--incremental}
6212 combined with two @option{--verbose} options@footnote{Two
6213 @option{--verbose} options were selected to avoid breaking usual
6214 verbose listing output (@option{--list --verbose}) when using in
6215 scripts.
6216
6217 @xopindex{incremental, using with @option{--list}}
6218 @xopindex{listed-incremental, using with @option{--list}}
6219 @xopindex{list, using with @option{--incremental}}
6220 @xopindex{list, using with @option{--listed-incremental}}
6221 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
6222 contents of the DUMPDIR header (with terminating nulls) when
6223 @option{--incremental} or @option{--listed-incremental} option was
6224 given, no matter what the verbosity level. This behavior, and,
6225 especially, the binary output it produced were considered inconvenient
6226 and were changed in version 1.16.}:
6227
6228 @smallexample
6229 @kbd{tar --list --incremental --verbose --verbose archive.tar}
6230 @end smallexample
6231
6232 This command will print, for each directory in the archive, the list
6233 of files in that directory at the time the archive was created. This
6234 information is put out in a format which is both human-readable and
6235 unambiguous for a program: each file name is printed as
6236
6237 @smallexample
6238 @var{x} @var{file}
6239 @end smallexample
6240
6241 @noindent
6242 where @var{x} is a letter describing the status of the file: @samp{Y}
6243 if the file is present in the archive, @samp{N} if the file is not
6244 included in the archive, or a @samp{D} if the file is a directory (and
6245 is included in the archive). @xref{Dumpdir}, for the detailed
6246 description of dumpdirs and status codes. Each such
6247 line is terminated by a newline character. The last line is followed
6248 by an additional newline to indicate the end of the data.
6249
6250 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
6251 gives the same behavior as @option{--listed-incremental} when used
6252 with @option{--list} and @option{--extract} options. When used with
6253 @option{--create} option, it creates an incremental archive without
6254 creating snapshot file. Thus, it is impossible to create several
6255 levels of incremental backups with @option{--incremental} option.
6256
6257 @node Backup Levels
6258 @section Levels of Backups
6259
6260 An archive containing all the files in the file system is called a
6261 @dfn{full backup} or @dfn{full dump}. You could insure your data by
6262 creating a full dump every day. This strategy, however, would waste a
6263 substantial amount of archive media and user time, as unchanged files
6264 are daily re-archived.
6265
6266 It is more efficient to do a full dump only occasionally. To back up
6267 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
6268 one} dump archives all the files that have changed since the last full
6269 dump.
6270
6271 A typical dump strategy would be to perform a full dump once a week,
6272 and a level one dump once a day. This means some versions of files
6273 will in fact be archived more than once, but this dump strategy makes
6274 it possible to restore a file system to within one day of accuracy by
6275 only extracting two archives---the last weekly (full) dump and the
6276 last daily (level one) dump. The only information lost would be in
6277 files changed or created since the last daily backup. (Doing dumps
6278 more than once a day is usually not worth the trouble.)
6279
6280 @GNUTAR{} comes with scripts you can use to do full
6281 and level-one (actually, even level-two and so on) dumps. Using
6282 scripts (shell programs) to perform backups and restoration is a
6283 convenient and reliable alternative to typing out file name lists
6284 and @command{tar} commands by hand.
6285
6286 Before you use these scripts, you need to edit the file
6287 @file{backup-specs}, which specifies parameters used by the backup
6288 scripts and by the restore script. This file is usually located
6289 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
6290 detailed description. Once the backup parameters are set, you can
6291 perform backups or restoration by running the appropriate script.
6292
6293 The name of the backup script is @code{backup}. The name of the
6294 restore script is @code{restore}. The following sections describe
6295 their use in detail.
6296
6297 @emph{Please Note:} The backup and restoration scripts are
6298 designed to be used together. While it is possible to restore files by
6299 hand from an archive which was created using a backup script, and to create
6300 an archive by hand which could then be extracted using the restore script,
6301 it is easier to use the scripts. @xref{Incremental Dumps}, before
6302 making such an attempt.
6303
6304 @node Backup Parameters
6305 @section Setting Parameters for Backups and Restoration
6306
6307 The file @file{backup-specs} specifies backup parameters for the
6308 backup and restoration scripts provided with @command{tar}. You must
6309 edit @file{backup-specs} to fit your system configuration and schedule
6310 before using these scripts.
6311
6312 Syntactically, @file{backup-specs} is a shell script, containing
6313 mainly variable assignments. However, any valid shell construct
6314 is allowed in this file. Particularly, you may wish to define
6315 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
6316 For more information about shell script syntax, please refer to
6317 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
6318 g_02, the definition of the Shell Command Language}. See also
6319 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
6320
6321 The shell variables controlling behavior of @code{backup} and
6322 @code{restore} are described in the following subsections.
6323
6324 @menu
6325 * General-Purpose Variables::
6326 * Magnetic Tape Control::
6327 * User Hooks::
6328 * backup-specs example:: An Example Text of @file{Backup-specs}
6329 @end menu
6330
6331 @node General-Purpose Variables
6332 @subsection General-Purpose Variables
6333
6334 @defvr {Backup variable} ADMINISTRATOR
6335 The user name of the backup administrator. @code{Backup} scripts
6336 sends a backup report to this address.
6337 @end defvr
6338
6339 @defvr {Backup variable} BACKUP_HOUR
6340 The hour at which the backups are done. This can be a number from 0
6341 to 23, or the time specification in form @var{hours}:@var{minutes},
6342 or the string @samp{now}.
6343
6344 This variable is used by @code{backup}. Its value may be overridden
6345 using @option{--time} option (@pxref{Scripted Backups}).
6346 @end defvr
6347
6348 @defvr {Backup variable} TAPE_FILE
6349
6350 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
6351 is a remote archive (@pxref{remote-dev}), backup script will suppose
6352 that your @command{mt} is able to access remote devices. If @var{RSH}
6353 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
6354 invocations of @command{mt}.
6355 @end defvr
6356
6357 @defvr {Backup variable} BLOCKING
6358
6359 The blocking factor @command{tar} will use when writing the dump archive.
6360 @xref{Blocking Factor}.
6361 @end defvr
6362
6363 @defvr {Backup variable} BACKUP_DIRS
6364
6365 A list of file systems to be dumped (for @code{backup}), or restored
6366 (for @code{restore}). You can include any directory
6367 name in the list --- subdirectories on that file system will be
6368 included, regardless of how they may look to other networked machines.
6369 Subdirectories on other file systems will be ignored.
6370
6371 The host name specifies which host to run @command{tar} on, and should
6372 normally be the host that actually contains the file system. However,
6373 the host machine must have @GNUTAR{} installed, and
6374 must be able to access the directory containing the backup scripts and
6375 their support files using the same file name that is used on the
6376 machine where the scripts are run (i.e., what @command{pwd} will print
6377 when in that directory on that machine). If the host that contains
6378 the file system does not have this capability, you can specify another
6379 host as long as it can access the file system through @acronym{NFS}.
6380
6381 If the list of file systems is very long you may wish to put it
6382 in a separate file. This file is usually named
6383 @file{/etc/backup/dirs}, but this name may be overridden in
6384 @file{backup-specs} using @code{DIRLIST} variable.
6385 @end defvr
6386
6387 @defvr {Backup variable} DIRLIST
6388
6389 The name of the file that contains a list of file systems to backup
6390 or restore. By default it is @file{/etc/backup/dirs}.
6391 @end defvr
6392
6393 @defvr {Backup variable} BACKUP_FILES
6394
6395 A list of individual files to be dumped (for @code{backup}), or restored
6396 (for @code{restore}). These should be accessible from the machine on
6397 which the backup script is run.
6398
6399 If the list of individual files is very long you may wish to store it
6400 in a separate file. This file is usually named
6401 @file{/etc/backup/files}, but this name may be overridden in
6402 @file{backup-specs} using @code{FILELIST} variable.
6403 @end defvr
6404
6405 @defvr {Backup variable} FILELIST
6406
6407 The name of the file that contains a list of individual files to backup
6408 or restore. By default it is @file{/etc/backup/files}.
6409 @end defvr
6410
6411 @defvr {Backup variable} MT
6412
6413 Full file name of @command{mt} binary.
6414 @end defvr
6415
6416 @defvr {Backup variable} RSH
6417 @anchor{RSH}
6418 Full file name of @command{rsh} binary or its equivalent. You may wish to
6419 set it to @code{ssh}, to improve security. In this case you will have
6420 to use public key authentication.
6421 @end defvr
6422
6423 @defvr {Backup variable} RSH_COMMAND
6424
6425 Full file name of @command{rsh} binary on remote machines. This will
6426 be passed via @option{--rsh-command} option to the remote invocation
6427 of @GNUTAR{}.
6428 @end defvr
6429
6430 @defvr {Backup variable} VOLNO_FILE
6431
6432 Name of temporary file to hold volume numbers. This needs to be accessible
6433 by all the machines which have file systems to be dumped.
6434 @end defvr
6435
6436 @defvr {Backup variable} XLIST
6437
6438 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
6439 located on the remote machine and containing the list of files to
6440 be excluded from the backup. Exclude file lists are searched in
6441 /etc/tar-backup directory. A common use for exclude file lists
6442 is to exclude files containing security-sensitive information
6443 (e.g., @file{/etc/shadow} from backups).
6444
6445 This variable affects only @code{backup}.
6446 @end defvr
6447
6448 @defvr {Backup variable} SLEEP_TIME
6449
6450 Time to sleep between dumps of any two successive file systems
6451
6452 This variable affects only @code{backup}.
6453 @end defvr
6454
6455 @defvr {Backup variable} DUMP_REMIND_SCRIPT
6456
6457 Script to be run when it's time to insert a new tape in for the next
6458 volume. Administrators may want to tailor this script for their site.
6459 If this variable isn't set, @GNUTAR{} will display its built-in
6460 prompt, and will expect confirmation from the console. For the
6461 description of the default prompt, see @ref{change volume prompt}.
6462
6463 @end defvr
6464
6465 @defvr {Backup variable} SLEEP_MESSAGE
6466
6467 Message to display on the terminal while waiting for dump time. Usually
6468 this will just be some literal text.
6469 @end defvr
6470
6471 @defvr {Backup variable} TAR
6472
6473 Full file name of the @GNUTAR{} executable. If this is not set, backup
6474 scripts will search @command{tar} in the current shell path.
6475 @end defvr
6476
6477 @node Magnetic Tape Control
6478 @subsection Magnetic Tape Control
6479
6480 Backup scripts access tape device using special @dfn{hook functions}.
6481 These functions take a single argument --- the name of the tape
6482 device. Their names are kept in the following variables:
6483
6484 @defvr {Backup variable} MT_BEGIN
6485 The name of @dfn{begin} function. This function is called before
6486 accessing the drive. By default it retensions the tape:
6487
6488 @smallexample
6489 MT_BEGIN=mt_begin
6490
6491 mt_begin() @{
6492 mt -f "$1" retension
6493 @}
6494 @end smallexample
6495 @end defvr
6496
6497 @defvr {Backup variable} MT_REWIND
6498 The name of @dfn{rewind} function. The default definition is as
6499 follows:
6500
6501 @smallexample
6502 MT_REWIND=mt_rewind
6503
6504 mt_rewind() @{
6505 mt -f "$1" rewind
6506 @}
6507 @end smallexample
6508
6509 @end defvr
6510
6511 @defvr {Backup variable} MT_OFFLINE
6512 The name of the function switching the tape off line. By default
6513 it is defined as follows:
6514
6515 @smallexample
6516 MT_OFFLINE=mt_offline
6517
6518 mt_offline() @{
6519 mt -f "$1" offl
6520 @}
6521 @end smallexample
6522 @end defvr
6523
6524 @defvr {Backup variable} MT_STATUS
6525 The name of the function used to obtain the status of the archive device,
6526 including error count. Default definition:
6527
6528 @smallexample
6529 MT_STATUS=mt_status
6530
6531 mt_status() @{
6532 mt -f "$1" status
6533 @}
6534 @end smallexample
6535 @end defvr
6536
6537 @node User Hooks
6538 @subsection User Hooks
6539
6540 @dfn{User hooks} are shell functions executed before and after
6541 each @command{tar} invocation. Thus, there are @dfn{backup
6542 hooks}, which are executed before and after dumping each file
6543 system, and @dfn{restore hooks}, executed before and
6544 after restoring a file system. Each user hook is a shell function
6545 taking four arguments:
6546
6547 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
6548 Its arguments are:
6549
6550 @table @var
6551 @item level
6552 Current backup or restore level.
6553
6554 @item host
6555 Name or IP address of the host machine being dumped or restored.
6556
6557 @item fs
6558 Full file name of the file system being dumped or restored.
6559
6560 @item fsname
6561 File system name with directory separators replaced with colons. This
6562 is useful, e.g., for creating unique files.
6563 @end table
6564 @end deffn
6565
6566 Following variables keep the names of user hook functions:
6567
6568 @defvr {Backup variable} DUMP_BEGIN
6569 Dump begin function. It is executed before dumping the file system.
6570 @end defvr
6571
6572 @defvr {Backup variable} DUMP_END
6573 Executed after dumping the file system.
6574 @end defvr
6575
6576 @defvr {Backup variable} RESTORE_BEGIN
6577 Executed before restoring the file system.
6578 @end defvr
6579
6580 @defvr {Backup variable} RESTORE_END
6581 Executed after restoring the file system.
6582 @end defvr
6583
6584 @node backup-specs example
6585 @subsection An Example Text of @file{Backup-specs}
6586
6587 The following is an example of @file{backup-specs}:
6588
6589 @smallexample
6590 # site-specific parameters for file system backup.
6591
6592 ADMINISTRATOR=friedman
6593 BACKUP_HOUR=1
6594 TAPE_FILE=/dev/nrsmt0
6595
6596 # Use @code{ssh} instead of the less secure @code{rsh}
6597 RSH=/usr/bin/ssh
6598 RSH_COMMAND=/usr/bin/ssh
6599
6600 # Override MT_STATUS function:
6601 my_status() @{
6602 mts -t $TAPE_FILE
6603 @}
6604 MT_STATUS=my_status
6605
6606 # Disable MT_OFFLINE function
6607 MT_OFFLINE=:
6608
6609 BLOCKING=124
6610 BACKUP_DIRS="
6611 albert:/fs/fsf
6612 apple-gunkies:/gd
6613 albert:/fs/gd2
6614 albert:/fs/gp
6615 geech:/usr/jla
6616 churchy:/usr/roland
6617 albert:/
6618 albert:/usr
6619 apple-gunkies:/
6620 apple-gunkies:/usr
6621 gnu:/hack
6622 gnu:/u
6623 apple-gunkies:/com/mailer/gnu
6624 apple-gunkies:/com/archive/gnu"
6625
6626 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
6627
6628 @end smallexample
6629
6630 @node Scripted Backups
6631 @section Using the Backup Scripts
6632
6633 The syntax for running a backup script is:
6634
6635 @smallexample
6636 backup --level=@var{level} --time=@var{time}
6637 @end smallexample
6638
6639 The @option{--level} option requests the dump level. Thus, to produce
6640 a full dump, specify @code{--level=0} (this is the default, so
6641 @option{--level} may be omitted if its value is
6642 @code{0})@footnote{For backward compatibility, the @code{backup} will also
6643 try to deduce the requested dump level from the name of the
6644 script itself. If the name consists of a string @samp{level-}
6645 followed by a single decimal digit, that digit is taken as
6646 the dump level number. Thus, you may create a link from @code{backup}
6647 to @code{level-1} and then run @code{level-1} whenever you need to
6648 create a level one dump.}.
6649
6650 The @option{--time} option determines when should the backup be
6651 run. @var{Time} may take three forms:
6652
6653 @table @asis
6654 @item @var{hh}:@var{mm}
6655
6656 The dump must be run at @var{hh} hours @var{mm} minutes.
6657
6658 @item @var{hh}
6659
6660 The dump must be run at @var{hh} hours.
6661
6662 @item now
6663
6664 The dump must be run immediately.
6665 @end table
6666
6667 You should start a script with a tape or disk mounted. Once you
6668 start a script, it prompts you for new tapes or disks as it
6669 needs them. Media volumes don't have to correspond to archive
6670 files --- a multi-volume archive can be started in the middle of a
6671 tape that already contains the end of another multi-volume archive.
6672 The @code{restore} script prompts for media by its archive volume,
6673 so to avoid an error message you should keep track of which tape
6674 (or disk) contains which volume of the archive (@pxref{Scripted
6675 Restoration}).
6676
6677 The backup scripts write two files on the file system. The first is a
6678 record file in @file{/etc/tar-backup/}, which is used by the scripts
6679 to store and retrieve information about which files were dumped. This
6680 file is not meant to be read by humans, and should not be deleted by
6681 them. @xref{Snapshot Files}, for a more detailed explanation of this
6682 file.
6683
6684 The second file is a log file containing the names of the file systems
6685 and files dumped, what time the backup was made, and any error
6686 messages that were generated, as well as how much space was left in
6687 the media volume after the last volume of the archive was written.
6688 You should check this log file after every backup. The file name is
6689 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
6690 represents current date, and @var{n} represents current dump level number.
6691
6692 The script also prints the name of each system being dumped to the
6693 standard output.
6694
6695 Following is the full list of options accepted by @code{backup}
6696 script:
6697
6698 @table @option
6699 @item -l @var{level}
6700 @itemx --level=@var{level}
6701 Do backup level @var{level} (default 0).
6702
6703 @item -f
6704 @itemx --force
6705 Force backup even if today's log file already exists.
6706
6707 @item -v[@var{level}]
6708 @itemx --verbose[=@var{level}]
6709 Set verbosity level. The higher the level is, the more debugging
6710 information will be output during execution. Default @var{level}
6711 is 100, which means the highest debugging level.
6712
6713 @item -t @var{start-time}
6714 @itemx --time=@var{start-time}
6715 Wait till @var{time}, then do backup.
6716
6717 @item -h
6718 @itemx --help
6719 Display short help message and exit.
6720
6721 @item -V
6722 @itemx --version
6723 Display information about the program's name, version, origin and legal
6724 status, all on standard output, and then exit successfully.
6725 @end table
6726
6727
6728 @node Scripted Restoration
6729 @section Using the Restore Script
6730
6731 To restore files that were archived using a scripted backup, use the
6732 @code{restore} script. Its usage is quite straightforward. In the
6733 simplest form, invoke @code{restore --all}, it will
6734 then restore all the file systems and files specified in
6735 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6736
6737 You may select the file systems (and/or files) to restore by
6738 giving @code{restore} a list of @dfn{patterns} in its command
6739 line. For example, running
6740
6741 @smallexample
6742 restore 'albert:*'
6743 @end smallexample
6744
6745 @noindent
6746 will restore all file systems on the machine @samp{albert}. A more
6747 complicated example:
6748
6749 @smallexample
6750 restore 'albert:*' '*:/var'
6751 @end smallexample
6752
6753 @noindent
6754 This command will restore all file systems on the machine @samp{albert}
6755 as well as @file{/var} file system on all machines.
6756
6757 By default @code{restore} will start restoring files from the lowest
6758 available dump level (usually zero) and will continue through
6759 all available dump levels. There may be situations where such a
6760 thorough restore is not necessary. For example, you may wish to
6761 restore only files from the recent level one backup. To do so,
6762 use @option{--level} option, as shown in the example below:
6763
6764 @smallexample
6765 restore --level=1
6766 @end smallexample
6767
6768 The full list of options accepted by @code{restore} follows:
6769
6770 @table @option
6771 @item -a
6772 @itemx --all
6773 Restore all file systems and files specified in @file{backup-specs}.
6774
6775 @item -l @var{level}
6776 @itemx --level=@var{level}
6777 Start restoring from the given backup level, instead of the default 0.
6778
6779 @item -v[@var{level}]
6780 @itemx --verbose[=@var{level}]
6781 Set verbosity level. The higher the level is, the more debugging
6782 information will be output during execution. Default @var{level}
6783 is 100, which means the highest debugging level.
6784
6785 @item -h
6786 @itemx --help
6787 Display short help message and exit.
6788
6789 @item -V
6790 @itemx --version
6791 Display information about the program's name, version, origin and legal
6792 status, all on standard output, and then exit successfully.
6793 @end table
6794
6795 You should start the restore script with the media containing the
6796 first volume of the archive mounted. The script will prompt for other
6797 volumes as they are needed. If the archive is on tape, you don't need
6798 to rewind the tape to to its beginning---if the tape head is
6799 positioned past the beginning of the archive, the script will rewind
6800 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6801 positioning.
6802
6803 @quotation
6804 @strong{Warning:} The script will delete files from the active file
6805 system if they were not in the file system when the archive was made.
6806 @end quotation
6807
6808 @xref{Incremental Dumps}, for an explanation of how the script makes
6809 that determination.
6810
6811 @node Choosing
6812 @chapter Choosing Files and Names for @command{tar}
6813
6814 Certain options to @command{tar} enable you to specify a name for your
6815 archive. Other options let you decide which files to include or exclude
6816 from the archive, based on when or whether files were modified, whether
6817 the file names do or don't match specified patterns, or whether files
6818 are in specified directories.
6819
6820 This chapter discusses these options in detail.
6821
6822 @menu
6823 * file:: Choosing the Archive's Name
6824 * Selecting Archive Members::
6825 * files:: Reading Names from a File
6826 * exclude:: Excluding Some Files
6827 * wildcards:: Wildcards Patterns and Matching
6828 * quoting styles:: Ways of Quoting Special Characters in Names
6829 * transform:: Modifying File and Member Names
6830 * after:: Operating Only on New Files
6831 * recurse:: Descending into Directories
6832 * one:: Crossing File System Boundaries
6833 @end menu
6834
6835 @node file
6836 @section Choosing and Naming Archive Files
6837
6838 @cindex Naming an archive
6839 @cindex Archive Name
6840 @cindex Choosing an archive file
6841 @cindex Where is the archive?
6842 @opindex file
6843 By default, @command{tar} uses an archive file name that was compiled when
6844 it was built on the system; usually this name refers to some physical
6845 tape drive on the machine. However, the person who installed @command{tar}
6846 on the system may not have set the default to a meaningful value as far as
6847 most users are concerned. As a result, you will usually want to tell
6848 @command{tar} where to find (or create) the archive. The
6849 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6850 option allows you to either specify or name a file to use as the archive
6851 instead of the default archive file location.
6852
6853 @table @option
6854 @xopindex{file, short description}
6855 @item --file=@var{archive-name}
6856 @itemx -f @var{archive-name}
6857 Name the archive to create or operate on. Use in conjunction with
6858 any operation.
6859 @end table
6860
6861 For example, in this @command{tar} command,
6862
6863 @smallexample
6864 $ @kbd{tar -cvf collection.tar blues folk jazz}
6865 @end smallexample
6866
6867 @noindent
6868 @file{collection.tar} is the name of the archive. It must directly
6869 follow the @option{-f} option, since whatever directly follows @option{-f}
6870 @emph{will} end up naming the archive. If you neglect to specify an
6871 archive name, you may end up overwriting a file in the working directory
6872 with the archive you create since @command{tar} will use this file's name
6873 for the archive name.
6874
6875 An archive can be saved as a file in the file system, sent through a
6876 pipe or over a network, or written to an I/O device such as a tape,
6877 floppy disk, or CD write drive.
6878
6879 @cindex Writing new archives
6880 @cindex Archive creation
6881 If you do not name the archive, @command{tar} uses the value of the
6882 environment variable @env{TAPE} as the file name for the archive. If
6883 that is not available, @command{tar} uses a default, compiled-in archive
6884 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6885
6886 @cindex Standard input and output
6887 @cindex tar to standard input and output
6888 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6889 archive from standard input (when listing or extracting files), or
6890 writes it to standard output (when creating an archive). If you use
6891 @file{-} as an @var{archive-name} when modifying an archive,
6892 @command{tar} reads the original archive from its standard input and
6893 writes the entire new archive to its standard output.
6894
6895 The following example is a convenient way of copying directory
6896 hierarchy from @file{sourcedir} to @file{targetdir}.
6897
6898 @smallexample
6899 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6900 @end smallexample
6901
6902 The @option{-C} option allows to avoid using subshells:
6903
6904 @smallexample
6905 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6906 @end smallexample
6907
6908 In both examples above, the leftmost @command{tar} invocation archives
6909 the contents of @file{sourcedir} to the standard output, while the
6910 rightmost one reads this archive from its standard input and
6911 extracts it. The @option{-p} option tells it to restore permissions
6912 of the extracted files.
6913
6914 @cindex Remote devices
6915 @cindex tar to a remote device
6916 @anchor{remote-dev}
6917 To specify an archive file on a device attached to a remote machine,
6918 use the following:
6919
6920 @smallexample
6921 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6922 @end smallexample
6923
6924 @noindent
6925 @command{tar} will set up the remote connection, if possible, and
6926 prompt you for a username and password. If you use
6927 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6928 will attempt to set up the remote connection using your username
6929 as the username on the remote machine.
6930
6931 @cindex Local and remote archives
6932 @anchor{local and remote archives}
6933 If the archive file name includes a colon (@samp{:}), then it is assumed
6934 to be a file on another machine. If the archive file is
6935 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6936 host @var{host}. The remote host is accessed using the @command{rsh}
6937 program, with a username of @var{user}. If the username is omitted
6938 (along with the @samp{@@} sign), then your user name will be used.
6939 (This is the normal @command{rsh} behavior.) It is necessary for the
6940 remote machine, in addition to permitting your @command{rsh} access, to
6941 have the @file{rmt} program installed (this command is included in
6942 the @GNUTAR{} distribution and by default is installed under
6943 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
6944 installation prefix). If you need to use a file whose name includes a
6945 colon, then the remote tape drive behavior
6946 can be inhibited by using the @option{--force-local} option.
6947
6948 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6949 tries to minimize input and output operations. The Amanda backup
6950 system, when used with @GNUTAR{}, has an initial sizing pass which
6951 uses this feature.
6952
6953 @node Selecting Archive Members
6954 @section Selecting Archive Members
6955 @cindex Specifying files to act on
6956 @cindex Specifying archive members
6957
6958 @dfn{File Name arguments} specify which files in the file system
6959 @command{tar} operates on, when creating or adding to an archive, or which
6960 archive members @command{tar} operates on, when reading or deleting from
6961 an archive. @xref{Operations}.
6962
6963 To specify file names, you can include them as the last arguments on
6964 the command line, as follows:
6965 @smallexample
6966 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6967 @end smallexample
6968
6969 If a file name begins with dash (@samp{-}), precede it with
6970 @option{--add-file} option to prevent it from being treated as an
6971 option.
6972
6973 @anchor{input name quoting}
6974 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6975 name, replacing @dfn{escape sequences} according to the following
6976 table:
6977
6978 @multitable @columnfractions 0.20 0.60
6979 @headitem Escape @tab Replaced with
6980 @item \a @tab Audible bell (@acronym{ASCII} 7)
6981 @item \b @tab Backspace (@acronym{ASCII} 8)
6982 @item \f @tab Form feed (@acronym{ASCII} 12)
6983 @item \n @tab New line (@acronym{ASCII} 10)
6984 @item \r @tab Carriage return (@acronym{ASCII} 13)
6985 @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
6986 @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
6987 @item \? @tab @acronym{ASCII} 127
6988 @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
6989 of up to 3 digits)
6990 @end multitable
6991
6992 A backslash followed by any other symbol is retained.
6993
6994 This default behavior is controlled by the following command line
6995 option:
6996
6997 @table @option
6998 @opindex unquote
6999 @item --unquote
7000 Enable unquoting input file or member names (default).
7001
7002 @opindex no-unquote
7003 @item --no-unquote
7004 Disable unquoting input file or member names.
7005 @end table
7006
7007 If you specify a directory name as a file name argument, all the files
7008 in that directory are operated on by @command{tar}.
7009
7010 If you do not specify files, @command{tar} behavior differs depending
7011 on the operation mode as described below:
7012
7013 When @command{tar} is invoked with @option{--create} (@option{-c}),
7014 @command{tar} will stop immediately, reporting the following:
7015
7016 @smallexample
7017 @group
7018 $ @kbd{tar cf a.tar}
7019 tar: Cowardly refusing to create an empty archive
7020 Try 'tar --help' or 'tar --usage' for more information.
7021 @end group
7022 @end smallexample
7023
7024 If you specify either @option{--list} (@option{-t}) or
7025 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
7026 operates on all the archive members in the archive.
7027
7028 If run with @option{--diff} option, tar will compare the archive with
7029 the contents of the current working directory.
7030
7031 If you specify any other operation, @command{tar} does nothing.
7032
7033 By default, @command{tar} takes file names from the command line. However,
7034 there are other ways to specify file or member names, or to modify the
7035 manner in which @command{tar} selects the files or members upon which to
7036 operate. In general, these methods work both for specifying the names
7037 of files and archive members.
7038
7039 @node files
7040 @section Reading Names from a File
7041
7042 @cindex Reading file names from a file
7043 @cindex Lists of file names
7044 @cindex File Name arguments, alternatives
7045 @cindex @command{find}, using with @command{tar}
7046 Instead of giving the names of files or archive members on the command
7047 line, you can put the names into a file, and then use the
7048 @option{--files-from=@var{file-of-names}} (@option{-T
7049 @var{file-of-names}}) option to @command{tar}. Give the name of the
7050 file which contains the list of files to include as the argument to
7051 @option{--files-from}. In the list, the file names should be separated by
7052 newlines. You will frequently use this option when you have generated
7053 the list of files to archive with the @command{find} utility.
7054
7055 @table @option
7056 @opindex files-from
7057 @item --files-from=@var{file-name}
7058 @itemx -T @var{file-name}
7059 Get names to extract or create from file @var{file-name}.
7060 @end table
7061
7062 If you give a single dash as a file name for @option{--files-from}, (i.e.,
7063 you specify either @code{--files-from=-} or @code{-T -}), then the file
7064 names are read from standard input.
7065
7066 Unless you are running @command{tar} with @option{--create}, you can not use
7067 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
7068 command.
7069
7070 Any number of @option{-T} options can be given in the command line.
7071
7072 The following example shows how to use @command{find} to generate a list of
7073 files smaller than 400K in length and put that list into a file
7074 called @file{small-files}. You can then use the @option{-T} option to
7075 @command{tar} to specify the files from that file, @file{small-files}, to
7076 create the archive @file{little.tgz}. (The @option{-z} option to
7077 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
7078 more information.)
7079
7080 @smallexample
7081 $ @kbd{find . -size -400 -print > small-files}
7082 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
7083 @end smallexample
7084
7085 @noindent
7086 In the file list given by @option{-T} option, any file name beginning
7087 with @samp{-} character is considered a @command{tar} option and is
7088 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
7089 recognized only @option{-C} option in file lists, and only if the
7090 option and its argument occupied two consecutive lines.}. For example,
7091 the common use of this feature is to change to another directory by
7092 specifying @option{-C} option:
7093
7094 @smallexample
7095 @group
7096 $ @kbd{cat list}
7097 -C/etc
7098 passwd
7099 hosts
7100 -C/lib
7101 libc.a
7102 $ @kbd{tar -c -f foo.tar --files-from list}
7103 @end group
7104 @end smallexample
7105
7106 @noindent
7107 In this example, @command{tar} will first switch to @file{/etc}
7108 directory and add files @file{passwd} and @file{hosts} to the
7109 archive. Then it will change to @file{/lib} directory and will archive
7110 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
7111 contain:
7112
7113 @smallexample
7114 @group
7115 $ @kbd{tar tf foo.tar}
7116 passwd
7117 hosts
7118 libc.a
7119 @end group
7120 @end smallexample
7121
7122 @noindent
7123 @xopindex{directory, using in @option{--files-from} argument}
7124 Notice that the option parsing algorithm used with @option{-T} is
7125 stricter than the one used by shell. Namely, when specifying option
7126 arguments, you should observe the following rules:
7127
7128 @itemize @bullet
7129 @item
7130 When using short (single-letter) option form, its argument must
7131 immediately follow the option letter, without any intervening
7132 whitespace. For example: @code{-Cdir}.
7133
7134 @item
7135 When using long option form, the option argument must be separated
7136 from the option by a single equal sign. No whitespace is allowed on
7137 any side of the equal sign. For example: @code{--directory=dir}.
7138
7139 @item
7140 For both short and long option forms, the option argument can be given
7141 on the next line after the option name, e.g.:
7142
7143 @smallexample
7144 @group
7145 --directory
7146 dir
7147 @end group
7148 @end smallexample
7149
7150 @noindent
7151 and
7152
7153 @smallexample
7154 @group
7155 -C
7156 dir
7157 @end group
7158 @end smallexample
7159 @end itemize
7160
7161 @opindex add-file
7162 If you happen to have a file whose name starts with @samp{-},
7163 precede it with @option{--add-file} option to prevent it from
7164 being recognized as an option. For example: @code{--add-file=--my-file}.
7165
7166 @menu
7167 * nul::
7168 @end menu
7169
7170 @node nul
7171 @subsection @code{NUL}-Terminated File Names
7172
7173 @cindex File names, terminated by @code{NUL}
7174 @cindex @code{NUL}-terminated file names
7175 The @option{--null} option causes
7176 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7177 to read file names terminated by a @code{NUL} instead of a newline, so
7178 files whose names contain newlines can be archived using
7179 @option{--files-from}.
7180
7181 @table @option
7182 @xopindex{null, described}
7183 @item --null
7184 Only consider @code{NUL}-terminated file names, instead of files that
7185 terminate in a newline.
7186
7187 @xopindex{no-null, described}
7188 @item --no-null
7189 Undo the effect of any previous @option{--null} option.
7190 @end table
7191
7192 The @option{--null} option is just like the one in @acronym{GNU}
7193 @command{xargs} and @command{cpio}, and is useful with the
7194 @option{-print0} predicate of @acronym{GNU} @command{find}. In
7195 @command{tar}, @option{--null} also disables special handling for
7196 file names that begin with dash.
7197
7198 This example shows how to use @command{find} to generate a list of files
7199 larger than 800K in length and put that list into a file called
7200 @file{long-files}. The @option{-print0} option to @command{find} is just
7201 like @option{-print}, except that it separates files with a @code{NUL}
7202 rather than with a newline. You can then run @command{tar} with both the
7203 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7204 files from that file, @file{long-files}, to create the archive
7205 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
7206 @command{tar} to recognize the @code{NUL} separator between files.
7207
7208 @smallexample
7209 $ @kbd{find . -size +800 -print0 > long-files}
7210 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
7211 @end smallexample
7212
7213 The @option{--no-null} option can be used if you need to read both
7214 @code{NUL}-terminated and newline-terminated files on the same command line.
7215 For example, if @file{flist} is a newline-terminated file, then the
7216 following command can be used to combine it with the above command:
7217
7218 @smallexample
7219 @group
7220 $ @kbd{find . -size +800 -print0 |
7221 tar -c -f big.tar --null -T - --no-null -T flist}
7222 @end group
7223 @end smallexample
7224
7225 This example uses short options for typographic reasons, to avoid
7226 very long lines.
7227
7228 @GNUTAR is able to automatically detect @code{NUL}-terminated file lists, so
7229 it is safe to use them even without the @option{--null} option. In
7230 this case @command{tar} will print a warning and continue reading such
7231 a file as if @option{--null} were actually given:
7232
7233 @smallexample
7234 @group
7235 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
7236 tar: -: file name read contains nul character
7237 @end group
7238 @end smallexample
7239
7240 The null terminator, however, remains in effect only for this
7241 particular file, any following @option{-T} options will assume
7242 newline termination. Of course, the null autodetection applies
7243 to these eventual surplus @option{-T} options as well.
7244
7245 @node exclude
7246 @section Excluding Some Files
7247
7248 @cindex File names, excluding files by
7249 @cindex Excluding files by name and pattern
7250 @cindex Excluding files by file system
7251 @opindex exclude
7252 @opindex exclude-from
7253 To avoid operating on files whose names match a particular pattern,
7254 use the @option{--exclude} or @option{--exclude-from} options.
7255
7256 @table @option
7257 @opindex exclude
7258 @item --exclude=@var{pattern}
7259 Causes @command{tar} to ignore files that match the @var{pattern}.
7260 @end table
7261
7262 @findex exclude
7263 The @option{--exclude=@var{pattern}} option prevents any file or
7264 member whose name matches the shell wildcard (@var{pattern}) from
7265 being operated on.
7266 For example, to create an archive with all the contents of the directory
7267 @file{src} except for files whose names end in @file{.o}, use the
7268 command @samp{tar -cf src.tar --exclude='*.o' src}.
7269
7270 You may give multiple @option{--exclude} options.
7271
7272 @table @option
7273 @opindex exclude-from
7274 @item --exclude-from=@var{file}
7275 @itemx -X @var{file}
7276 Causes @command{tar} to ignore files that match the patterns listed in
7277 @var{file}.
7278 @end table
7279
7280 @findex exclude-from
7281 Use the @option{--exclude-from} option to read a
7282 list of patterns, one per line, from @var{file}; @command{tar} will
7283 ignore files matching those patterns. Thus if @command{tar} is
7284 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
7285 single line @file{*.o}, no files whose names end in @file{.o} will be
7286 added to the archive.
7287
7288 Notice, that lines from @var{file} are read verbatim. One of the
7289 frequent errors is leaving some extra whitespace after a file name,
7290 which is difficult to catch using text editors.
7291
7292 However, empty lines are OK.
7293
7294 @table @option
7295 @cindex version control system, excluding files
7296 @cindex VCS, excluding files
7297 @cindex SCCS, excluding files
7298 @cindex RCS, excluding files
7299 @cindex CVS, excluding files
7300 @cindex SVN, excluding files
7301 @cindex git, excluding files
7302 @cindex Bazaar, excluding files
7303 @cindex Arch, excluding files
7304 @cindex Mercurial, excluding files
7305 @cindex Darcs, excluding files
7306 @opindex exclude-vcs
7307 @item --exclude-vcs
7308 Exclude files and directories used by following version control
7309 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
7310 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
7311
7312 As of version @value{VERSION}, the following files are excluded:
7313
7314 @itemize @bullet
7315 @item @file{CVS/}, and everything under it
7316 @item @file{RCS/}, and everything under it
7317 @item @file{SCCS/}, and everything under it
7318 @item @file{.git/}, and everything under it
7319 @item @file{.gitignore}
7320 @item @file{.cvsignore}
7321 @item @file{.svn/}, and everything under it
7322 @item @file{.arch-ids/}, and everything under it
7323 @item @file{@{arch@}/}, and everything under it
7324 @item @file{=RELEASE-ID}
7325 @item @file{=meta-update}
7326 @item @file{=update}
7327 @item @file{.bzr}
7328 @item @file{.bzrignore}
7329 @item @file{.bzrtags}
7330 @item @file{.hg}
7331 @item @file{.hgignore}
7332 @item @file{.hgrags}
7333 @item @file{_darcs}
7334 @end itemize
7335
7336 @opindex exclude-backups
7337 @item --exclude-backups
7338 Exclude backup and lock files. This option causes exclusion of files
7339 that match the following shell globbing patterns:
7340
7341 @table @asis
7342 @item .#*
7343 @item *~
7344 @item #*#
7345 @end table
7346
7347 @end table
7348
7349 @findex exclude-caches
7350 When creating an archive, the @option{--exclude-caches} option family
7351 causes @command{tar} to exclude all directories that contain a @dfn{cache
7352 directory tag}. A cache directory tag is a short file with the
7353 well-known name @file{CACHEDIR.TAG} and having a standard header
7354 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
7355 Various applications write cache directory tags into directories they
7356 use to hold regenerable, non-precious data, so that such data can be
7357 more easily excluded from backups.
7358
7359 There are three @samp{exclude-caches} options, each providing a different
7360 exclusion semantics:
7361
7362 @table @option
7363 @opindex exclude-caches
7364 @item --exclude-caches
7365 Do not archive the contents of the directory, but archive the
7366 directory itself and the @file{CACHEDIR.TAG} file.
7367
7368 @opindex exclude-caches-under
7369 @item --exclude-caches-under
7370 Do not archive the contents of the directory, nor the
7371 @file{CACHEDIR.TAG} file, archive only the directory itself.
7372
7373 @opindex exclude-caches-all
7374 @item --exclude-caches-all
7375 Omit directories containing @file{CACHEDIR.TAG} file entirely.
7376 @end table
7377
7378 @findex exclude-tag
7379 Another option family, @option{--exclude-tag}, provides a generalization of
7380 this concept. It takes a single argument, a file name to look for.
7381 Any directory that contains this file will be excluded from the dump.
7382 Similarly to @samp{exclude-caches}, there are three options in this
7383 option family:
7384
7385 @table @option
7386 @opindex exclude-tag
7387 @item --exclude-tag=@var{file}
7388 Do not dump the contents of the directory, but dump the
7389 directory itself and the @var{file}.
7390
7391 @opindex exclude-tag-under
7392 @item --exclude-tag-under=@var{file}
7393 Do not dump the contents of the directory, nor the
7394 @var{file}, archive only the directory itself.
7395
7396 @opindex exclude-tag-all
7397 @item --exclude-tag-all=@var{file}
7398 Omit directories containing @var{file} file entirely.
7399 @end table
7400
7401 Multiple @option{--exclude-tag*} options can be given.
7402
7403 For example, given this directory:
7404
7405 @smallexample
7406 @group
7407 $ @kbd{find dir}
7408 dir
7409 dir/blues
7410 dir/jazz
7411 dir/folk
7412 dir/folk/tagfile
7413 dir/folk/sanjuan
7414 dir/folk/trote
7415 @end group
7416 @end smallexample
7417
7418 The @option{--exclude-tag} will produce the following:
7419
7420 @smallexample
7421 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
7422 dir/
7423 dir/blues
7424 dir/jazz
7425 dir/folk/
7426 tar: dir/folk/: contains a cache directory tag tagfile;
7427 contents not dumped
7428 dir/folk/tagfile
7429 @end smallexample
7430
7431 Both the @file{dir/folk} directory and its tagfile are preserved in
7432 the archive, however the rest of files in this directory are not.
7433
7434 Now, using the @option{--exclude-tag-under} option will exclude
7435 @file{tagfile} from the dump, while still preserving the directory
7436 itself, as shown in this example:
7437
7438 @smallexample
7439 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
7440 dir/
7441 dir/blues
7442 dir/jazz
7443 dir/folk/
7444 ./tar: dir/folk/: contains a cache directory tag tagfile;
7445 contents not dumped
7446 @end smallexample
7447
7448 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
7449 directory entirely:
7450
7451 @smallexample
7452 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
7453 dir/
7454 dir/blues
7455 dir/jazz
7456 ./tar: dir/folk/: contains a cache directory tag tagfile;
7457 directory not dumped
7458 @end smallexample
7459
7460 @menu
7461 * problems with exclude::
7462 @end menu
7463
7464 @node problems with exclude
7465 @unnumberedsubsec Problems with Using the @code{exclude} Options
7466
7467 @xopindex{exclude, potential problems with}
7468 Some users find @samp{exclude} options confusing. Here are some common
7469 pitfalls:
7470
7471 @itemize @bullet
7472 @item
7473 The main operating mode of @command{tar} does not act on a file name
7474 explicitly listed on the command line, if one of its file name
7475 components is excluded. In the example above, if
7476 you create an archive and exclude files that end with @samp{*.o}, but
7477 explicitly name the file @samp{dir.o/foo} after all the options have been
7478 listed, @samp{dir.o/foo} will be excluded from the archive.
7479
7480 @item
7481 You can sometimes confuse the meanings of @option{--exclude} and
7482 @option{--exclude-from}. Be careful: use @option{--exclude} when files
7483 to be excluded are given as a pattern on the command line. Use
7484 @option{--exclude-from} to introduce the name of a file which contains
7485 a list of patterns, one per line; each of these patterns can exclude
7486 zero, one, or many files.
7487
7488 @item
7489 When you use @option{--exclude=@var{pattern}}, be sure to quote the
7490 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
7491 like @samp{*}. If you do not do this, the shell might expand the
7492 @samp{*} itself using files at hand, so @command{tar} might receive a
7493 list of files instead of one pattern, or none at all, making the
7494 command somewhat illegal. This might not correspond to what you want.
7495
7496 For example, write:
7497
7498 @smallexample
7499 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
7500 @end smallexample
7501
7502 @noindent
7503 rather than:
7504
7505 @smallexample
7506 # @emph{Wrong!}
7507 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
7508 @end smallexample
7509
7510 @item
7511 You must use use shell syntax, or globbing, rather than @code{regexp}
7512 syntax, when using exclude options in @command{tar}. If you try to use
7513 @code{regexp} syntax to describe files to be excluded, your command
7514 might fail.
7515
7516 @item
7517 @FIXME{The change in semantics must have occurred before 1.11,
7518 so I doubt if it is worth mentioning at all. Anyway, should at
7519 least specify in which version the semantics changed.}
7520 In earlier versions of @command{tar}, what is now the
7521 @option{--exclude-from} option was called @option{--exclude} instead.
7522 Now, @option{--exclude} applies to patterns listed on the command
7523 line and @option{--exclude-from} applies to patterns listed in a
7524 file.
7525
7526 @end itemize
7527
7528 @node wildcards
7529 @section Wildcards Patterns and Matching
7530
7531 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
7532 @samp{*} or @samp{?} for example, are replaced and expanded into all
7533 existing files matching the given pattern. @GNUTAR{} can use wildcard
7534 patterns for matching (or globbing) archive members when extracting
7535 from or listing an archive. Wildcard patterns are also used for
7536 verifying volume labels of @command{tar} archives. This section has the
7537 purpose of explaining wildcard syntax for @command{tar}.
7538
7539 @FIXME{the next few paragraphs need work.}
7540
7541 A @var{pattern} should be written according to shell syntax, using wildcard
7542 characters to effect globbing. Most characters in the pattern stand
7543 for themselves in the matched string, and case is significant: @samp{a}
7544 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
7545 pattern matches any single character in the matched string. The character
7546 @samp{*} in the pattern matches zero, one, or more single characters in
7547 the matched string. The character @samp{\} says to take the following
7548 character of the pattern @emph{literally}; it is useful when one needs to
7549 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
7550
7551 The character @samp{[}, up to the matching @samp{]}, introduces a character
7552 class. A @dfn{character class} is a list of acceptable characters
7553 for the next single character of the matched string. For example,
7554 @samp{[abcde]} would match any of the first five letters of the alphabet.
7555 Note that within a character class, all of the ``special characters''
7556 listed above other than @samp{\} lose their special meaning; for example,
7557 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
7558 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
7559 the characters @samp{-} and @samp{]} must either come @emph{first} or
7560 @emph{last} in a character class.)
7561
7562 @cindex Excluding characters from a character class
7563 @cindex Character class, excluding characters from
7564 If the first character of the class after the opening @samp{[}
7565 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
7566 Rather than listing character to match, it lists those characters which
7567 are @emph{forbidden} as the next single character of the matched string.
7568
7569 Other characters of the class stand for themselves. The special
7570 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
7571 letters, is meant to represent all characters between @var{a} and
7572 @var{e}, inclusive.
7573
7574 @FIXME{need to add a sentence or so here to make this clear for those
7575 who don't have dan around.}
7576
7577 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
7578 special for wildcard matches. However, if a pattern completely matches
7579 a directory prefix of a matched string, then it matches the full matched
7580 string: thus, excluding a directory also excludes all the files beneath it.
7581
7582 @menu
7583 * controlling pattern-matching::
7584 @end menu
7585
7586 @node controlling pattern-matching
7587 @unnumberedsubsec Controlling Pattern-Matching
7588
7589 For the purposes of this section, we call @dfn{exclusion members} all
7590 member names obtained while processing @option{--exclude} and
7591 @option{--exclude-from} options, and @dfn{inclusion members} those
7592 member names that were given in the command line or read from the file
7593 specified with @option{--files-from} option.
7594
7595 These two pairs of member lists are used in the following operations:
7596 @option{--diff}, @option{--extract}, @option{--list},
7597 @option{--update}.
7598
7599 There are no inclusion members in create mode (@option{--create} and
7600 @option{--append}), since in this mode the names obtained from the
7601 command line refer to @emph{files}, not archive members.
7602
7603 By default, inclusion members are compared with archive members
7604 literally @footnote{Notice that earlier @GNUTAR{} versions used
7605 globbing for inclusion members, which contradicted to UNIX98
7606 specification and was not documented. @xref{Changes}, for more
7607 information on this and other changes.} and exclusion members are
7608 treated as globbing patterns. For example:
7609
7610 @smallexample
7611 @group
7612 $ @kbd{tar tf foo.tar}
7613 a.c
7614 b.c
7615 a.txt
7616 [remarks]
7617 # @i{Member names are used verbatim:}
7618 $ @kbd{tar -xf foo.tar -v '[remarks]'}
7619 [remarks]
7620 # @i{Exclude member names are globbed:}
7621 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
7622 a.txt
7623 [remarks]
7624 @end group
7625 @end smallexample
7626
7627 This behavior can be altered by using the following options:
7628
7629 @table @option
7630 @opindex wildcards
7631 @item --wildcards
7632 Treat all member names as wildcards.
7633
7634 @opindex no-wildcards
7635 @item --no-wildcards
7636 Treat all member names as literal strings.
7637 @end table
7638
7639 Thus, to extract files whose names end in @samp{.c}, you can use:
7640
7641 @smallexample
7642 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
7643 a.c
7644 b.c
7645 @end smallexample
7646
7647 @noindent
7648 Notice quoting of the pattern to prevent the shell from interpreting
7649 it.
7650
7651 The effect of @option{--wildcards} option is canceled by
7652 @option{--no-wildcards}. This can be used to pass part of
7653 the command line arguments verbatim and other part as globbing
7654 patterns. For example, the following invocation:
7655
7656 @smallexample
7657 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
7658 @end smallexample
7659
7660 @noindent
7661 instructs @command{tar} to extract from @file{foo.tar} all files whose
7662 names end in @samp{.txt} and the file named @file{[remarks]}.
7663
7664 Normally, a pattern matches a name if an initial subsequence of the
7665 name's components matches the pattern, where @samp{*}, @samp{?}, and
7666 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
7667 and wildcards can match @samp{/}.
7668
7669 Other than optionally stripping leading @samp{/} from names
7670 (@pxref{absolute}), patterns and names are used as-is. For
7671 example, trailing @samp{/} is not trimmed from a user-specified name
7672 before deciding whether to exclude it.
7673
7674 However, this matching procedure can be altered by the options listed
7675 below. These options accumulate. For example:
7676
7677 @smallexample
7678 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
7679 @end smallexample
7680
7681 @noindent
7682 ignores case when excluding @samp{makefile}, but not when excluding
7683 @samp{readme}.
7684
7685 @table @option
7686 @opindex anchored
7687 @opindex no-anchored
7688 @item --anchored
7689 @itemx --no-anchored
7690 If anchored, a pattern must match an initial subsequence
7691 of the name's components. Otherwise, the pattern can match any
7692 subsequence. Default is @option{--no-anchored} for exclusion members
7693 and @option{--anchored} inclusion members.
7694
7695 @opindex ignore-case
7696 @opindex no-ignore-case
7697 @item --ignore-case
7698 @itemx --no-ignore-case
7699 When ignoring case, upper-case patterns match lower-case names and vice versa.
7700 When not ignoring case (the default), matching is case-sensitive.
7701
7702 @opindex wildcards-match-slash
7703 @opindex no-wildcards-match-slash
7704 @item --wildcards-match-slash
7705 @itemx --no-wildcards-match-slash
7706 When wildcards match slash (the default for exclusion members), a
7707 wildcard like @samp{*} in the pattern can match a @samp{/} in the
7708 name. Otherwise, @samp{/} is matched only by @samp{/}.
7709
7710 @end table
7711
7712 The @option{--recursion} and @option{--no-recursion} options
7713 (@pxref{recurse}) also affect how member patterns are interpreted. If
7714 recursion is in effect, a pattern matches a name if it matches any of
7715 the name's parent directories.
7716
7717 The following table summarizes pattern-matching default values:
7718
7719 @multitable @columnfractions .3 .7
7720 @headitem Members @tab Default settings
7721 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
7722 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
7723 @end multitable
7724
7725 @node quoting styles
7726 @section Quoting Member Names
7727
7728 When displaying member names, @command{tar} takes care to avoid
7729 ambiguities caused by certain characters. This is called @dfn{name
7730 quoting}. The characters in question are:
7731
7732 @itemize @bullet
7733 @item Non-printable control characters:
7734 @anchor{escape sequences}
7735 @multitable @columnfractions 0.20 0.10 0.60
7736 @headitem Character @tab @acronym{ASCII} @tab Character name
7737 @item \a @tab 7 @tab Audible bell
7738 @item \b @tab 8 @tab Backspace
7739 @item \f @tab 12 @tab Form feed
7740 @item \n @tab 10 @tab New line
7741 @item \r @tab 13 @tab Carriage return
7742 @item \t @tab 9 @tab Horizontal tabulation
7743 @item \v @tab 11 @tab Vertical tabulation
7744 @end multitable
7745
7746 @item Space (@acronym{ASCII} 32)
7747
7748 @item Single and double quotes (@samp{'} and @samp{"})
7749
7750 @item Backslash (@samp{\})
7751 @end itemize
7752
7753 The exact way @command{tar} uses to quote these characters depends on
7754 the @dfn{quoting style}. The default quoting style, called
7755 @dfn{escape} (see below), uses backslash notation to represent control
7756 characters, space and backslash. Using this quoting style, control
7757 characters are represented as listed in column @samp{Character} in the
7758 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
7759
7760 @GNUTAR{} offers seven distinct quoting styles, which can be selected
7761 using @option{--quoting-style} option:
7762
7763 @table @option
7764 @item --quoting-style=@var{style}
7765 @opindex quoting-style
7766
7767 Sets quoting style. Valid values for @var{style} argument are:
7768 literal, shell, shell-always, c, escape, locale, clocale.
7769 @end table
7770
7771 These styles are described in detail below. To illustrate their
7772 effect, we will use an imaginary tar archive @file{arch.tar}
7773 containing the following members:
7774
7775 @smallexample
7776 @group
7777 # 1. Contains horizontal tabulation character.
7778 a tab
7779 # 2. Contains newline character
7780 a
7781 newline
7782 # 3. Contains a space
7783 a space
7784 # 4. Contains double quotes
7785 a"double"quote
7786 # 5. Contains single quotes
7787 a'single'quote
7788 # 6. Contains a backslash character:
7789 a\backslash
7790 @end group
7791 @end smallexample
7792
7793 Here is how usual @command{ls} command would have listed them, if they
7794 had existed in the current working directory:
7795
7796 @smallexample
7797 @group
7798 $ @kbd{ls}
7799 a\ttab
7800 a\nnewline
7801 a\ space
7802 a"double"quote
7803 a'single'quote
7804 a\\backslash
7805 @end group
7806 @end smallexample
7807
7808 Quoting styles:
7809
7810 @table @samp
7811 @item literal
7812 No quoting, display each character as is:
7813
7814 @smallexample
7815 @group
7816 $ @kbd{tar tf arch.tar --quoting-style=literal}
7817 ./
7818 ./a space
7819 ./a'single'quote
7820 ./a"double"quote
7821 ./a\backslash
7822 ./a tab
7823 ./a
7824 newline
7825 @end group
7826 @end smallexample
7827
7828 @item shell
7829 Display characters the same way Bourne shell does:
7830 control characters, except @samp{\t} and @samp{\n}, are printed using
7831 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
7832 single quote is printed as @samp{\'}. If a name contains any quoted
7833 characters, it is enclosed in single quotes. In particular, if a name
7834 contains single quotes, it is printed as several single-quoted strings:
7835
7836 @smallexample
7837 @group
7838 $ @kbd{tar tf arch.tar --quoting-style=shell}
7839 ./
7840 './a space'
7841 './a'\''single'\''quote'
7842 './a"double"quote'
7843 './a\backslash'
7844 './a tab'
7845 './a
7846 newline'
7847 @end group
7848 @end smallexample
7849
7850 @item shell-always
7851 Same as @samp{shell}, but the names are always enclosed in single
7852 quotes:
7853
7854 @smallexample
7855 @group
7856 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
7857 './'
7858 './a space'
7859 './a'\''single'\''quote'
7860 './a"double"quote'
7861 './a\backslash'
7862 './a tab'
7863 './a
7864 newline'
7865 @end group
7866 @end smallexample
7867
7868 @item c
7869 Use the notation of the C programming language. All names are
7870 enclosed in double quotes. Control characters are quoted using
7871 backslash notations, double quotes are represented as @samp{\"},
7872 backslash characters are represented as @samp{\\}. Single quotes and
7873 spaces are not quoted:
7874
7875 @smallexample
7876 @group
7877 $ @kbd{tar tf arch.tar --quoting-style=c}
7878 "./"
7879 "./a space"
7880 "./a'single'quote"
7881 "./a\"double\"quote"
7882 "./a\\backslash"
7883 "./a\ttab"
7884 "./a\nnewline"
7885 @end group
7886 @end smallexample
7887
7888 @item escape
7889 Control characters are printed using backslash notation, a space is
7890 printed as @samp{\ } and a backslash as @samp{\\}. This is the
7891 default quoting style, unless it was changed when configured the
7892 package.
7893
7894 @smallexample
7895 @group
7896 $ @kbd{tar tf arch.tar --quoting-style=escape}
7897 ./
7898 ./a space
7899 ./a'single'quote
7900 ./a"double"quote
7901 ./a\\backslash
7902 ./a\ttab
7903 ./a\nnewline
7904 @end group
7905 @end smallexample
7906
7907 @item locale
7908 Control characters, single quote and backslash are printed using
7909 backslash notation. All names are quoted using left and right
7910 quotation marks, appropriate to the current locale. If it does not
7911 define quotation marks, use @samp{'} as left and as right
7912 quotation marks. Any occurrences of the right quotation mark in a
7913 name are escaped with @samp{\}, for example:
7914
7915 For example:
7916
7917 @smallexample
7918 @group
7919 $ @kbd{tar tf arch.tar --quoting-style=locale}
7920 './'
7921 './a space'
7922 './a\'single\'quote'
7923 './a"double"quote'
7924 './a\\backslash'
7925 './a\ttab'
7926 './a\nnewline'
7927 @end group
7928 @end smallexample
7929
7930 @item clocale
7931 Same as @samp{locale}, but @samp{"} is used for both left and right
7932 quotation marks, if not provided by the currently selected locale:
7933
7934 @smallexample
7935 @group
7936 $ @kbd{tar tf arch.tar --quoting-style=clocale}
7937 "./"
7938 "./a space"
7939 "./a'single'quote"
7940 "./a\"double\"quote"
7941 "./a\\backslash"
7942 "./a\ttab"
7943 "./a\nnewline"
7944 @end group
7945 @end smallexample
7946 @end table
7947
7948 You can specify which characters should be quoted in addition to those
7949 implied by the current quoting style:
7950
7951 @table @option
7952 @item --quote-chars=@var{string}
7953 Always quote characters from @var{string}, even if the selected
7954 quoting style would not quote them.
7955 @end table
7956
7957 For example, using @samp{escape} quoting (compare with the usual
7958 escape listing above):
7959
7960 @smallexample
7961 @group
7962 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7963 ./
7964 ./a\ space
7965 ./a'single'quote
7966 ./a\"double\"quote
7967 ./a\\backslash
7968 ./a\ttab
7969 ./a\nnewline
7970 @end group
7971 @end smallexample
7972
7973 To disable quoting of such additional characters, use the following
7974 option:
7975
7976 @table @option
7977 @item --no-quote-chars=@var{string}
7978 Remove characters listed in @var{string} from the list of quoted
7979 characters set by the previous @option{--quote-chars} option.
7980 @end table
7981
7982 This option is particularly useful if you have added
7983 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7984 and wish to disable it for the current invocation.
7985
7986 Note, that @option{--no-quote-chars} does @emph{not} disable those
7987 characters that are quoted by default in the selected quoting style.
7988
7989 @node transform
7990 @section Modifying File and Member Names
7991
7992 @command{Tar} archives contain detailed information about files stored
7993 in them and full file names are part of that information. When
7994 storing a file to an archive, its file name is recorded in it,
7995 along with the actual file contents. When restoring from an archive,
7996 a file is created on disk with exactly the same name as that stored
7997 in the archive. In the majority of cases this is the desired behavior
7998 of a file archiver. However, there are some cases when it is not.
7999
8000 First of all, it is often unsafe to extract archive members with
8001 absolute file names or those that begin with a @file{../}. @GNUTAR{}
8002 takes special precautions when extracting such names and provides a
8003 special option for handling them, which is described in
8004 @ref{absolute}.
8005
8006 Secondly, you may wish to extract file names without some leading
8007 directory components, or with otherwise modified names. In other
8008 cases it is desirable to store files under differing names in the
8009 archive.
8010
8011 @GNUTAR{} provides several options for these needs.
8012
8013 @table @option
8014 @opindex strip-components
8015 @item --strip-components=@var{number}
8016 Strip given @var{number} of leading components from file names before
8017 extraction.
8018 @end table
8019
8020 For example, suppose you have archived whole @file{/usr} hierarchy to
8021 a tar archive named @file{usr.tar}. Among other files, this archive
8022 contains @file{usr/include/stdlib.h}, which you wish to extract to
8023 the current working directory. To do so, you type:
8024
8025 @smallexample
8026 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
8027 @end smallexample
8028
8029 The option @option{--strip=2} instructs @command{tar} to strip the
8030 two leading components (@file{usr/} and @file{include/}) off the file
8031 name.
8032
8033 If you add the @option{--verbose} (@option{-v}) option to the invocation
8034 above, you will note that the verbose listing still contains the
8035 full file name, with the two removed components still in place. This
8036 can be inconvenient, so @command{tar} provides a special option for
8037 altering this behavior:
8038
8039 @anchor{show-transformed-names}
8040 @table @option
8041 @opindex show-transformed-names
8042 @item --show-transformed-names
8043 Display file or member names with all requested transformations
8044 applied.
8045 @end table
8046
8047 @noindent
8048 For example:
8049
8050 @smallexample
8051 @group
8052 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
8053 usr/include/stdlib.h
8054 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
8055 stdlib.h
8056 @end group
8057 @end smallexample
8058
8059 Notice that in both cases the file @file{stdlib.h} is extracted to the
8060 current working directory, @option{--show-transformed-names} affects
8061 only the way its name is displayed.
8062
8063 This option is especially useful for verifying whether the invocation
8064 will have the desired effect. Thus, before running
8065
8066 @smallexample
8067 $ @kbd{tar -x --strip=@var{n}}
8068 @end smallexample
8069
8070 @noindent
8071 it is often advisable to run
8072
8073 @smallexample
8074 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
8075 @end smallexample
8076
8077 @noindent
8078 to make sure the command will produce the intended results.
8079
8080 In case you need to apply more complex modifications to the file name,
8081 @GNUTAR{} provides a general-purpose transformation option:
8082
8083 @table @option
8084 @opindex transform
8085 @opindex xform
8086 @item --transform=@var{expression}
8087 @itemx --xform=@var{expression}
8088 Modify file names using supplied @var{expression}.
8089 @end table
8090
8091 @noindent
8092 The @var{expression} is a @command{sed}-like replace expression of the
8093 form:
8094
8095 @smallexample
8096 s/@var{regexp}/@var{replace}/[@var{flags}]
8097 @end smallexample
8098
8099 @noindent
8100 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
8101 replacement for each file name part that matches @var{regexp}. Both
8102 @var{regexp} and @var{replace} are described in detail in
8103 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
8104
8105 Any delimiter can be used in lieu of @samp{/}, the only requirement being
8106 that it be used consistently throughout the expression. For example,
8107 the following two expressions are equivalent:
8108
8109 @smallexample
8110 @group
8111 s/one/two/
8112 s,one,two,
8113 @end group
8114 @end smallexample
8115
8116 Changing delimiters is often useful when the @var{regex} contains
8117 slashes. For example, it is more convenient to write @code{s,/,-,} than
8118 @code{s/\//-/}.
8119
8120 As in @command{sed}, you can give several replace expressions,
8121 separated by a semicolon.
8122
8123 Supported @var{flags} are:
8124
8125 @table @samp
8126 @item g
8127 Apply the replacement to @emph{all} matches to the @var{regexp}, not
8128 just the first.
8129
8130 @item i
8131 Use case-insensitive matching.
8132
8133 @item x
8134 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
8135 regexps, Extended regular expressions, Extended regular expressions,
8136 sed, GNU sed}).
8137
8138 @item @var{number}
8139 Only replace the @var{number}th match of the @var{regexp}.
8140
8141 Note: the @acronym{POSIX} standard does not specify what should happen
8142 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
8143 follows the GNU @command{sed} implementation in this regard, so
8144 the interaction is defined to be: ignore matches before the
8145 @var{number}th, and then match and replace all matches from the
8146 @var{number}th on.
8147
8148 @end table
8149
8150 In addition, several @dfn{transformation scope} flags are supported,
8151 that control to what files transformations apply. These are:
8152
8153 @table @samp
8154 @item r
8155 Apply transformation to regular archive members.
8156
8157 @item R
8158 Do not apply transformation to regular archive members.
8159
8160 @item s
8161 Apply transformation to symbolic link targets.
8162
8163 @item S
8164 Do not apply transformation to symbolic link targets.
8165
8166 @item h
8167 Apply transformation to hard link targets.
8168
8169 @item H
8170 Do not apply transformation to hard link targets.
8171 @end table
8172
8173 Default is @samp{rsh}, which means to apply tranformations to both archive
8174 members and targets of symbolic and hard links.
8175
8176 Default scope flags can also be changed using @samp{flags=} statement
8177 in the transform expression. The flags set this way remain in force
8178 until next @samp{flags=} statement or end of expression, whichever
8179 occurs first. For example:
8180
8181 @smallexample
8182 --transform 'flags=S;s|^|/usr/local/|'
8183 @end smallexample
8184
8185 Here are several examples of @option{--transform} usage:
8186
8187 @enumerate
8188 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
8189
8190 @smallexample
8191 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
8192 @end smallexample
8193
8194 @item Strip two leading directory components (equivalent to
8195 @option{--strip-components=2}):
8196
8197 @smallexample
8198 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
8199 @end smallexample
8200
8201 @item Convert each file name to lower case:
8202
8203 @smallexample
8204 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
8205 @end smallexample
8206
8207 @item Prepend @file{/prefix/} to each file name:
8208
8209 @smallexample
8210 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
8211 @end smallexample
8212
8213 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
8214 to each archive member:
8215
8216 @smallexample
8217 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
8218 @end smallexample
8219 @end enumerate
8220
8221 Notice the use of flags in the last example. The @file{/lib}
8222 directory often contains many symbolic links to files within it.
8223 It may look, for example, like this:
8224
8225 @smallexample
8226 $ @kbd{ls -l}
8227 drwxr-xr-x root/root 0 2008-07-08 16:20 /lib/
8228 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
8229 lrwxrwxrwx root/root 0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
8230 ...
8231 @end smallexample
8232
8233 Using the expression @samp{s,^,/usr/local/,} would mean adding
8234 @samp{/usr/local} to both regular archive members and to link
8235 targets. In this case, @file{/lib/libc.so.6} would become:
8236
8237 @smallexample
8238 /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
8239 @end smallexample
8240
8241 This is definitely not desired. To avoid this, the @samp{S} flag
8242 is used, which excludes symbolic link targets from filename
8243 transformations. The result is:
8244
8245 @smallexample
8246 $ @kbd{tar --transform 's,^,/usr/local/,S', -c -v -f arch.tar \
8247 --show-transformed /lib}
8248 drwxr-xr-x root/root 0 2008-07-08 16:20 /usr/local/lib/
8249 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
8250 lrwxrwxrwx root/root 0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
8251 -> libc-2.3.2.so
8252 @end smallexample
8253
8254 Unlike @option{--strip-components}, @option{--transform} can be used
8255 in any @GNUTAR{} operation mode. For example, the following command
8256 adds files to the archive while replacing the leading @file{usr/}
8257 component with @file{var/}:
8258
8259 @smallexample
8260 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
8261 @end smallexample
8262
8263 To test @option{--transform} effect we suggest using
8264 @option{--show-transformed-names} option:
8265
8266 @smallexample
8267 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
8268 --verbose --show-transformed-names /}
8269 @end smallexample
8270
8271 If both @option{--strip-components} and @option{--transform} are used
8272 together, then @option{--transform} is applied first, and the required
8273 number of components is then stripped from its result.
8274
8275 You can use as many @option{--transform} options in a single command
8276 line as you want. The specified expressions will then be applied in
8277 order of their appearance. For example, the following two invocations
8278 are equivalent:
8279
8280 @smallexample
8281 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
8282 --transform='s,/usr/local,/usr/,'}
8283 $ @kbd{tar -cf arch.tar \
8284 --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
8285 @end smallexample
8286
8287 @node after
8288 @section Operating Only on New Files
8289
8290 @cindex Excluding file by age
8291 @cindex Data Modification time, excluding files by
8292 @cindex Modification time, excluding files by
8293 @cindex Age, excluding files by
8294 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
8295 @option{-N @var{date}}) option causes @command{tar} to only work on
8296 files whose data modification or status change times are newer than
8297 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
8298 it is taken to be a file name; the data modification time of that file
8299 is used as the date. If you use this option when creating or appending
8300 to an archive, the archive will only include new files. If you use
8301 @option{--after-date} when extracting an archive, @command{tar} will
8302 only extract files newer than the @var{date} you specify.
8303
8304 If you only want @command{tar} to make the date comparison based on
8305 modification of the file's data (rather than status
8306 changes), then use the @option{--newer-mtime=@var{date}} option.
8307
8308 @cindex --after-date and --update compared
8309 @cindex --newer-mtime and --update compared
8310 You may use these options with any operation. Note that these options
8311 differ from the @option{--update} (@option{-u}) operation in that they
8312 allow you to specify a particular date against which @command{tar} can
8313 compare when deciding whether or not to archive the files.
8314
8315 @table @option
8316 @opindex after-date
8317 @opindex newer
8318 @item --after-date=@var{date}
8319 @itemx --newer=@var{date}
8320 @itemx -N @var{date}
8321 Only store files newer than @var{date}.
8322
8323 Acts on files only if their data modification or status change times are
8324 later than @var{date}. Use in conjunction with any operation.
8325
8326 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
8327 name; the data modification time of that file is used as the date.
8328
8329 @opindex newer-mtime
8330 @item --newer-mtime=@var{date}
8331 Acts like @option{--after-date}, but only looks at data modification times.
8332 @end table
8333
8334 These options limit @command{tar} to operate only on files which have
8335 been modified after the date specified. A file's status is considered to have
8336 changed if its contents have been modified, or if its owner,
8337 permissions, and so forth, have been changed. (For more information on
8338 how to specify a date, see @ref{Date input formats}; remember that the
8339 entire date argument must be quoted if it contains any spaces.)
8340
8341 Gurus would say that @option{--after-date} tests both the data
8342 modification time (@code{mtime}, the time the contents of the file
8343 were last modified) and the status change time (@code{ctime}, the time
8344 the file's status was last changed: owner, permissions, etc.@:)
8345 fields, while @option{--newer-mtime} tests only the @code{mtime}
8346 field.
8347
8348 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
8349 @code{ctime} and processes the file if either one is more recent than
8350 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
8351 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
8352 contents of the file were looked at).
8353
8354 Date specifiers can have embedded spaces. Because of this, you may need
8355 to quote date arguments to keep the shell from parsing them as separate
8356 arguments. For example, the following command will add to the archive
8357 all the files modified less than two days ago:
8358
8359 @smallexample
8360 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
8361 @end smallexample
8362
8363 When any of these options is used with the option @option{--verbose}
8364 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
8365 date back to its textual representation and compare that with the
8366 one given with the option. If the two dates differ, @command{tar} will
8367 print a warning saying what date it will use. This is to help user
8368 ensure he is using the right date. For example:
8369
8370 @smallexample
8371 @group
8372 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
8373 tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
8374 13:19:37.232434
8375 @end group
8376 @end smallexample
8377
8378 @quotation
8379 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
8380 should not be used for incremental backups. @xref{Incremental Dumps},
8381 for proper way of creating incremental backups.
8382 @end quotation
8383
8384 @node recurse
8385 @section Descending into Directories
8386 @cindex Avoiding recursion in directories
8387 @cindex Descending directories, avoiding
8388 @cindex Directories, avoiding recursion
8389 @cindex Recursion in directories, avoiding
8390
8391 Usually, @command{tar} will recursively explore all directories (either
8392 those given on the command line or through the @option{--files-from}
8393 option) for the various files they contain. However, you may not always
8394 want @command{tar} to act this way.
8395
8396 @opindex no-recursion
8397 @cindex @command{find}, using with @command{tar}
8398 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
8399 into specified directories. If you specify @option{--no-recursion}, you can
8400 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
8401 utility for hunting through levels of directories to
8402 construct a list of file names which you could then pass to @command{tar}.
8403 @command{find} allows you to be more selective when choosing which files to
8404 archive; see @ref{files}, for more information on using @command{find} with
8405 @command{tar}.
8406
8407 @table @option
8408 @item --no-recursion
8409 Prevents @command{tar} from recursively descending directories.
8410
8411 @opindex recursion
8412 @item --recursion
8413 Requires @command{tar} to recursively descend directories.
8414 This is the default.
8415 @end table
8416
8417 When you use @option{--no-recursion}, @GNUTAR{} grabs
8418 directory entries themselves, but does not descend on them
8419 recursively. Many people use @command{find} for locating files they
8420 want to back up, and since @command{tar} @emph{usually} recursively
8421 descends on directories, they have to use the @samp{@w{-not -type d}}
8422 test in their @command{find} invocation (@pxref{Type, Type, Type test,
8423 find, Finding Files}), as they usually do not want all the files in a
8424 directory. They then use the @option{--files-from} option to archive
8425 the files located via @command{find}.
8426
8427 The problem when restoring files archived in this manner is that the
8428 directories themselves are not in the archive; so the
8429 @option{--same-permissions} (@option{--preserve-permissions},
8430 @option{-p}) option does not affect them---while users might really
8431 like it to. Specifying @option{--no-recursion} is a way to tell
8432 @command{tar} to grab only the directory entries given to it, adding
8433 no new files on its own. To summarize, if you use @command{find} to
8434 create a list of files to be stored in an archive, use it as follows:
8435
8436 @smallexample
8437 @group
8438 $ @kbd{find @var{dir} @var{tests} | \
8439 tar -cf @var{archive} -T - --no-recursion}
8440 @end group
8441 @end smallexample
8442
8443 The @option{--no-recursion} option also applies when extracting: it
8444 causes @command{tar} to extract only the matched directory entries, not
8445 the files under those directories.
8446
8447 The @option{--no-recursion} option also affects how globbing patterns
8448 are interpreted (@pxref{controlling pattern-matching}).
8449
8450 The @option{--no-recursion} and @option{--recursion} options apply to
8451 later options and operands, and can be overridden by later occurrences
8452 of @option{--no-recursion} and @option{--recursion}. For example:
8453
8454 @smallexample
8455 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
8456 @end smallexample
8457
8458 @noindent
8459 creates an archive with one entry for @file{grape}, and the recursive
8460 contents of @file{grape/concord}, but no entries under @file{grape}
8461 other than @file{grape/concord}.
8462
8463 @node one
8464 @section Crossing File System Boundaries
8465 @cindex File system boundaries, not crossing
8466
8467 @command{tar} will normally automatically cross file system boundaries in
8468 order to archive files which are part of a directory tree. You can
8469 change this behavior by running @command{tar} and specifying
8470 @option{--one-file-system}. This option only affects files that are
8471 archived because they are in a directory that is being archived;
8472 @command{tar} will still archive files explicitly named on the command line
8473 or through @option{--files-from}, regardless of where they reside.
8474
8475 @table @option
8476 @opindex one-file-system
8477 @item --one-file-system
8478 Prevents @command{tar} from crossing file system boundaries when
8479 archiving. Use in conjunction with any write operation.
8480 @end table
8481
8482 The @option{--one-file-system} option causes @command{tar} to modify its
8483 normal behavior in archiving the contents of directories. If a file in
8484 a directory is not on the same file system as the directory itself, then
8485 @command{tar} will not archive that file. If the file is a directory
8486 itself, @command{tar} will not archive anything beneath it; in other words,
8487 @command{tar} will not cross mount points.
8488
8489 This option is useful for making full or incremental archival backups of
8490 a file system. If this option is used in conjunction with
8491 @option{--verbose} (@option{-v}), files that are excluded are
8492 mentioned by name on the standard error.
8493
8494 @menu
8495 * directory:: Changing Directory
8496 * absolute:: Absolute File Names
8497 @end menu
8498
8499 @node directory
8500 @subsection Changing the Working Directory
8501
8502 @FIXME{need to read over this node now for continuity; i've switched
8503 things around some.}
8504
8505 @cindex Changing directory mid-stream
8506 @cindex Directory, changing mid-stream
8507 @cindex Working directory, specifying
8508 To change the working directory in the middle of a list of file names,
8509 either on the command line or in a file specified using
8510 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
8511 This will change the working directory to the specified directory
8512 after that point in the list.
8513
8514 @table @option
8515 @opindex directory
8516 @item --directory=@var{directory}
8517 @itemx -C @var{directory}
8518 Changes the working directory in the middle of a command line.
8519 @end table
8520
8521 For example,
8522
8523 @smallexample
8524 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
8525 @end smallexample
8526
8527 @noindent
8528 will place the files @file{grape} and @file{prune} from the current
8529 directory into the archive @file{jams.tar}, followed by the file
8530 @file{cherry} from the directory @file{food}. This option is especially
8531 useful when you have several widely separated files that you want to
8532 store in the same archive.
8533
8534 Note that the file @file{cherry} is recorded in the archive under the
8535 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
8536 archive will contain three files that all appear to have come from the
8537 same directory; if the archive is extracted with plain @samp{tar
8538 --extract}, all three files will be written in the current directory.
8539
8540 Contrast this with the command,
8541
8542 @smallexample
8543 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
8544 @end smallexample
8545
8546 @noindent
8547 which records the third file in the archive under the name
8548 @file{red/cherry} so that, if the archive is extracted using
8549 @samp{tar --extract}, the third file will be written in a subdirectory
8550 named @file{red}.
8551
8552 You can use the @option{--directory} option to make the archive
8553 independent of the original name of the directory holding the files.
8554 The following command places the files @file{/etc/passwd},
8555 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
8556 @file{foo.tar}:
8557
8558 @smallexample
8559 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
8560 @end smallexample
8561
8562 @noindent
8563 However, the names of the archive members will be exactly what they were
8564 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
8565 They will not appear to be related by file name to the original
8566 directories where those files were located.
8567
8568 Note that @option{--directory} options are interpreted consecutively. If
8569 @option{--directory} specifies a relative file name, it is interpreted
8570 relative to the then current directory, which might not be the same as
8571 the original current working directory of @command{tar}, due to a previous
8572 @option{--directory} option.
8573
8574 When using @option{--files-from} (@pxref{files}), you can put various
8575 @command{tar} options (including @option{-C}) in the file list. Notice,
8576 however, that in this case the option and its argument may not be
8577 separated by whitespace. If you use short option, its argument must
8578 either follow the option letter immediately, without any intervening
8579 whitespace, or occupy the next line. Otherwise, if you use long
8580 option, separate its argument by an equal sign.
8581
8582 For instance, the file list for the above example will be:
8583
8584 @smallexample
8585 @group
8586 -C/etc
8587 passwd
8588 hosts
8589 --directory=/lib
8590 libc.a
8591 @end group
8592 @end smallexample
8593
8594 @noindent
8595 To use it, you would invoke @command{tar} as follows:
8596
8597 @smallexample
8598 $ @kbd{tar -c -f foo.tar --files-from list}
8599 @end smallexample
8600
8601 The interpretation of @option{--directory} is disabled by
8602 @option{--null} option.
8603
8604 @node absolute
8605 @subsection Absolute File Names
8606 @cindex absolute file names
8607 @cindex file names, absolute
8608
8609 By default, @GNUTAR{} drops a leading @samp{/} on
8610 input or output, and complains about file names containing a @file{..}
8611 component. There is an option that turns off this behavior:
8612
8613 @table @option
8614 @opindex absolute-names
8615 @item --absolute-names
8616 @itemx -P
8617 Do not strip leading slashes from file names, and permit file names
8618 containing a @file{..} file name component.
8619 @end table
8620
8621 When @command{tar} extracts archive members from an archive, it strips any
8622 leading slashes (@samp{/}) from the member name. This causes absolute
8623 member names in the archive to be treated as relative file names. This
8624 allows you to have such members extracted wherever you want, instead of
8625 being restricted to extracting the member in the exact directory named
8626 in the archive. For example, if the archive member has the name
8627 @file{/etc/passwd}, @command{tar} will extract it as if the name were
8628 really @file{etc/passwd}.
8629
8630 File names containing @file{..} can cause problems when extracting, so
8631 @command{tar} normally warns you about such files when creating an
8632 archive, and rejects attempts to extracts such files.
8633
8634 Other @command{tar} programs do not do this. As a result, if you
8635 create an archive whose member names start with a slash, they will be
8636 difficult for other people with a non-@GNUTAR{}
8637 program to use. Therefore, @GNUTAR{} also strips
8638 leading slashes from member names when putting members into the
8639 archive. For example, if you ask @command{tar} to add the file
8640 @file{/bin/ls} to an archive, it will do so, but the member name will
8641 be @file{bin/ls}@footnote{A side effect of this is that when
8642 @option{--create} is used with @option{--verbose} the resulting output
8643 is not, generally speaking, the same as the one you'd get running
8644 @kbd{tar --list} command. This may be important if you use some
8645 scripts for comparing both outputs. @xref{listing member and file names},
8646 for the information on how to handle this case.}.
8647
8648 Symbolic links containing @file{..} or leading @samp{/} can also cause
8649 problems when extracting, so @command{tar} normally extracts them last;
8650 it may create empty files as placeholders during extraction.
8651
8652 If you use the @option{--absolute-names} (@option{-P}) option,
8653 @command{tar} will do none of these transformations.
8654
8655 To archive or extract files relative to the root directory, specify
8656 the @option{--absolute-names} (@option{-P}) option.
8657
8658 Normally, @command{tar} acts on files relative to the working
8659 directory---ignoring superior directory names when archiving, and
8660 ignoring leading slashes when extracting.
8661
8662 When you specify @option{--absolute-names} (@option{-P}),
8663 @command{tar} stores file names including all superior directory
8664 names, and preserves leading slashes. If you only invoked
8665 @command{tar} from the root directory you would never need the
8666 @option{--absolute-names} option, but using this option
8667 may be more convenient than switching to root.
8668
8669 @FIXME{Should be an example in the tutorial/wizardry section using this
8670 to transfer files between systems.}
8671
8672 @table @option
8673 @item --absolute-names
8674 Preserves full file names (including superior directory names) when
8675 archiving and extracting files.
8676
8677 @end table
8678
8679 @command{tar} prints out a message about removing the @samp{/} from
8680 file names. This message appears once per @GNUTAR{}
8681 invocation. It represents something which ought to be told; ignoring
8682 what it means can cause very serious surprises, later.
8683
8684 Some people, nevertheless, do not want to see this message. Wanting to
8685 play really dangerously, one may of course redirect @command{tar} standard
8686 error to the sink. For example, under @command{sh}:
8687
8688 @smallexample
8689 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
8690 @end smallexample
8691
8692 @noindent
8693 Another solution, both nicer and simpler, would be to change to
8694 the @file{/} directory first, and then avoid absolute notation.
8695 For example:
8696
8697 @smallexample
8698 $ @kbd{tar -c -f archive.tar -C / home}
8699 @end smallexample
8700
8701 @xref{Integrity}, for some of the security-related implications
8702 of using this option.
8703
8704 @include parse-datetime.texi
8705
8706 @node Formats
8707 @chapter Controlling the Archive Format
8708
8709 @cindex Tar archive formats
8710 Due to historical reasons, there are several formats of tar archives.
8711 All of them are based on the same principles, but have some subtle
8712 differences that often make them incompatible with each other.
8713
8714 GNU tar is able to create and handle archives in a variety of formats.
8715 The most frequently used formats are (in alphabetical order):
8716
8717 @table @asis
8718 @item gnu
8719 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
8720 from an early @acronym{POSIX} standard, adding some improvements such as
8721 sparse file handling and incremental archives. Unfortunately these
8722 features were implemented in a way incompatible with other archive
8723 formats.
8724
8725 Archives in @samp{gnu} format are able to hold file names of unlimited
8726 length.
8727
8728 @item oldgnu
8729 Format used by @GNUTAR{} of versions prior to 1.12.
8730
8731 @item v7
8732 Archive format, compatible with the V7 implementation of tar. This
8733 format imposes a number of limitations. The most important of them
8734 are:
8735
8736 @enumerate
8737 @item The maximum length of a file name is limited to 99 characters.
8738 @item The maximum length of a symbolic link is limited to 99 characters.
8739 @item It is impossible to store special files (block and character
8740 devices, fifos etc.)
8741 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
8742 octal)
8743 @item V7 archives do not contain symbolic ownership information (user
8744 and group name of the file owner).
8745 @end enumerate
8746
8747 This format has traditionally been used by Automake when producing
8748 Makefiles. This practice will change in the future, in the meantime,
8749 however this means that projects containing file names more than 99
8750 characters long will not be able to use @GNUTAR{} @value{VERSION} and
8751 Automake prior to 1.9.
8752
8753 @item ustar
8754 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
8755 symbolic ownership information. It is also able to store
8756 special files. However, it imposes several restrictions as well:
8757
8758 @enumerate
8759 @item The maximum length of a file name is limited to 256 characters,
8760 provided that the file name can be split at a directory separator in
8761 two parts, first of them being at most 155 bytes long. So, in most
8762 cases the maximum file name length will be shorter than 256
8763 characters.
8764 @item The maximum length of a symbolic link name is limited to
8765 100 characters.
8766 @item Maximum size of a file the archive is able to accommodate
8767 is 8GB
8768 @item Maximum value of UID/GID is 2097151.
8769 @item Maximum number of bits in device major and minor numbers is 21.
8770 @end enumerate
8771
8772 @item star
8773 Format used by J@"org Schilling @command{star}
8774 implementation. @GNUTAR{} is able to read @samp{star} archives but
8775 currently does not produce them.
8776
8777 @item posix
8778 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
8779 most flexible and feature-rich format. It does not impose any
8780 restrictions on file sizes or file name lengths. This format is quite
8781 recent, so not all tar implementations are able to handle it properly.
8782 However, this format is designed in such a way that any tar
8783 implementation able to read @samp{ustar} archives will be able to read
8784 most @samp{posix} archives as well, with the only exception that any
8785 additional information (such as long file names etc.) will in such
8786 case be extracted as plain text files along with the files it refers to.
8787
8788 This archive format will be the default format for future versions
8789 of @GNUTAR{}.
8790
8791 @end table
8792
8793 The following table summarizes the limitations of each of these
8794 formats:
8795
8796 @multitable @columnfractions .10 .20 .20 .20 .20
8797 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
8798 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8799 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8800 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
8801 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
8802 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
8803 @end multitable
8804
8805 The default format for @GNUTAR{} is defined at compilation
8806 time. You may check it by running @command{tar --help}, and examining
8807 the last lines of its output. Usually, @GNUTAR{} is configured
8808 to create archives in @samp{gnu} format, however, future version will
8809 switch to @samp{posix}.
8810
8811 @menu
8812 * Compression:: Using Less Space through Compression
8813 * Attributes:: Handling File Attributes
8814 * Portability:: Making @command{tar} Archives More Portable
8815 * cpio:: Comparison of @command{tar} and @command{cpio}
8816 @end menu
8817
8818 @node Compression
8819 @section Using Less Space through Compression
8820
8821 @menu
8822 * gzip:: Creating and Reading Compressed Archives
8823 * sparse:: Archiving Sparse Files
8824 @end menu
8825
8826 @node gzip
8827 @subsection Creating and Reading Compressed Archives
8828 @cindex Compressed archives
8829 @cindex Storing archives in compressed format
8830
8831 @cindex gzip
8832 @cindex bzip2
8833 @cindex lzip
8834 @cindex lzma
8835 @cindex lzop
8836 @cindex compress
8837 @GNUTAR{} is able to create and read compressed archives. It supports
8838 a wide variety of compression programs, namely: @command{gzip},
8839 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
8840 @command{xz} and traditional @command{compress}. The latter is
8841 supported mostly for backward compatibility, and we recommend
8842 against using it, because it is by far less effective than the other
8843 compression programs@footnote{It also had patent problems in the past.}.
8844
8845 Creating a compressed archive is simple: you just specify a
8846 @dfn{compression option} along with the usual archive creation
8847 commands. The compression option is @option{-z} (@option{--gzip}) to
8848 create a @command{gzip} compressed archive, @option{-j}
8849 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
8850 @option{--lzip} to create an @asis{lzip} compressed archive,
8851 @option{-J} (@option{--xz}) to create an @asis{XZ} archive,
8852 @option{--lzma} to create an @asis{LZMA} compressed
8853 archive, @option{--lzop} to create an @asis{LSOP} archive, and
8854 @option{-Z} (@option{--compress}) to use @command{compress} program.
8855 For example:
8856
8857 @smallexample
8858 $ @kbd{tar czf archive.tar.gz .}
8859 @end smallexample
8860
8861 You can also let @GNUTAR{} select the compression program based on
8862 the suffix of the archive file name. This is done using
8863 @option{--auto-compress} (@option{-a}) command line option. For
8864 example, the following invocation will use @command{bzip2} for
8865 compression:
8866
8867 @smallexample
8868 $ @kbd{tar caf archive.tar.bz2 .}
8869 @end smallexample
8870
8871 @noindent
8872 whereas the following one will use @command{lzma}:
8873
8874 @smallexample
8875 $ @kbd{tar caf archive.tar.lzma .}
8876 @end smallexample
8877
8878 For a complete list of file name suffixes recognized by @GNUTAR{},
8879 see @ref{auto-compress}.
8880
8881 Reading compressed archive is even simpler: you don't need to specify
8882 any additional options as @GNUTAR{} recognizes its format
8883 automatically. Thus, the following commands will list and extract the
8884 archive created in previous example:
8885
8886 @smallexample
8887 # List the compressed archive
8888 $ @kbd{tar tf archive.tar.gz}
8889 # Extract the compressed archive
8890 $ @kbd{tar xf archive.tar.gz}
8891 @end smallexample
8892
8893 The format recognition algorithm is based on @dfn{signatures}, a
8894 special byte sequences in the beginning of file, that are specific for
8895 certain compression formats. If this approach fails, @command{tar}
8896 falls back to using archive name suffix to determine its format
8897 (@pxref{auto-compress}, for a list of recognized suffixes).
8898
8899 @anchor{alternative decompression programs}
8900 @cindex alternative decompression programs
8901 Some compression programs are able to handle different compression
8902 formats. @GNUTAR{} uses this, if the principal decompressor for the
8903 given format is not available. For example, if @command{compress} is
8904 not installed, @command{tar} will try to use @command{gzip}. As of
8905 version @value{VERSION} the following alternatives are
8906 tried@footnote{To verbosely trace the decompressor selection, use the
8907 @option{--warning=decompress-program} option
8908 (@pxref{warnings,decompress-program}).}:
8909
8910 @multitable @columnfractions 0.3 0.3 0.3
8911 @headitem Format @tab Main decompressor @tab Alternatives
8912 @item compress @tab compress @tab gzip
8913 @item lzma @tab lzma @tab xz
8914 @item bzip2 @tab bzip2 @tab lbzip2
8915 @end multitable
8916
8917 The only case when you have to specify a decompression option while
8918 reading the archive is when reading from a pipe or from a tape drive
8919 that does not support random access. However, in this case @GNUTAR{}
8920 will indicate which option you should use. For example:
8921
8922 @smallexample
8923 $ @kbd{cat archive.tar.gz | tar tf -}
8924 tar: Archive is compressed. Use -z option
8925 tar: Error is not recoverable: exiting now
8926 @end smallexample
8927
8928 If you see such diagnostics, just add the suggested option to the
8929 invocation of @GNUTAR{}:
8930
8931 @smallexample
8932 $ @kbd{cat archive.tar.gz | tar tzf -}
8933 @end smallexample
8934
8935 Notice also, that there are several restrictions on operations on
8936 compressed archives. First of all, compressed archives cannot be
8937 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
8938 them or delete (@option{--delete}) members from them or
8939 add (@option{--append}, alias @option{-r}) members to them. Likewise, you
8940 cannot append another @command{tar} archive to a compressed archive using
8941 @option{--concatenate} (@option{-A}). Secondly, multi-volume
8942 archives cannot be compressed.
8943
8944 The following options allow to select a particular compressor program:
8945
8946 @table @option
8947 @opindex gzip
8948 @opindex ungzip
8949 @item -z
8950 @itemx --gzip
8951 @itemx --ungzip
8952 Filter the archive through @command{gzip}.
8953
8954 @opindex xz
8955 @item -J
8956 @itemx --xz
8957 Filter the archive through @code{xz}.
8958
8959 @item -j
8960 @itemx --bzip2
8961 Filter the archive through @code{bzip2}.
8962
8963 @opindex lzip
8964 @item --lzip
8965 Filter the archive through @command{lzip}.
8966
8967 @opindex lzma
8968 @item --lzma
8969 Filter the archive through @command{lzma}.
8970
8971 @opindex lzop
8972 @item --lzop
8973 Filter the archive through @command{lzop}.
8974
8975 @opindex compress
8976 @opindex uncompress
8977 @item -Z
8978 @itemx --compress
8979 @itemx --uncompress
8980 Filter the archive through @command{compress}.
8981 @end table
8982
8983 When any of these options is given, @GNUTAR{} searches the compressor
8984 binary in the current path and invokes it. The name of the compressor
8985 program is specified at compilation time using a corresponding
8986 @option{--with-@var{compname}} option to @command{configure}, e.g.
8987 @option{--with-bzip2} to select a specific @command{bzip2} binary.
8988 @xref{lbzip2}, for a detailed discussion.
8989
8990 The output produced by @command{tar --help} shows the actual
8991 compressor names along with each of these options.
8992
8993 You can use any of these options on physical devices (tape drives,
8994 etc.) and remote files as well as on normal files; data to or from
8995 such devices or remote files is reblocked by another copy of the
8996 @command{tar} program to enforce the specified (or default) record
8997 size. The default compression parameters are used. Most compression
8998 programs let you override these by setting a program-specific
8999 environment variable. For example, with @command{gzip} you can set
9000 @env{GZIP}:
9001
9002 @smallexample
9003 $ @kbd{GZIP='-9 -n' tar czf archive.tar.gz subdir}
9004 @end smallexample
9005 Another way would be to use the @option{-I} option instead (see
9006 below), e.g.:
9007
9008 @smallexample
9009 $ @kbd{tar -cf archive.tar.gz -I 'gzip -9 -n' subdir}
9010 @end smallexample
9011
9012 @noindent
9013 Finally, the third, traditional, way to do this is to use a pipe:
9014
9015 @smallexample
9016 $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
9017 @end smallexample
9018
9019 @cindex corrupted archives
9020 Compressed archives are easily corrupted, because compressed files
9021 have little redundancy. The adaptive nature of the
9022 compression scheme means that the compression tables are implicitly
9023 spread all over the archive. If you lose a few blocks, the dynamic
9024 construction of the compression tables becomes unsynchronized, and there
9025 is little chance that you could recover later in the archive.
9026
9027 Other compression options provide better control over creating
9028 compressed archives. These are:
9029
9030 @table @option
9031 @anchor{auto-compress}
9032 @opindex auto-compress
9033 @item --auto-compress
9034 @itemx -a
9035 Select a compression program to use by the archive file name
9036 suffix. The following suffixes are recognized:
9037
9038 @multitable @columnfractions 0.3 0.6
9039 @headitem Suffix @tab Compression program
9040 @item @samp{.gz} @tab @command{gzip}
9041 @item @samp{.tgz} @tab @command{gzip}
9042 @item @samp{.taz} @tab @command{gzip}
9043 @item @samp{.Z} @tab @command{compress}
9044 @item @samp{.taZ} @tab @command{compress}
9045 @item @samp{.bz2} @tab @command{bzip2}
9046 @item @samp{.tz2} @tab @command{bzip2}
9047 @item @samp{.tbz2} @tab @command{bzip2}
9048 @item @samp{.tbz} @tab @command{bzip2}
9049 @item @samp{.lz} @tab @command{lzip}
9050 @item @samp{.lzma} @tab @command{lzma}
9051 @item @samp{.tlz} @tab @command{lzma}
9052 @item @samp{.lzo} @tab @command{lzop}
9053 @item @samp{.xz} @tab @command{xz}
9054 @end multitable
9055
9056 @anchor{use-compress-program}
9057 @opindex use-compress-program
9058 @item --use-compress-program=@var{command}
9059 @itemx -I=@var{command}
9060 Use external compression program @var{command}. Use this option if you
9061 are not happy with the compression program associated with the suffix
9062 at compile time or if you have a compression program that @GNUTAR{}
9063 does not support. The @var{command} argument is a valid command
9064 invocation, as you would type it at the command line prompt, with any
9065 additional options as needed. Enclose it in quotes if it contains
9066 white space (see @ref{external, Running External Commands}, for more detail).
9067
9068 The @var{command} should follow two conventions:
9069
9070 First, when invoked without additional options, it should read data
9071 from standard input, compress it and output it on standard output.
9072
9073 Secondly, if invoked with the additional @option{-d} option, it should
9074 do exactly the opposite, i.e., read the compressed data from the
9075 standard input and produce uncompressed data on the standard output.
9076
9077 The latter requirement means that you must not use the @option{-d}
9078 option as a part of the @var{command} itself.
9079 @end table
9080
9081 @cindex gpg, using with tar
9082 @cindex gnupg, using with tar
9083 @cindex Using encrypted archives
9084 The @option{--use-compress-program} option, in particular, lets you
9085 implement your own filters, not necessarily dealing with
9086 compression/decompression. For example, suppose you wish to implement
9087 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
9088 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
9089 Manual}). The following script does that:
9090
9091 @smallexample
9092 @group
9093 #! /bin/sh
9094 case $1 in
9095 -d) gpg --decrypt - | gzip -d -c;;
9096 '') gzip -c | gpg -s;;
9097 *) echo "Unknown option $1">&2; exit 1;;
9098 esac
9099 @end group
9100 @end smallexample
9101
9102 Suppose you name it @file{gpgz} and save it somewhere in your
9103 @env{PATH}. Then the following command will create a compressed
9104 archive signed with your private key:
9105
9106 @smallexample
9107 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
9108 @end smallexample
9109
9110 @noindent
9111 Likewise, the command below will list its contents:
9112
9113 @smallexample
9114 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
9115 @end smallexample
9116
9117 @ignore
9118 The above is based on the following discussion:
9119
9120 I have one question, or maybe it's a suggestion if there isn't a way
9121 to do it now. I would like to use @option{--gzip}, but I'd also like
9122 the output to be fed through a program like @acronym{GNU}
9123 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
9124 to use :-)), basically adding ECC protection on top of compression.
9125 It seems as if this should be quite easy to do, but I can't work out
9126 exactly how to go about it. Of course, I can pipe the standard output
9127 of @command{tar} through @command{ecc}, but then I lose (though I
9128 haven't started using it yet, I confess) the ability to have
9129 @command{tar} use @command{rmt} for it's I/O (I think).
9130
9131 I think the most straightforward thing would be to let me specify a
9132 general set of filters outboard of compression (preferably ordered,
9133 so the order can be automatically reversed on input operations, and
9134 with the options they require specifiable), but beggars shouldn't be
9135 choosers and anything you decide on would be fine with me.
9136
9137 By the way, I like @command{ecc} but if (as the comments say) it can't
9138 deal with loss of block sync, I'm tempted to throw some time at adding
9139 that capability. Supposing I were to actually do such a thing and
9140 get it (apparently) working, do you accept contributed changes to
9141 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
9142
9143 Isn't that exactly the role of the
9144 @option{--use-compress-prog=@var{program}} option?
9145 I never tried it myself, but I suspect you may want to write a
9146 @var{prog} script or program able to filter stdin to stdout to
9147 way you want. It should recognize the @option{-d} option, for when
9148 extraction is needed rather than creation.
9149
9150 It has been reported that if one writes compressed data (through the
9151 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
9152 the DLT compression mode, the data will actually get bigger and one will
9153 end up with less space on the tape.
9154 @end ignore
9155
9156 @menu
9157 * lbzip2:: Using lbzip2 with @GNUTAR{}.
9158 @end menu
9159
9160 @node lbzip2
9161 @subsubsection Using lbzip2 with @GNUTAR{}.
9162 @cindex lbzip2
9163 @cindex Laszlo Ersek
9164 @command{Lbzip2} is a multithreaded utility for handling
9165 @samp{bzip2} compression, written by Laszlo Ersek. It makes use of
9166 multiple processors to speed up its operation and in general works
9167 considerably faster than @command{bzip2}. For a detailed description
9168 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
9169 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
9170 lbzip2: parallel bzip2 utility}.
9171
9172 Recent versions of @command{lbzip2} are mostly command line compatible
9173 with @command{bzip2}, which makes it possible to automatically invoke
9174 it via the @option{--bzip2} @GNUTAR{} command line option. To do so,
9175 @GNUTAR{} must be configured with the @option{--with-bzip2} command
9176 line option, like this:
9177
9178 @smallexample
9179 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
9180 @end smallexample
9181
9182 Once configured and compiled this way, @command{tar --help} will show the
9183 following:
9184
9185 @smallexample
9186 @group
9187 $ @kbd{tar --help | grep -- --bzip2}
9188 -j, --bzip2 filter the archive through lbzip2
9189 @end group
9190 @end smallexample
9191
9192 @noindent
9193 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
9194
9195 @node sparse
9196 @subsection Archiving Sparse Files
9197 @cindex Sparse Files
9198
9199 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
9200 in a file is a section of the file's contents which was never written.
9201 The contents of a hole reads as all zeros. On many operating systems,
9202 actual disk storage is not allocated for holes, but they are counted
9203 in the length of the file. If you archive such a file, @command{tar}
9204 could create an archive longer than the original. To have @command{tar}
9205 attempt to recognize the holes in a file, use @option{--sparse}
9206 (@option{-S}). When you use this option, then, for any file using
9207 less disk space than would be expected from its length, @command{tar}
9208 searches the file for consecutive stretches of zeros. It then records
9209 in the archive for the file where the consecutive stretches of zeros
9210 are, and only archives the ``real contents'' of the file. On
9211 extraction (using @option{--sparse} is not needed on extraction) any
9212 such files have holes created wherever the continuous stretches of zeros
9213 were found. Thus, if you use @option{--sparse}, @command{tar} archives
9214 won't take more space than the original.
9215
9216 @table @option
9217 @opindex sparse
9218 @item -S
9219 @itemx --sparse
9220 This option instructs @command{tar} to test each file for sparseness
9221 before attempting to archive it. If the file is found to be sparse it
9222 is treated specially, thus allowing to decrease the amount of space
9223 used by its image in the archive.
9224
9225 This option is meaningful only when creating or updating archives. It
9226 has no effect on extraction.
9227 @end table
9228
9229 Consider using @option{--sparse} when performing file system backups,
9230 to avoid archiving the expanded forms of files stored sparsely in the
9231 system.
9232
9233 Even if your system has no sparse files currently, some may be
9234 created in the future. If you use @option{--sparse} while making file
9235 system backups as a matter of course, you can be assured the archive
9236 will never take more space on the media than the files take on disk
9237 (otherwise, archiving a disk filled with sparse files might take
9238 hundreds of tapes). @xref{Incremental Dumps}.
9239
9240 However, be aware that @option{--sparse} option presents a serious
9241 drawback. Namely, in order to determine if the file is sparse
9242 @command{tar} has to read it before trying to archive it, so in total
9243 the file is read @strong{twice}. So, always bear in mind that the
9244 time needed to process all files with this option is roughly twice
9245 the time needed to archive them without it.
9246 @FIXME{A technical note:
9247
9248 Programs like @command{dump} do not have to read the entire file; by
9249 examining the file system directly, they can determine in advance
9250 exactly where the holes are and thus avoid reading through them. The
9251 only data it need read are the actual allocated data blocks.
9252 @GNUTAR{} uses a more portable and straightforward
9253 archiving approach, it would be fairly difficult that it does
9254 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
9255 1990-12-10:
9256
9257 @quotation
9258 What I did say is that you cannot tell the difference between a hole and an
9259 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
9260 best tells you how many holes there are; it doesn't tell you @emph{where}.
9261 Just as programs may, conceivably, care what @code{st_blocks} is (care
9262 to name one that does?), they may also care where the holes are (I have
9263 no examples of this one either, but it's equally imaginable).
9264
9265 I conclude from this that good archivers are not portable. One can
9266 arguably conclude that if you want a portable program, you can in good
9267 conscience restore files with as many holes as possible, since you can't
9268 get it right.
9269 @end quotation
9270 }
9271
9272 @cindex sparse formats, defined
9273 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
9274 sparse files using in three distinct ways, called @dfn{sparse
9275 formats}. A sparse format is identified by its @dfn{number},
9276 consisting, as usual of two decimal numbers, delimited by a dot. By
9277 default, format @samp{1.0} is used. If, for some reason, you wish to
9278 use an earlier format, you can select it using
9279 @option{--sparse-version} option.
9280
9281 @table @option
9282 @opindex sparse-version
9283 @item --sparse-version=@var{version}
9284
9285 Select the format to store sparse files in. Valid @var{version} values
9286 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
9287 for a detailed description of each format.
9288 @end table
9289
9290 Using @option{--sparse-format} option implies @option{--sparse}.
9291
9292 @node Attributes
9293 @section Handling File Attributes
9294 @cindex atrributes, files
9295 @cindex file attributes
9296
9297 When @command{tar} reads files, it updates their access times. To
9298 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
9299 reset the access time retroactively or avoid changing it in the first
9300 place.
9301
9302 @table @option
9303 @opindex atime-preserve
9304 @item --atime-preserve
9305 @itemx --atime-preserve=replace
9306 @itemx --atime-preserve=system
9307 Preserve the access times of files that are read. This works only for
9308 files that you own, unless you have superuser privileges.
9309
9310 @option{--atime-preserve=replace} works on most systems, but it also
9311 restores the data modification time and updates the status change
9312 time. Hence it doesn't interact with incremental dumps nicely
9313 (@pxref{Incremental Dumps}), and it can set access or data modification times
9314 incorrectly if other programs access the file while @command{tar} is
9315 running.
9316
9317 @option{--atime-preserve=system} avoids changing the access time in
9318 the first place, if the operating system supports this.
9319 Unfortunately, this may or may not work on any given operating system
9320 or file system. If @command{tar} knows for sure it won't work, it
9321 complains right away.
9322
9323 Currently @option{--atime-preserve} with no operand defaults to
9324 @option{--atime-preserve=replace}, but this is intended to change to
9325 @option{--atime-preserve=system} when the latter is better-supported.
9326
9327 @opindex touch
9328 @item -m
9329 @itemx --touch
9330 Do not extract data modification time.
9331
9332 When this option is used, @command{tar} leaves the data modification times
9333 of the files it extracts as the times when the files were extracted,
9334 instead of setting it to the times recorded in the archive.
9335
9336 This option is meaningless with @option{--list} (@option{-t}).
9337
9338 @opindex same-owner
9339 @item --same-owner
9340 Create extracted files with the same ownership they have in the
9341 archive.
9342
9343 This is the default behavior for the superuser,
9344 so this option is meaningful only for non-root users, when @command{tar}
9345 is executed on those systems able to give files away. This is
9346 considered as a security flaw by many people, at least because it
9347 makes quite difficult to correctly account users for the disk space
9348 they occupy. Also, the @code{suid} or @code{sgid} attributes of
9349 files are easily and silently lost when files are given away.
9350
9351 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
9352 separately. If it can't find a user name (because the user @acronym{ID} is not
9353 in @file{/etc/passwd}), then it does not write one. When restoring,
9354 it tries to look the name (if one was written) up in
9355 @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
9356 the archive instead.
9357
9358 @opindex no-same-owner
9359 @item --no-same-owner
9360 @itemx -o
9361 Do not attempt to restore ownership when extracting. This is the
9362 default behavior for ordinary users, so this option has an effect
9363 only for the superuser.
9364
9365 @opindex numeric-owner
9366 @item --numeric-owner
9367 The @option{--numeric-owner} option allows (ANSI) archives to be written
9368 without user/group name information or such information to be ignored
9369 when extracting. It effectively disables the generation and/or use
9370 of user/group name information. This option forces extraction using
9371 the numeric ids from the archive, ignoring the names.
9372
9373 This is useful in certain circumstances, when restoring a backup from
9374 an emergency floppy with different passwd/group files for example.
9375 It is otherwise impossible to extract files with the right ownerships
9376 if the password file in use during the extraction does not match the
9377 one belonging to the file system(s) being extracted. This occurs,
9378 for example, if you are restoring your files after a major crash and
9379 had booted from an emergency floppy with no password file or put your
9380 disk into another machine to do the restore.
9381
9382 The numeric ids are @emph{always} saved into @command{tar} archives.
9383 The identifying names are added at create time when provided by the
9384 system, unless @option{--format=oldgnu} is used. Numeric ids could be
9385 used when moving archives between a collection of machines using
9386 a centralized management for attribution of numeric ids to users
9387 and groups. This is often made through using the NIS capabilities.
9388
9389 When making a @command{tar} file for distribution to other sites, it
9390 is sometimes cleaner to use a single owner for all files in the
9391 distribution, and nicer to specify the write permission bits of the
9392 files as stored in the archive independently of their actual value on
9393 the file system. The way to prepare a clean distribution is usually
9394 to have some Makefile rule creating a directory, copying all needed
9395 files in that directory, then setting ownership and permissions as
9396 wanted (there are a lot of possible schemes), and only then making a
9397 @command{tar} archive out of this directory, before cleaning
9398 everything out. Of course, we could add a lot of options to
9399 @GNUTAR{} for fine tuning permissions and ownership.
9400 This is not the good way, I think. @GNUTAR{} is
9401 already crowded with options and moreover, the approach just explained
9402 gives you a great deal of control already.
9403
9404 @xopindex{same-permissions, short description}
9405 @xopindex{preserve-permissions, short description}
9406 @item -p
9407 @itemx --same-permissions
9408 @itemx --preserve-permissions
9409 Extract all protection information.
9410
9411 This option causes @command{tar} to set the modes (access permissions) of
9412 extracted files exactly as recorded in the archive. If this option
9413 is not used, the current @code{umask} setting limits the permissions
9414 on extracted files. This option is by default enabled when
9415 @command{tar} is executed by a superuser.
9416
9417
9418 This option is meaningless with @option{--list} (@option{-t}).
9419
9420 @opindex preserve
9421 @item --preserve
9422 Same as both @option{--same-permissions} and @option{--same-order}.
9423
9424 This option is deprecated, and will be removed in @GNUTAR{} version 1.23.
9425
9426 @end table
9427
9428 @node Portability
9429 @section Making @command{tar} Archives More Portable
9430
9431 Creating a @command{tar} archive on a particular system that is meant to be
9432 useful later on many other machines and with other versions of @command{tar}
9433 is more challenging than you might think. @command{tar} archive formats
9434 have been evolving since the first versions of Unix. Many such formats
9435 are around, and are not always compatible with each other. This section
9436 discusses a few problems, and gives some advice about making @command{tar}
9437 archives more portable.
9438
9439 One golden rule is simplicity. For example, limit your @command{tar}
9440 archives to contain only regular files and directories, avoiding
9441 other kind of special files. Do not attempt to save sparse files or
9442 contiguous files as such. Let's discuss a few more problems, in turn.
9443
9444 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
9445 archives and archive labels) in GNU and PAX formats.}
9446
9447 @menu
9448 * Portable Names:: Portable Names
9449 * dereference:: Symbolic Links
9450 * hard links:: Hard Links
9451 * old:: Old V7 Archives
9452 * ustar:: Ustar Archives
9453 * gnu:: GNU and old GNU format archives.
9454 * posix:: @acronym{POSIX} archives
9455 * Checksumming:: Checksumming Problems
9456 * Large or Negative Values:: Large files, negative time stamps, etc.
9457 * Other Tars:: How to Extract GNU-Specific Data Using
9458 Other @command{tar} Implementations
9459 @end menu
9460
9461 @node Portable Names
9462 @subsection Portable Names
9463
9464 Use portable file and member names. A name is portable if it contains
9465 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
9466 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
9467 contain @samp{/-}. Avoid deep directory nesting. For portability to
9468 old Unix hosts, limit your file name components to 14 characters or
9469 less.
9470
9471 If you intend to have your @command{tar} archives to be read under
9472 MSDOS, you should not rely on case distinction for file names, and you
9473 might use the @acronym{GNU} @command{doschk} program for helping you
9474 further diagnosing illegal MSDOS names, which are even more limited
9475 than System V's.
9476
9477 @node dereference
9478 @subsection Symbolic Links
9479 @cindex File names, using symbolic links
9480 @cindex Symbolic link as file name
9481
9482 @opindex dereference
9483 Normally, when @command{tar} archives a symbolic link, it writes a
9484 block to the archive naming the target of the link. In that way, the
9485 @command{tar} archive is a faithful record of the file system contents.
9486 When @option{--dereference} (@option{-h}) is used with
9487 @option{--create} (@option{-c}), @command{tar} archives the files
9488 symbolic links point to, instead of
9489 the links themselves.
9490
9491 When creating portable archives, use @option{--dereference}
9492 (@option{-h}): some systems do not support
9493 symbolic links, and moreover, your distribution might be unusable if
9494 it contains unresolved symbolic links.
9495
9496 When reading from an archive, the @option{--dereference} (@option{-h})
9497 option causes @command{tar} to follow an already-existing symbolic
9498 link when @command{tar} writes or reads a file named in the archive.
9499 Ordinarily, @command{tar} does not follow such a link, though it may
9500 remove the link before writing a new file. @xref{Dealing with Old
9501 Files}.
9502
9503 The @option{--dereference} option is unsafe if an untrusted user can
9504 modify directories while @command{tar} is running. @xref{Security}.
9505
9506 @node hard links
9507 @subsection Hard Links
9508 @cindex File names, using hard links
9509 @cindex hard links, dereferencing
9510 @cindex dereferencing hard links
9511
9512 Normally, when @command{tar} archives a hard link, it writes a
9513 block to the archive naming the target of the link (a @samp{1} type
9514 block). In that way, the actual file contents is stored in file only
9515 once. For example, consider the following two files:
9516
9517 @smallexample
9518 @group
9519 $ ls -l
9520 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
9521 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
9522 @end group
9523 @end smallexample
9524
9525 Here, @file{jeden} is a link to @file{one}. When archiving this
9526 directory with a verbose level 2, you will get an output similar to
9527 the following:
9528
9529 @smallexample
9530 $ tar cvvf ../archive.tar .
9531 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
9532 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
9533 hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
9534 @end smallexample
9535
9536 The last line shows that, instead of storing two copies of the file,
9537 @command{tar} stored it only once, under the name @file{jeden}, and
9538 stored file @file{one} as a hard link to this file.
9539
9540 It may be important to know that all hard links to the given file are
9541 stored in the archive. For example, this may be necessary for exact
9542 reproduction of the file system. The following option does that:
9543
9544 @table @option
9545 @xopindex{check-links, described}
9546 @item --check-links
9547 @itemx -l
9548 Check the number of links dumped for each processed file. If this
9549 number does not match the total number of hard links for the file, print
9550 a warning message.
9551 @end table
9552
9553 For example, trying to archive only file @file{jeden} with this option
9554 produces the following diagnostics:
9555
9556 @smallexample
9557 $ tar -c -f ../archive.tar -l jeden
9558 tar: Missing links to 'jeden'.
9559 @end smallexample
9560
9561 Although creating special records for hard links helps keep a faithful
9562 record of the file system contents and makes archives more compact, it
9563 may present some difficulties when extracting individual members from
9564 the archive. For example, trying to extract file @file{one} from the
9565 archive created in previous examples produces, in the absense of file
9566 @file{jeden}:
9567
9568 @smallexample
9569 $ tar xf archive.tar ./one
9570 tar: ./one: Cannot hard link to './jeden': No such file or directory
9571 tar: Error exit delayed from previous errors
9572 @end smallexample
9573
9574 The reason for this behavior is that @command{tar} cannot seek back in
9575 the archive to the previous member (in this case, @file{one}), to
9576 extract it@footnote{There are plans to fix this in future releases.}.
9577 If you wish to avoid such problems at the cost of a bigger archive,
9578 use the following option:
9579
9580 @table @option
9581 @xopindex{hard-dereference, described}
9582 @item --hard-dereference
9583 Dereference hard links and store the files they refer to.
9584 @end table
9585
9586 For example, trying this option on our two sample files, we get two
9587 copies in the archive, each of which can then be extracted
9588 independently of the other:
9589
9590 @smallexample
9591 @group
9592 $ tar -c -vv -f ../archive.tar --hard-dereference .
9593 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
9594 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
9595 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
9596 @end group
9597 @end smallexample
9598
9599 @node old
9600 @subsection Old V7 Archives
9601 @cindex Format, old style
9602 @cindex Old style format
9603 @cindex Old style archives
9604 @cindex v7 archive format
9605
9606 Certain old versions of @command{tar} cannot handle additional
9607 information recorded by newer @command{tar} programs. To create an
9608 archive in V7 format (not ANSI), which can be read by these old
9609 versions, specify the @option{--format=v7} option in
9610 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
9611 accepts @option{--portability} or @option{--old-archive} for this
9612 option). When you specify it,
9613 @command{tar} leaves out information about directories, pipes, fifos,
9614 contiguous files, and device files, and specifies file ownership by
9615 group and user IDs instead of group and user names.
9616
9617 When updating an archive, do not use @option{--format=v7}
9618 unless the archive was created using this option.
9619
9620 In most cases, a @emph{new} format archive can be read by an @emph{old}
9621 @command{tar} program without serious trouble, so this option should
9622 seldom be needed. On the other hand, most modern @command{tar}s are
9623 able to read old format archives, so it might be safer for you to
9624 always use @option{--format=v7} for your distributions. Notice,
9625 however, that @samp{ustar} format is a better alternative, as it is
9626 free from many of @samp{v7}'s drawbacks.
9627
9628 @node ustar
9629 @subsection Ustar Archive Format
9630
9631 @cindex ustar archive format
9632 Archive format defined by @acronym{POSIX}.1-1988 specification is called
9633 @code{ustar}. Although it is more flexible than the V7 format, it
9634 still has many restrictions (@pxref{Formats,ustar}, for the detailed
9635 description of @code{ustar} format). Along with V7 format,
9636 @code{ustar} format is a good choice for archives intended to be read
9637 with other implementations of @command{tar}.
9638
9639 To create archive in @code{ustar} format, use @option{--format=ustar}
9640 option in conjunction with the @option{--create} (@option{-c}).
9641
9642 @node gnu
9643 @subsection @acronym{GNU} and old @GNUTAR{} format
9644
9645 @cindex GNU archive format
9646 @cindex Old GNU archive format
9647 @GNUTAR{} was based on an early draft of the
9648 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
9649 @command{tar}, such as the support for file names longer than 100
9650 characters, use portions of the @command{tar} header record which were
9651 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
9652 @acronym{POSIX} have allocated the same parts of the header record for
9653 other purposes. As a result, @GNUTAR{} format is
9654 incompatible with the current @acronym{POSIX} specification, and with
9655 @command{tar} programs that follow it.
9656
9657 In the majority of cases, @command{tar} will be configured to create
9658 this format by default. This will change in future releases, since
9659 we plan to make @samp{POSIX} format the default.
9660
9661 To force creation a @GNUTAR{} archive, use option
9662 @option{--format=gnu}.
9663
9664 @node posix
9665 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
9666
9667 @cindex POSIX archive format
9668 @cindex PAX archive format
9669 Starting from version 1.14 @GNUTAR{} features full support for
9670 @acronym{POSIX.1-2001} archives.
9671
9672 A @acronym{POSIX} conformant archive will be created if @command{tar}
9673 was given @option{--format=posix} (@option{--format=pax}) option. No
9674 special option is required to read and extract from a @acronym{POSIX}
9675 archive.
9676
9677 @menu
9678 * PAX keywords:: Controlling Extended Header Keywords.
9679 @end menu
9680
9681 @node PAX keywords
9682 @subsubsection Controlling Extended Header Keywords
9683
9684 @table @option
9685 @opindex pax-option
9686 @item --pax-option=@var{keyword-list}
9687 Handle keywords in @acronym{PAX} extended headers. This option is
9688 equivalent to @option{-o} option of the @command{pax} utility.
9689 @end table
9690
9691 @var{Keyword-list} is a comma-separated
9692 list of keyword options, each keyword option taking one of
9693 the following forms:
9694
9695 @table @code
9696 @item delete=@var{pattern}
9697 When used with one of archive-creation commands,
9698 this option instructs @command{tar} to omit from extended header records
9699 that it produces any keywords matching the string @var{pattern}.
9700
9701 When used in extract or list mode, this option instructs tar
9702 to ignore any keywords matching the given @var{pattern} in the extended
9703 header records. In both cases, matching is performed using the pattern
9704 matching notation described in @acronym{POSIX 1003.2}, 3.13
9705 (@pxref{wildcards}). For example:
9706
9707 @smallexample
9708 --pax-option delete=security.*
9709 @end smallexample
9710
9711 would suppress security-related information.
9712
9713 @item exthdr.name=@var{string}
9714
9715 This keyword allows user control over the name that is written into the
9716 ustar header blocks for the extended headers. The name is obtained
9717 from @var{string} after making the following substitutions:
9718
9719 @multitable @columnfractions .25 .55
9720 @headitem Meta-character @tab Replaced By
9721 @item %d @tab The directory name of the file, equivalent to the
9722 result of the @command{dirname} utility on the translated file name.
9723 @item %f @tab The name of the file with the directory information
9724 stripped, equivalent to the result of the @command{basename} utility
9725 on the translated file name.
9726 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9727 @item %% @tab A @samp{%} character.
9728 @end multitable
9729
9730 Any other @samp{%} characters in @var{string} produce undefined
9731 results.
9732
9733 If no option @samp{exthdr.name=string} is specified, @command{tar}
9734 will use the following default value:
9735
9736 @smallexample
9737 %d/PaxHeaders.%p/%f
9738 @end smallexample
9739
9740 @item exthdr.mtime=@var{value}
9741
9742 This keyword defines the value of the @samp{mtime} field that
9743 is written into the ustar header blocks for the extended headers.
9744 By default, the @samp{mtime} field is set to the modification time
9745 of the archive member described by that extended headers.
9746
9747 @item globexthdr.name=@var{string}
9748 This keyword allows user control over the name that is written into
9749 the ustar header blocks for global extended header records. The name
9750 is obtained from the contents of @var{string}, after making
9751 the following substitutions:
9752
9753 @multitable @columnfractions .25 .55
9754 @headitem Meta-character @tab Replaced By
9755 @item %n @tab An integer that represents the
9756 sequence number of the global extended header record in the archive,
9757 starting at 1.
9758 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9759 @item %% @tab A @samp{%} character.
9760 @end multitable
9761
9762 Any other @samp{%} characters in @var{string} produce undefined results.
9763
9764 If no option @samp{globexthdr.name=string} is specified, @command{tar}
9765 will use the following default value:
9766
9767 @smallexample
9768 $TMPDIR/GlobalHead.%p.%n
9769 @end smallexample
9770
9771 @noindent
9772 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
9773 environment variable. If @var{TMPDIR} is not set, @command{tar}
9774 uses @samp{/tmp}.
9775
9776 @item globexthdr.mtime=@var{value}
9777
9778 This keyword defines the value of the @samp{mtime} field that
9779 is written into the ustar header blocks for the global extended headers.
9780 By default, the @samp{mtime} field is set to the time when
9781 @command{tar} was invoked.
9782
9783 @item @var{keyword}=@var{value}
9784 When used with one of archive-creation commands, these keyword/value pairs
9785 will be included at the beginning of the archive in a global extended
9786 header record. When used with one of archive-reading commands,
9787 @command{tar} will behave as if it has encountered these keyword/value
9788 pairs at the beginning of the archive in a global extended header
9789 record.
9790
9791 @item @var{keyword}:=@var{value}
9792 When used with one of archive-creation commands, these keyword/value pairs
9793 will be included as records at the beginning of an extended header for
9794 each file. This is effectively equivalent to @var{keyword}=@var{value}
9795 form except that it creates no global extended header records.
9796
9797 When used with one of archive-reading commands, @command{tar} will
9798 behave as if these keyword/value pairs were included as records at the
9799 end of each extended header; thus, they will override any global or
9800 file-specific extended header record keywords of the same names.
9801 For example, in the command:
9802
9803 @smallexample
9804 tar --format=posix --create \
9805 --file archive --pax-option gname:=user .
9806 @end smallexample
9807
9808 the group name will be forced to a new value for all files
9809 stored in the archive.
9810 @end table
9811
9812 In any of the forms described above, the @var{value} may be
9813 a string enclosed in curly braces. In that case, the string
9814 between the braces is understood either as a textual time
9815 representation, as described in @ref{Date input formats}, or a name of
9816 the existing file, starting with @samp{/} or @samp{.}. In the latter
9817 case, the modification time of that file is used.
9818
9819 For example, to set all modification times to the current date, you
9820 use the following option:
9821
9822 @smallexample
9823 --pax-option='mtime:=@{now@}'
9824 @end smallexample
9825
9826 Note quoting of the option's argument.
9827
9828 @cindex archives, binary equivalent
9829 @cindex binary equivalent archives, creating
9830 As another example, here is the option that ensures that any two
9831 archives created using it, will be binary equivalent if they have the
9832 same contents:
9833
9834 @smallexample
9835 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0
9836 @end smallexample
9837
9838 @node Checksumming
9839 @subsection Checksumming Problems
9840
9841 SunOS and HP-UX @command{tar} fail to accept archives created using
9842 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
9843 is, file names having characters with the eight bit set, because they
9844 use signed checksums, while @GNUTAR{} uses unsigned
9845 checksums while creating archives, as per @acronym{POSIX} standards. On
9846 reading, @GNUTAR{} computes both checksums and
9847 accepts any. It is somewhat worrying that a lot of people may go
9848 around doing backup of their files using faulty (or at least
9849 non-standard) software, not learning about it until it's time to
9850 restore their missing files with an incompatible file extractor, or
9851 vice versa.
9852
9853 @GNUTAR{} computes checksums both ways, and accept
9854 any on read, so @acronym{GNU} tar can read Sun tapes even with their
9855 wrong checksums. @GNUTAR{} produces the standard
9856 checksum, however, raising incompatibilities with Sun. That is to
9857 say, @GNUTAR{} has not been modified to
9858 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
9859 I've been told that more recent Sun @command{tar} now read standard
9860 archives, so maybe Sun did a similar patch, after all?
9861
9862 The story seems to be that when Sun first imported @command{tar}
9863 sources on their system, they recompiled it without realizing that
9864 the checksums were computed differently, because of a change in
9865 the default signing of @code{char}'s in their compiler. So they
9866 started computing checksums wrongly. When they later realized their
9867 mistake, they merely decided to stay compatible with it, and with
9868 themselves afterwards. Presumably, but I do not really know, HP-UX
9869 has chosen that their @command{tar} archives to be compatible with Sun's.
9870 The current standards do not favor Sun @command{tar} format. In any
9871 case, it now falls on the shoulders of SunOS and HP-UX users to get
9872 a @command{tar} able to read the good archives they receive.
9873
9874 @node Large or Negative Values
9875 @subsection Large or Negative Values
9876 @cindex large values
9877 @cindex future time stamps
9878 @cindex negative time stamps
9879 @UNREVISED
9880
9881 The above sections suggest to use @samp{oldest possible} archive
9882 format if in doubt. However, sometimes it is not possible. If you
9883 attempt to archive a file whose metadata cannot be represented using
9884 required format, @GNUTAR{} will print error message and ignore such a
9885 file. You will than have to switch to a format that is able to
9886 handle such values. The format summary table (@pxref{Formats}) will
9887 help you to do so.
9888
9889 In particular, when trying to archive files larger than 8GB or with
9890 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
9891 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
9892 @acronym{POSIX} archive formats. When considering which format to
9893 choose, bear in mind that the @acronym{GNU} format uses
9894 two's-complement base-256 notation to store values that do not fit
9895 into standard @acronym{ustar} range. Such archives can generally be
9896 read only by a @GNUTAR{} implementation. Moreover, they sometimes
9897 cannot be correctly restored on another hosts even by @GNUTAR{}. For
9898 example, using two's complement representation for negative time
9899 stamps that assumes a signed 32-bit @code{time_t} generates archives
9900 that are not portable to hosts with differing @code{time_t}
9901 representations.
9902
9903 On the other hand, @acronym{POSIX} archives, generally speaking, can
9904 be extracted by any tar implementation that understands older
9905 @acronym{ustar} format. The only exception are files larger than 8GB.
9906
9907 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
9908 POSIX-aware tars.}
9909
9910 @node Other Tars
9911 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
9912
9913 In previous sections you became acquainted with various quirks
9914 necessary to make your archives portable. Sometimes you may need to
9915 extract archives containing GNU-specific members using some
9916 third-party @command{tar} implementation or an older version of
9917 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
9918 but if it is for some reason impossible, this section will explain
9919 how to cope without it.
9920
9921 When we speak about @dfn{GNU-specific} members we mean two classes of
9922 them: members split between the volumes of a multi-volume archive and
9923 sparse members. You will be able to always recover such members if
9924 the archive is in PAX format. In addition split members can be
9925 recovered from archives in old GNU format. The following subsections
9926 describe the required procedures in detail.
9927
9928 @menu
9929 * Split Recovery:: Members Split Between Volumes
9930 * Sparse Recovery:: Sparse Members
9931 @end menu
9932
9933 @node Split Recovery
9934 @subsubsection Extracting Members Split Between Volumes
9935
9936 @cindex Mutli-volume archives, extracting using non-GNU tars
9937 If a member is split between several volumes of an old GNU format archive
9938 most third party @command{tar} implementation will fail to extract
9939 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
9940 This program is available from
9941 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
9942 home page}. It concatenates several archive volumes into a single
9943 valid archive. For example, if you have three volumes named from
9944 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
9945 extract them using a third-party @command{tar}:
9946
9947 @smallexample
9948 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
9949 @end smallexample
9950
9951 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
9952 You could use this approach for most (although not all) PAX
9953 format archives as well. However, extracting split members from a PAX
9954 archive is a much easier task, because PAX volumes are constructed in
9955 such a way that each part of a split member is extracted to a
9956 different file by @command{tar} implementations that are not aware of
9957 GNU extensions. More specifically, the very first part retains its
9958 original name, and all subsequent parts are named using the pattern:
9959
9960 @smallexample
9961 %d/GNUFileParts.%p/%f.%n
9962 @end smallexample
9963
9964 @noindent
9965 where symbols preceeded by @samp{%} are @dfn{macro characters} that
9966 have the following meaning:
9967
9968 @multitable @columnfractions .25 .55
9969 @headitem Meta-character @tab Replaced By
9970 @item %d @tab The directory name of the file, equivalent to the
9971 result of the @command{dirname} utility on its full name.
9972 @item %f @tab The file name of the file, equivalent to the result
9973 of the @command{basename} utility on its full name.
9974 @item %p @tab The process @acronym{ID} of the @command{tar} process that
9975 created the archive.
9976 @item %n @tab Ordinal number of this particular part.
9977 @end multitable
9978
9979 For example, if the file @file{var/longfile} was split during archive
9980 creation between three volumes, and the creator @command{tar} process
9981 had process @acronym{ID} @samp{27962}, then the member names will be:
9982
9983 @smallexample
9984 var/longfile
9985 var/GNUFileParts.27962/longfile.1
9986 var/GNUFileParts.27962/longfile.2
9987 @end smallexample
9988
9989 When you extract your archive using a third-party @command{tar}, these
9990 files will be created on your disk, and the only thing you will need
9991 to do to restore your file in its original form is concatenate them in
9992 the proper order, for example:
9993
9994 @smallexample
9995 @group
9996 $ @kbd{cd var}
9997 $ @kbd{cat GNUFileParts.27962/longfile.1 \
9998 GNUFileParts.27962/longfile.2 >> longfile}
9999 $ rm -f GNUFileParts.27962
10000 @end group
10001 @end smallexample
10002
10003 Notice, that if the @command{tar} implementation you use supports PAX
10004 format archives, it will probably emit warnings about unknown keywords
10005 during extraction. They will look like this:
10006
10007 @smallexample
10008 @group
10009 Tar file too small
10010 Unknown extended header keyword 'GNU.volume.filename' ignored.
10011 Unknown extended header keyword 'GNU.volume.size' ignored.
10012 Unknown extended header keyword 'GNU.volume.offset' ignored.
10013 @end group
10014 @end smallexample
10015
10016 @noindent
10017 You can safely ignore these warnings.
10018
10019 If your @command{tar} implementation is not PAX-aware, you will get
10020 more warnings and more files generated on your disk, e.g.:
10021
10022 @smallexample
10023 @group
10024 $ @kbd{tar xf vol-1.tar}
10025 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
10026 normal file
10027 Unexpected EOF in archive
10028 $ @kbd{tar xf vol-2.tar}
10029 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
10030 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
10031 'x', extracted as normal file
10032 @end group
10033 @end smallexample
10034
10035 Ignore these warnings. The @file{PaxHeaders.*} directories created
10036 will contain files with @dfn{extended header keywords} describing the
10037 extracted files. You can delete them, unless they describe sparse
10038 members. Read further to learn more about them.
10039
10040 @node Sparse Recovery
10041 @subsubsection Extracting Sparse Members
10042
10043 @cindex sparse files, extracting with non-GNU tars
10044 Any @command{tar} implementation will be able to extract sparse members from a
10045 PAX archive. However, the extracted files will be @dfn{condensed},
10046 i.e., any zero blocks will be removed from them. When we restore such
10047 a condensed file to its original form, by adding zero blocks (or
10048 @dfn{holes}) back to their original locations, we call this process
10049 @dfn{expanding} a compressed sparse file.
10050
10051 @pindex xsparse
10052 To expand a file, you will need a simple auxiliary program called
10053 @command{xsparse}. It is available in source form from
10054 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
10055 home page}.
10056
10057 @cindex sparse files v.1.0, extracting with non-GNU tars
10058 Let's begin with archive members in @dfn{sparse format
10059 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
10060 The condensed file will contain both file map and file data, so no
10061 additional data will be needed to restore it. If the original file
10062 name was @file{@var{dir}/@var{name}}, then the condensed file will be
10063 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
10064 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
10065 @dfn{process @acronym{ID}} of the @command{tar} process which created the
10066 archive (@pxref{PAX keywords}).}.
10067
10068 To expand a version 1.0 file, run @command{xsparse} as follows:
10069
10070 @smallexample
10071 $ @kbd{xsparse @file{cond-file}}
10072 @end smallexample
10073
10074 @noindent
10075 where @file{cond-file} is the name of the condensed file. The utility
10076 will deduce the name for the resulting expanded file using the
10077 following algorithm:
10078
10079 @enumerate 1
10080 @item If @file{cond-file} does not contain any directories,
10081 @file{../cond-file} will be used;
10082
10083 @item If @file{cond-file} has the form
10084 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
10085 are simple names, with no @samp{/} characters in them, the output file
10086 name will be @file{@var{dir}/@var{name}}.
10087
10088 @item Otherwise, if @file{cond-file} has the form
10089 @file{@var{dir}/@var{name}}, the output file name will be
10090 @file{@var{name}}.
10091 @end enumerate
10092
10093 In the unlikely case when this algorithm does not suit your needs,
10094 you can explicitly specify output file name as a second argument to
10095 the command:
10096
10097 @smallexample
10098 $ @kbd{xsparse @file{cond-file} @file{out-file}}
10099 @end smallexample
10100
10101 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
10102 first. In this mode, the command does not actually expand the file,
10103 but verbosely lists all actions it would be taking to do so. The dry
10104 run mode is enabled by @option{-n} command line argument:
10105
10106 @smallexample
10107 @group
10108 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
10109 Reading v.1.0 sparse map
10110 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10111 '/home/gray/sparsefile'
10112 Finished dry run
10113 @end group
10114 @end smallexample
10115
10116 To actually expand the file, you would run:
10117
10118 @smallexample
10119 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
10120 @end smallexample
10121
10122 @noindent
10123 The program behaves the same way all UNIX utilities do: it will keep
10124 quiet unless it has simething important to tell you (e.g. an error
10125 condition or something). If you wish it to produce verbose output,
10126 similar to that from the dry run mode, use @option{-v} option:
10127
10128 @smallexample
10129 @group
10130 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
10131 Reading v.1.0 sparse map
10132 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10133 '/home/gray/sparsefile'
10134 Done
10135 @end group
10136 @end smallexample
10137
10138 Additionally, if your @command{tar} implementation has extracted the
10139 @dfn{extended headers} for this file, you can instruct @command{xstar}
10140 to use them in order to verify the integrity of the expanded file.
10141 The option @option{-x} sets the name of the extended header file to
10142 use. Continuing our example:
10143
10144 @smallexample
10145 @group
10146 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
10147 /home/gray/GNUSparseFile.6058/sparsefile}
10148 Reading extended header file
10149 Found variable GNU.sparse.major = 1
10150 Found variable GNU.sparse.minor = 0
10151 Found variable GNU.sparse.name = sparsefile
10152 Found variable GNU.sparse.realsize = 217481216
10153 Reading v.1.0 sparse map
10154 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10155 '/home/gray/sparsefile'
10156 Done
10157 @end group
10158 @end smallexample
10159
10160 @anchor{extracting sparse v.0.x}
10161 @cindex sparse files v.0.1, extracting with non-GNU tars
10162 @cindex sparse files v.0.0, extracting with non-GNU tars
10163 An @dfn{extended header} is a special @command{tar} archive header
10164 that precedes an archive member and contains a set of
10165 @dfn{variables}, describing the member properties that cannot be
10166 stored in the standard @code{ustar} header. While optional for
10167 expanding sparse version 1.0 members, the use of extended headers is
10168 mandatory when expanding sparse members in older sparse formats: v.0.0
10169 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
10170 Formats}.) So, for these formats, the question is: how to obtain
10171 extended headers from the archive?
10172
10173 If you use a @command{tar} implementation that does not support PAX
10174 format, extended headers for each member will be extracted as a
10175 separate file. If we represent the member name as
10176 @file{@var{dir}/@var{name}}, then the extended header file will be
10177 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
10178 @var{n} is an integer number.
10179
10180 Things become more difficult if your @command{tar} implementation
10181 does support PAX headers, because in this case you will have to
10182 manually extract the headers. We recommend the following algorithm:
10183
10184 @enumerate 1
10185 @item
10186 Consult the documentation of your @command{tar} implementation for an
10187 option that prints @dfn{block numbers} along with the archive
10188 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
10189 @command{star} has @option{-block-number}.
10190
10191 @item
10192 Obtain verbose listing using the @samp{block number} option, and
10193 find block numbers of the sparse member in question and the member
10194 immediately following it. For example, running @command{star} on our
10195 archive we obtain:
10196
10197 @smallexample
10198 @group
10199 $ @kbd{star -t -v -block-number -f arc.tar}
10200 @dots{}
10201 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
10202 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
10203 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
10204 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
10205 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
10206 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
10207 @dots{}
10208 @end group
10209 @end smallexample
10210
10211 @noindent
10212 (as usual, ignore the warnings about unknown keywords.)
10213
10214 @item
10215 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
10216 and @var{Bn} be the block number of the next member.
10217 Compute:
10218
10219 @smallexample
10220 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
10221 @end smallexample
10222
10223 @noindent
10224 This number gives the size of the extended header part in tar @dfn{blocks}.
10225 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
10226 = 7}.
10227
10228 @item
10229 Use @command{dd} to extract the headers:
10230
10231 @smallexample
10232 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
10233 @end smallexample
10234
10235 @noindent
10236 where @var{archive} is the archive name, @var{hname} is a name of the
10237 file to store the extended header in, @var{Bs} and @var{N} are
10238 computed in previous steps.
10239
10240 In our example, this command will be
10241
10242 @smallexample
10243 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
10244 @end smallexample
10245 @end enumerate
10246
10247 Finally, you can expand the condensed file, using the obtained header:
10248
10249 @smallexample
10250 @group
10251 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
10252 Reading extended header file
10253 Found variable GNU.sparse.size = 217481216
10254 Found variable GNU.sparse.numblocks = 208
10255 Found variable GNU.sparse.name = sparsefile
10256 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
10257 Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
10258 Done
10259 @end group
10260 @end smallexample
10261
10262 @node cpio
10263 @section Comparison of @command{tar} and @command{cpio}
10264 @UNREVISED
10265
10266 @FIXME{Reorganize the following material}
10267
10268 The @command{cpio} archive formats, like @command{tar}, do have maximum
10269 file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
10270 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
10271 file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
10272 with arbitrary file name lengths, but other @command{cpio} implementations
10273 may crash unexplainedly trying to read them.
10274
10275 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
10276 @command{cpio} doesn't handle symbolic links in the form in which it comes
10277 in System V prior to SVR4, and some vendors may have added symlinks
10278 to their system without enhancing @command{cpio} to know about them.
10279 Others may have enhanced it in a way other than the way I did it
10280 at Sun, and which was adopted by AT&T (and which is, I think, also
10281 present in the @command{cpio} that Berkeley picked up from AT&T and put
10282 into a later @acronym{BSD} release---I think I gave them my changes).
10283
10284 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
10285 can handle @command{tar} format input, and write it on output, and it
10286 probably handles symbolic links. They may not have bothered doing
10287 anything to enhance @command{tar} as a result.)
10288
10289 @command{cpio} handles special files; traditional @command{tar} doesn't.
10290
10291 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
10292 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
10293 (4.3-tahoe and later).
10294
10295 @command{tar}'s way of handling multiple hard links to a file can handle
10296 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
10297 @command{cpio}s way requires you to play some games (in its ``binary''
10298 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
10299 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
10300 field of the header to make sure that the file system @acronym{ID}/i-number pairs
10301 of different files were always different), and I don't know which
10302 @command{cpio}s, if any, play those games. Those that don't might get
10303 confused and think two files are the same file when they're not, and
10304 make hard links between them.
10305
10306 @command{tar}s way of handling multiple hard links to a file places only
10307 one copy of the link on the tape, but the name attached to that copy
10308 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
10309 way puts one copy for every link, but you can retrieve it using any
10310 of the names.
10311
10312 @quotation
10313 What type of check sum (if any) is used, and how is this calculated.
10314 @end quotation
10315
10316 See the attached manual pages for @command{tar} and @command{cpio} format.
10317 @command{tar} uses a checksum which is the sum of all the bytes in the
10318 @command{tar} header for a file; @command{cpio} uses no checksum.
10319
10320 @quotation
10321 If anyone knows why @command{cpio} was made when @command{tar} was present
10322 at the unix scene,
10323 @end quotation
10324
10325 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
10326 generally-available version of UNIX had @command{tar} at the time. I don't
10327 know whether any version that was generally available @emph{within AT&T}
10328 had @command{tar}, or, if so, whether the people within AT&T who did
10329 @command{cpio} knew about it.
10330
10331 On restore, if there is a corruption on a tape @command{tar} will stop at
10332 that point, while @command{cpio} will skip over it and try to restore the
10333 rest of the files.
10334
10335 The main difference is just in the command syntax and header format.
10336
10337 @command{tar} is a little more tape-oriented in that everything is blocked
10338 to start on a record boundary.
10339
10340 @quotation
10341 Is there any differences between the ability to recover crashed
10342 archives between the two of them. (Is there any chance of recovering
10343 crashed archives at all.)
10344 @end quotation
10345
10346 Theoretically it should be easier under @command{tar} since the blocking
10347 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
10348 However, modern @command{cpio}'s and variations have an option to just
10349 search for the next file header after an error with a reasonable chance
10350 of resyncing. However, lots of tape driver software won't allow you to
10351 continue past a media error which should be the only reason for getting
10352 out of sync unless a file changed sizes while you were writing the
10353 archive.
10354
10355 @quotation
10356 If anyone knows why @command{cpio} was made when @command{tar} was present
10357 at the unix scene, please tell me about this too.
10358 @end quotation
10359
10360 Probably because it is more media efficient (by not blocking everything
10361 and using only the space needed for the headers where @command{tar}
10362 always uses 512 bytes per file header) and it knows how to archive
10363 special files.
10364
10365 You might want to look at the freely available alternatives. The
10366 major ones are @command{afio}, @GNUTAR{}, and
10367 @command{pax}, each of which have their own extensions with some
10368 backwards compatibility.
10369
10370 Sparse files were @command{tar}red as sparse files (which you can
10371 easily test, because the resulting archive gets smaller, and
10372 @acronym{GNU} @command{cpio} can no longer read it).
10373
10374 @node Media
10375 @chapter Tapes and Other Archive Media
10376 @UNREVISED
10377
10378 A few special cases about tape handling warrant more detailed
10379 description. These special cases are discussed below.
10380
10381 Many complexities surround the use of @command{tar} on tape drives. Since
10382 the creation and manipulation of archives located on magnetic tape was
10383 the original purpose of @command{tar}, it contains many features making
10384 such manipulation easier.
10385
10386 Archives are usually written on dismountable media---tape cartridges,
10387 mag tapes, or floppy disks.
10388
10389 The amount of data a tape or disk holds depends not only on its size,
10390 but also on how it is formatted. A 2400 foot long reel of mag tape
10391 holds 40 megabytes of data when formatted at 1600 bits per inch. The
10392 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
10393
10394 Magnetic media are re-usable---once the archive on a tape is no longer
10395 needed, the archive can be erased and the tape or disk used over.
10396 Media quality does deteriorate with use, however. Most tapes or disks
10397 should be discarded when they begin to produce data errors. EXABYTE
10398 tape cartridges should be discarded when they generate an @dfn{error
10399 count} (number of non-usable bits) of more than 10k.
10400
10401 Magnetic media are written and erased using magnetic fields, and
10402 should be protected from such fields to avoid damage to stored data.
10403 Sticking a floppy disk to a filing cabinet using a magnet is probably
10404 not a good idea.
10405
10406 @menu
10407 * Device:: Device selection and switching
10408 * Remote Tape Server::
10409 * Common Problems and Solutions::
10410 * Blocking:: Blocking
10411 * Many:: Many archives on one tape
10412 * Using Multiple Tapes:: Using Multiple Tapes
10413 * label:: Including a Label in the Archive
10414 * verify::
10415 * Write Protection::
10416 @end menu
10417
10418 @node Device
10419 @section Device Selection and Switching
10420 @UNREVISED
10421
10422 @table @option
10423 @item -f [@var{hostname}:]@var{file}
10424 @itemx --file=[@var{hostname}:]@var{file}
10425 Use archive file or device @var{file} on @var{hostname}.
10426 @end table
10427
10428 This option is used to specify the file name of the archive @command{tar}
10429 works on.
10430
10431 If the file name is @samp{-}, @command{tar} reads the archive from standard
10432 input (when listing or extracting), or writes it to standard output
10433 (when creating). If the @samp{-} file name is given when updating an
10434 archive, @command{tar} will read the original archive from its standard
10435 input, and will write the entire new archive to its standard output.
10436
10437 If the file name contains a @samp{:}, it is interpreted as
10438 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
10439 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
10440 either case, @command{tar} will invoke the command @command{rsh} (or
10441 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
10442 machine. If you give an alternate login name, it will be given to the
10443 @command{rsh}.
10444 Naturally, the remote machine must have an executable
10445 @command{/usr/libexec/rmt}. This program is free software from the
10446 University of California, and a copy of the source code can be found
10447 with the sources for @command{tar}; it's compiled and installed by default.
10448 The exact path to this utility is determined when configuring the package.
10449 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
10450 your installation prefix. This location may also be overridden at
10451 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
10452 ---rmt-command}, for detailed description of this option. @xref{Remote
10453 Tape Server}, for the description of @command{rmt} command).
10454
10455 If this option is not given, but the environment variable @env{TAPE}
10456 is set, its value is used; otherwise, old versions of @command{tar}
10457 used a default archive name (which was picked when @command{tar} was
10458 compiled). The default is normally set up to be the @dfn{first} tape
10459 drive or other transportable I/O medium on the system.
10460
10461 Starting with version 1.11.5, @GNUTAR{} uses
10462 standard input and standard output as the default device, and I will
10463 not try anymore supporting automatic device detection at installation
10464 time. This was failing really in too many cases, it was hopeless.
10465 This is now completely left to the installer to override standard
10466 input and standard output for default device, if this seems
10467 preferable. Further, I think @emph{most} actual usages of
10468 @command{tar} are done with pipes or disks, not really tapes,
10469 cartridges or diskettes.
10470
10471 Some users think that using standard input and output is running
10472 after trouble. This could lead to a nasty surprise on your screen if
10473 you forget to specify an output file name---especially if you are going
10474 through a network or terminal server capable of buffering large amounts
10475 of output. We had so many bug reports in that area of configuring
10476 default tapes automatically, and so many contradicting requests, that
10477 we finally consider the problem to be portably intractable. We could
10478 of course use something like @samp{/dev/tape} as a default, but this
10479 is @emph{also} running after various kind of trouble, going from hung
10480 processes to accidental destruction of real tapes. After having seen
10481 all this mess, using standard input and output as a default really
10482 sounds like the only clean choice left, and a very useful one too.
10483
10484 @GNUTAR{} reads and writes archive in records, I
10485 suspect this is the main reason why block devices are preferred over
10486 character devices. Most probably, block devices are more efficient
10487 too. The installer could also check for @samp{DEFTAPE} in
10488 @file{<sys/mtio.h>}.
10489
10490 @table @option
10491 @xopindex{force-local, short description}
10492 @item --force-local
10493 Archive file is local even if it contains a colon.
10494
10495 @opindex rsh-command
10496 @item --rsh-command=@var{command}
10497 Use remote @var{command} instead of @command{rsh}. This option exists
10498 so that people who use something other than the standard @command{rsh}
10499 (e.g., a Kerberized @command{rsh}) can access a remote device.
10500
10501 When this command is not used, the shell command found when
10502 the @command{tar} program was installed is used instead. This is
10503 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
10504 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
10505 The installer may have overridden this by defining the environment
10506 variable @env{RSH} @emph{at installation time}.
10507
10508 @item -[0-7][lmh]
10509 Specify drive and density.
10510
10511 @xopindex{multi-volume, short description}
10512 @item -M
10513 @itemx --multi-volume
10514 Create/list/extract multi-volume archive.
10515
10516 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
10517 that may be larger than will fit on the medium used to hold it.
10518 @xref{Multi-Volume Archives}.
10519
10520 @xopindex{tape-length, short description}
10521 @item -L @var{num}
10522 @itemx --tape-length=@var{size}[@var{suf}]
10523 Change tape after writing @var{size} units of data. Unless @var{suf} is
10524 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
10525 1024} bytes. The following suffixes alter this behavior:
10526
10527 @float Table, size-suffixes
10528 @caption{Size Suffixes}
10529 @multitable @columnfractions 0.2 0.3 0.3
10530 @headitem Suffix @tab Units @tab Byte Equivalent
10531 @item b @tab Blocks @tab @var{size} x 512
10532 @item B @tab Kilobytes @tab @var{size} x 1024
10533 @item c @tab Bytes @tab @var{size}
10534 @item G @tab Gigabytes @tab @var{size} x 1024^3
10535 @item K @tab Kilobytes @tab @var{size} x 1024
10536 @item k @tab Kilobytes @tab @var{size} x 1024
10537 @item M @tab Megabytes @tab @var{size} x 1024^2
10538 @item P @tab Petabytes @tab @var{size} x 1024^5
10539 @item T @tab Terabytes @tab @var{size} x 1024^4
10540 @item w @tab Words @tab @var{size} x 2
10541 @end multitable
10542 @end float
10543
10544 This option might be useful when your tape drivers do not properly
10545 detect end of physical tapes. By being slightly conservative on the
10546 maximum tape length, you might avoid the problem entirely.
10547
10548 @xopindex{info-script, short description}
10549 @xopindex{new-volume-script, short description}
10550 @item -F @var{command}
10551 @itemx --info-script=@var{command}
10552 @itemx --new-volume-script=@var{command}
10553 Execute @var{command} at end of each tape. This implies
10554 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
10555 description of this option.
10556 @end table
10557
10558 @node Remote Tape Server
10559 @section Remote Tape Server
10560
10561 @cindex remote tape drive
10562 @pindex rmt
10563 In order to access the tape drive on a remote machine, @command{tar}
10564 uses the remote tape server written at the University of California at
10565 Berkeley. The remote tape server must be installed as
10566 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
10567 want to use. @command{tar} calls @command{rmt} by running an
10568 @command{rsh} or @command{remsh} to the remote machine, optionally
10569 using a different login name if one is supplied.
10570
10571 A copy of the source for the remote tape server is provided. Its
10572 source code can be freely distributed. It is compiled and
10573 installed by default.
10574
10575 @cindex absolute file names
10576 Unless you use the @option{--absolute-names} (@option{-P}) option,
10577 @GNUTAR{} will not allow you to create an archive that contains
10578 absolute file names (a file name beginning with @samp{/}.) If you try,
10579 @command{tar} will automatically remove the leading @samp{/} from the
10580 file names it stores in the archive. It will also type a warning
10581 message telling you what it is doing.
10582
10583 When reading an archive that was created with a different
10584 @command{tar} program, @GNUTAR{} automatically
10585 extracts entries in the archive which have absolute file names as if
10586 the file names were not absolute. This is an important feature. A
10587 visitor here once gave a @command{tar} tape to an operator to restore;
10588 the operator used Sun @command{tar} instead of @GNUTAR{},
10589 and the result was that it replaced large portions of
10590 our @file{/bin} and friends with versions from the tape; needless to
10591 say, we were unhappy about having to recover the file system from
10592 backup tapes.
10593
10594 For example, if the archive contained a file @file{/usr/bin/computoy},
10595 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
10596 relative to the current directory. If you want to extract the files in
10597 an archive to the same absolute names that they had when the archive
10598 was created, you should do a @samp{cd /} before extracting the files
10599 from the archive, or you should either use the @option{--absolute-names}
10600 option, or use the command @samp{tar -C / @dots{}}.
10601
10602 @cindex Ultrix 3.1 and write failure
10603 Some versions of Unix (Ultrix 3.1 is known to have this problem),
10604 can claim that a short write near the end of a tape succeeded,
10605 when it actually failed. This will result in the -M option not
10606 working correctly. The best workaround at the moment is to use a
10607 significantly larger blocking factor than the default 20.
10608
10609 In order to update an archive, @command{tar} must be able to backspace the
10610 archive in order to reread or rewrite a record that was just read (or
10611 written). This is currently possible only on two kinds of files: normal
10612 disk files (or any other file that can be backspaced with @samp{lseek}),
10613 and industry-standard 9-track magnetic tape (or any other kind of tape
10614 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
10615
10616 This means that the @option{--append}, @option{--concatenate}, and
10617 @option{--delete} commands will not work on any other kind of file.
10618 Some media simply cannot be backspaced, which means these commands and
10619 options will never be able to work on them. These non-backspacing
10620 media include pipes and cartridge tape drives.
10621
10622 Some other media can be backspaced, and @command{tar} will work on them
10623 once @command{tar} is modified to do so.
10624
10625 Archives created with the @option{--multi-volume}, @option{--label}, and
10626 @option{--incremental} (@option{-G}) options may not be readable by other version
10627 of @command{tar}. In particular, restoring a file that was split over
10628 a volume boundary will require some careful work with @command{dd}, if
10629 it can be done at all. Other versions of @command{tar} may also create
10630 an empty file whose name is that of the volume header. Some versions
10631 of @command{tar} may create normal files instead of directories archived
10632 with the @option{--incremental} (@option{-G}) option.
10633
10634 @node Common Problems and Solutions
10635 @section Some Common Problems and their Solutions
10636
10637 @ifclear PUBLISH
10638
10639 @format
10640 errors from system:
10641 permission denied
10642 no such file or directory
10643 not owner
10644
10645 errors from @command{tar}:
10646 directory checksum error
10647 header format error
10648
10649 errors from media/system:
10650 i/o error
10651 device busy
10652 @end format
10653
10654 @end ifclear
10655
10656 @node Blocking
10657 @section Blocking
10658 @cindex block
10659 @cindex record
10660
10661 @dfn{Block} and @dfn{record} terminology is rather confused, and it
10662 is also confusing to the expert reader. On the other hand, readers
10663 who are new to the field have a fresh mind, and they may safely skip
10664 the next two paragraphs, as the remainder of this manual uses those
10665 two terms in a quite consistent way.
10666
10667 John Gilmore, the writer of the public domain @command{tar} from which
10668 @GNUTAR{} was originally derived, wrote (June 1995):
10669
10670 @quotation
10671 The nomenclature of tape drives comes from IBM, where I believe
10672 they were invented for the IBM 650 or so. On IBM mainframes, what
10673 is recorded on tape are tape blocks. The logical organization of
10674 data is into records. There are various ways of putting records into
10675 blocks, including @code{F} (fixed sized records), @code{V} (variable
10676 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
10677 to a block), @code{VB} (variable size records, @var{n} to a block),
10678 @code{VSB} (variable spanned blocked: variable sized records that can
10679 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
10680 parameter specified this to the operating system.
10681
10682 The Unix man page on @command{tar} was totally confused about this.
10683 When I wrote @code{PD TAR}, I used the historically correct terminology
10684 (@command{tar} writes data records, which are grouped into blocks).
10685 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
10686 here), and now Fran@,{c}ois has migrated that terminology back
10687 into the source code too.
10688 @end quotation
10689
10690 The term @dfn{physical block} means the basic transfer chunk from or
10691 to a device, after which reading or writing may stop without anything
10692 being lost. In this manual, the term @dfn{block} usually refers to
10693 a disk physical block, @emph{assuming} that each disk block is 512
10694 bytes in length. It is true that some disk devices have different
10695 physical blocks, but @command{tar} ignore these differences in its own
10696 format, which is meant to be portable, so a @command{tar} block is always
10697 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
10698 The term @dfn{logical block} often represents the basic chunk of
10699 allocation of many disk blocks as a single entity, which the operating
10700 system treats somewhat atomically; this concept is only barely used
10701 in @GNUTAR{}.
10702
10703 The term @dfn{physical record} is another way to speak of a physical
10704 block, those two terms are somewhat interchangeable. In this manual,
10705 the term @dfn{record} usually refers to a tape physical block,
10706 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
10707 It is true that archives may be put on disk or used with pipes,
10708 but nevertheless, @command{tar} tries to read and write the archive one
10709 @dfn{record} at a time, whatever the medium in use. One record is made
10710 up of an integral number of blocks, and this operation of putting many
10711 disk blocks into a single tape block is called @dfn{reblocking}, or
10712 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
10713 the logical organization of many characters into something meaningful
10714 to the application. The term @dfn{unit record} describes a small set
10715 of characters which are transmitted whole to or by the application,
10716 and often refers to a line of text. Those two last terms are unrelated
10717 to what we call a @dfn{record} in @GNUTAR{}.
10718
10719 When writing to tapes, @command{tar} writes the contents of the archive
10720 in chunks known as @dfn{records}. To change the default blocking
10721 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
10722 @var{512-size}}) option. Each record will then be composed of
10723 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
10724 @xref{Standard}.) Each file written to the archive uses at least one
10725 full record. As a result, using a larger record size can result in
10726 more wasted space for small files. On the other hand, a larger record
10727 size can often be read and written much more efficiently.
10728
10729 Further complicating the problem is that some tape drives ignore the
10730 blocking entirely. For these, a larger record size can still improve
10731 performance (because the software layers above the tape drive still
10732 honor the blocking), but not as dramatically as on tape drives that
10733 honor blocking.
10734
10735 When reading an archive, @command{tar} can usually figure out the
10736 record size on itself. When this is the case, and a non-standard
10737 record size was used when the archive was created, @command{tar} will
10738 print a message about a non-standard blocking factor, and then operate
10739 normally. On some tape devices, however, @command{tar} cannot figure
10740 out the record size itself. On most of those, you can specify a
10741 blocking factor (with @option{--blocking-factor}) larger than the
10742 actual blocking factor, and then use the @option{--read-full-records}
10743 (@option{-B}) option. (If you specify a blocking factor with
10744 @option{--blocking-factor} and don't use the
10745 @option{--read-full-records} option, then @command{tar} will not
10746 attempt to figure out the recording size itself.) On some devices,
10747 you must always specify the record size exactly with
10748 @option{--blocking-factor} when reading, because @command{tar} cannot
10749 figure it out. In any case, use @option{--list} (@option{-t}) before
10750 doing any extractions to see whether @command{tar} is reading the archive
10751 correctly.
10752
10753 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
10754 putting them into records is to put a whole number of them (one or
10755 more) into each record. @command{tar} records are all the same size;
10756 at the end of the file there's a block containing all zeros, which
10757 is how you tell that the remainder of the last record(s) are garbage.
10758
10759 In a standard @command{tar} file (no options), the block size is 512
10760 and the record size is 10240, for a blocking factor of 20. What the
10761 @option{--blocking-factor} option does is sets the blocking factor,
10762 changing the record size while leaving the block size at 512 bytes.
10763 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
10764 most tape drives these days prefer much bigger records in order to
10765 stream and not waste tape. When writing tapes for myself, some tend
10766 to use a factor of the order of 2048, say, giving a record size of
10767 around one megabyte.
10768
10769 If you use a blocking factor larger than 20, older @command{tar}
10770 programs might not be able to read the archive, so we recommend this
10771 as a limit to use in practice. @GNUTAR{}, however,
10772 will support arbitrarily large record sizes, limited only by the
10773 amount of virtual memory or the physical characteristics of the tape
10774 device.
10775
10776 @menu
10777 * Format Variations:: Format Variations
10778 * Blocking Factor:: The Blocking Factor of an Archive
10779 @end menu
10780
10781 @node Format Variations
10782 @subsection Format Variations
10783 @cindex Format Parameters
10784 @cindex Format Options
10785 @cindex Options, archive format specifying
10786 @cindex Options, format specifying
10787 @UNREVISED
10788
10789 Format parameters specify how an archive is written on the archive
10790 media. The best choice of format parameters will vary depending on
10791 the type and number of files being archived, and on the media used to
10792 store the archive.
10793
10794 To specify format parameters when accessing or creating an archive,
10795 you can use the options described in the following sections.
10796 If you do not specify any format parameters, @command{tar} uses
10797 default parameters. You cannot modify a compressed archive.
10798 If you create an archive with the @option{--blocking-factor} option
10799 specified (@pxref{Blocking Factor}), you must specify that
10800 blocking-factor when operating on the archive. @xref{Formats}, for other
10801 examples of format parameter considerations.
10802
10803 @node Blocking Factor
10804 @subsection The Blocking Factor of an Archive
10805 @cindex Blocking Factor
10806 @cindex Record Size
10807 @cindex Number of blocks per record
10808 @cindex Number of bytes per record
10809 @cindex Bytes per record
10810 @cindex Blocks per record
10811 @UNREVISED
10812
10813 @opindex blocking-factor
10814 The data in an archive is grouped into blocks, which are 512 bytes.
10815 Blocks are read and written in whole number multiples called
10816 @dfn{records}. The number of blocks in a record (i.e., the size of a
10817 record in units of 512 bytes) is called the @dfn{blocking factor}.
10818 The @option{--blocking-factor=@var{512-size}} (@option{-b
10819 @var{512-size}}) option specifies the blocking factor of an archive.
10820 The default blocking factor is typically 20 (i.e., 10240 bytes), but
10821 can be specified at installation. To find out the blocking factor of
10822 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
10823 This may not work on some devices.
10824
10825 Records are separated by gaps, which waste space on the archive media.
10826 If you are archiving on magnetic tape, using a larger blocking factor
10827 (and therefore larger records) provides faster throughput and allows you
10828 to fit more data on a tape (because there are fewer gaps). If you are
10829 archiving on cartridge, a very large blocking factor (say 126 or more)
10830 greatly increases performance. A smaller blocking factor, on the other
10831 hand, may be useful when archiving small files, to avoid archiving lots
10832 of nulls as @command{tar} fills out the archive to the end of the record.
10833 In general, the ideal record size depends on the size of the
10834 inter-record gaps on the tape you are using, and the average size of the
10835 files you are archiving. @xref{create}, for information on
10836 writing archives.
10837
10838 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
10839
10840 Archives with blocking factors larger than 20 cannot be read
10841 by very old versions of @command{tar}, or by some newer versions
10842 of @command{tar} running on old machines with small address spaces.
10843 With @GNUTAR{}, the blocking factor of an archive is limited
10844 only by the maximum record size of the device containing the archive,
10845 or by the amount of available virtual memory.
10846
10847 Also, on some systems, not using adequate blocking factors, as sometimes
10848 imposed by the device drivers, may yield unexpected diagnostics. For
10849 example, this has been reported:
10850
10851 @smallexample
10852 Cannot write to /dev/dlt: Invalid argument
10853 @end smallexample
10854
10855 @noindent
10856 In such cases, it sometimes happen that the @command{tar} bundled by
10857 the system is aware of block size idiosyncrasies, while @GNUTAR{}
10858 requires an explicit specification for the block size,
10859 which it cannot guess. This yields some people to consider
10860 @GNUTAR{} is misbehaving, because by comparison,
10861 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
10862 for example, might resolve the problem.
10863
10864 If you use a non-default blocking factor when you create an archive, you
10865 must specify the same blocking factor when you modify that archive. Some
10866 archive devices will also require you to specify the blocking factor when
10867 reading that archive, however this is not typically the case. Usually, you
10868 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
10869 reports a non-default record size and then lists the archive members as
10870 it would normally. To extract files from an archive with a non-standard
10871 blocking factor (particularly if you're not sure what the blocking factor
10872 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
10873 specifying a blocking factor larger then the blocking factor of the archive
10874 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
10875 @xref{list}, for more information on the @option{--list} (@option{-t})
10876 operation. @xref{Reading}, for a more detailed explanation of that option.
10877
10878 @table @option
10879 @item --blocking-factor=@var{number}
10880 @itemx -b @var{number}
10881 Specifies the blocking factor of an archive. Can be used with any
10882 operation, but is usually not necessary with @option{--list} (@option{-t}).
10883 @end table
10884
10885 Device blocking
10886
10887 @table @option
10888 @item -b @var{blocks}
10889 @itemx --blocking-factor=@var{blocks}
10890 Set record size to @math{@var{blocks}*512} bytes.
10891
10892 This option is used to specify a @dfn{blocking factor} for the archive.
10893 When reading or writing the archive, @command{tar}, will do reads and writes
10894 of the archive in records of @math{@var{block}*512} bytes. This is true
10895 even when the archive is compressed. Some devices requires that all
10896 write operations be a multiple of a certain size, and so, @command{tar}
10897 pads the archive out to the next record boundary.
10898
10899 The default blocking factor is set when @command{tar} is compiled, and is
10900 typically 20. Blocking factors larger than 20 cannot be read by very
10901 old versions of @command{tar}, or by some newer versions of @command{tar}
10902 running on old machines with small address spaces.
10903
10904 With a magnetic tape, larger records give faster throughput and fit
10905 more data on a tape (because there are fewer inter-record gaps).
10906 If the archive is in a disk file or a pipe, you may want to specify
10907 a smaller blocking factor, since a large one will result in a large
10908 number of null bytes at the end of the archive.
10909
10910 When writing cartridge or other streaming tapes, a much larger
10911 blocking factor (say 126 or more) will greatly increase performance.
10912 However, you must specify the same blocking factor when reading or
10913 updating the archive.
10914
10915 Apparently, Exabyte drives have a physical block size of 8K bytes.
10916 If we choose our blocksize as a multiple of 8k bytes, then the problem
10917 seems to disappear. Id est, we are using block size of 112 right
10918 now, and we haven't had the problem since we switched@dots{}
10919
10920 With @GNUTAR{} the blocking factor is limited only
10921 by the maximum record size of the device containing the archive, or by
10922 the amount of available virtual memory.
10923
10924 However, deblocking or reblocking is virtually avoided in a special
10925 case which often occurs in practice, but which requires all the
10926 following conditions to be simultaneously true:
10927 @itemize @bullet
10928 @item
10929 the archive is subject to a compression option,
10930 @item
10931 the archive is not handled through standard input or output, nor
10932 redirected nor piped,
10933 @item
10934 the archive is directly handled to a local disk, instead of any special
10935 device,
10936 @item
10937 @option{--blocking-factor} is not explicitly specified on the @command{tar}
10938 invocation.
10939 @end itemize
10940
10941 If the output goes directly to a local disk, and not through
10942 stdout, then the last write is not extended to a full record size.
10943 Otherwise, reblocking occurs. Here are a few other remarks on this
10944 topic:
10945
10946 @itemize @bullet
10947
10948 @item
10949 @command{gzip} will complain about trailing garbage if asked to
10950 uncompress a compressed archive on tape, there is an option to turn
10951 the message off, but it breaks the regularity of simply having to use
10952 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
10953 silently ignoring any number of trailing zeros. I'll ask Jean-loup
10954 Gailly, by sending a copy of this message to him.
10955
10956 @item
10957 @command{compress} does not show this problem, but as Jean-loup pointed
10958 out to Michael, @samp{compress -d} silently adds garbage after
10959 the result of decompression, which tar ignores because it already
10960 recognized its end-of-file indicator. So this bug may be safely
10961 ignored.
10962
10963 @item
10964 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
10965 but will still return an exit status of 2 which tar reports in turn.
10966 @command{tar} might ignore the exit status returned, but I hate doing
10967 that, as it weakens the protection @command{tar} offers users against
10968 other possible problems at decompression time. If @command{gzip} was
10969 silently skipping trailing zeros @emph{and} also avoiding setting the
10970 exit status in this innocuous case, that would solve this situation.
10971
10972 @item
10973 @command{tar} should become more solid at not stopping to read a pipe at
10974 the first null block encountered. This inelegantly breaks the pipe.
10975 @command{tar} should rather drain the pipe out before exiting itself.
10976 @end itemize
10977
10978 @xopindex{ignore-zeros, short description}
10979 @item -i
10980 @itemx --ignore-zeros
10981 Ignore blocks of zeros in archive (means EOF).
10982
10983 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
10984 of zeros in the archive. Normally a block of zeros indicates the
10985 end of the archive, but when reading a damaged archive, or one which
10986 was created by concatenating several archives together, this option
10987 allows @command{tar} to read the entire archive. This option is not on
10988 by default because many versions of @command{tar} write garbage after
10989 the zeroed blocks.
10990
10991 Note that this option causes @command{tar} to read to the end of the
10992 archive file, which may sometimes avoid problems when multiple files
10993 are stored on a single physical tape.
10994
10995 @xopindex{read-full-records, short description}
10996 @item -B
10997 @itemx --read-full-records
10998 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
10999
11000 If @option{--read-full-records} is used, @command{tar}
11001 will not panic if an attempt to read a record from the archive does
11002 not return a full record. Instead, @command{tar} will keep reading
11003 until it has obtained a full
11004 record.
11005
11006 This option is turned on by default when @command{tar} is reading
11007 an archive from standard input, or from a remote machine. This is
11008 because on @acronym{BSD} Unix systems, a read of a pipe will return however
11009 much happens to be in the pipe, even if it is less than @command{tar}
11010 requested. If this option was not used, @command{tar} would fail as
11011 soon as it read an incomplete record from the pipe.
11012
11013 This option is also useful with the commands for updating an archive.
11014
11015 @end table
11016
11017 Tape blocking
11018
11019 @FIXME{Appropriate options should be moved here from elsewhere.}
11020
11021 @cindex blocking factor
11022 @cindex tape blocking
11023
11024 When handling various tapes or cartridges, you have to take care of
11025 selecting a proper blocking, that is, the number of disk blocks you
11026 put together as a single tape block on the tape, without intervening
11027 tape gaps. A @dfn{tape gap} is a small landing area on the tape
11028 with no information on it, used for decelerating the tape to a
11029 full stop, and for later regaining the reading or writing speed.
11030 When the tape driver starts reading a record, the record has to
11031 be read whole without stopping, as a tape gap is needed to stop the
11032 tape motion without losing information.
11033
11034 @cindex Exabyte blocking
11035 @cindex DAT blocking
11036 Using higher blocking (putting more disk blocks per tape block) will use
11037 the tape more efficiently as there will be less tape gaps. But reading
11038 such tapes may be more difficult for the system, as more memory will be
11039 required to receive at once the whole record. Further, if there is a
11040 reading error on a huge record, this is less likely that the system will
11041 succeed in recovering the information. So, blocking should not be too
11042 low, nor it should be too high. @command{tar} uses by default a blocking of
11043 20 for historical reasons, and it does not really matter when reading or
11044 writing to disk. Current tape technology would easily accommodate higher
11045 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
11046 We were told that for some DLT drives, the blocking should be a multiple
11047 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
11048 Other manufacturers may use different recommendations for the same tapes.
11049 This might also depends of the buffering techniques used inside modern
11050 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
11051 Others request blocking to be some exponent of two.
11052
11053 So, there is no fixed rule for blocking. But blocking at read time
11054 should ideally be the same as blocking used at write time. At one place
11055 I know, with a wide variety of equipment, they found it best to use a
11056 blocking of 32 to guarantee that their tapes are fully interchangeable.
11057
11058 I was also told that, for recycled tapes, prior erasure (by the same
11059 drive unit that will be used to create the archives) sometimes lowers
11060 the error rates observed at rewriting time.
11061
11062 I might also use @option{--number-blocks} instead of
11063 @option{--block-number}, so @option{--block} will then expand to
11064 @option{--blocking-factor} unambiguously.
11065
11066 @node Many
11067 @section Many Archives on One Tape
11068
11069 @FIXME{Appropriate options should be moved here from elsewhere.}
11070
11071 @findex ntape @r{device}
11072 Most tape devices have two entries in the @file{/dev} directory, or
11073 entries that come in pairs, which differ only in the minor number for
11074 this device. Let's take for example @file{/dev/tape}, which often
11075 points to the only or usual tape device of a given system. There might
11076 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
11077 name is the @emph{rewinding} version of the device, while the name
11078 having @samp{nr} in it is the @emph{no rewinding} version of the same
11079 device.
11080
11081 A rewinding tape device will bring back the tape to its beginning point
11082 automatically when this device is opened or closed. Since @command{tar}
11083 opens the archive file before using it and closes it afterwards, this
11084 means that a simple:
11085
11086 @smallexample
11087 $ @kbd{tar cf /dev/tape @var{directory}}
11088 @end smallexample
11089
11090 @noindent
11091 will reposition the tape to its beginning both prior and after saving
11092 @var{directory} contents to it, thus erasing prior tape contents and
11093 making it so that any subsequent write operation will destroy what has
11094 just been saved.
11095
11096 @cindex tape positioning
11097 So, a rewinding device is normally meant to hold one and only one file.
11098 If you want to put more than one @command{tar} archive on a given tape, you
11099 will need to avoid using the rewinding version of the tape device. You
11100 will also have to pay special attention to tape positioning. Errors in
11101 positioning may overwrite the valuable data already on your tape. Many
11102 people, burnt by past experiences, will only use rewinding devices and
11103 limit themselves to one file per tape, precisely to avoid the risk of
11104 such errors. Be fully aware that writing at the wrong position on a
11105 tape loses all information past this point and most probably until the
11106 end of the tape, and this destroyed information @emph{cannot} be
11107 recovered.
11108
11109 To save @var{directory-1} as a first archive at the beginning of a
11110 tape, and leave that tape ready for a second archive, you should use:
11111
11112 @smallexample
11113 $ @kbd{mt -f /dev/nrtape rewind}
11114 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
11115 @end smallexample
11116
11117 @cindex tape marks
11118 @dfn{Tape marks} are special magnetic patterns written on the tape
11119 media, which are later recognizable by the reading hardware. These
11120 marks are used after each file, when there are many on a single tape.
11121 An empty file (that is to say, two tape marks in a row) signal the
11122 logical end of the tape, after which no file exist. Usually,
11123 non-rewinding tape device drivers will react to the close request issued
11124 by @command{tar} by first writing two tape marks after your archive, and by
11125 backspacing over one of these. So, if you remove the tape at that time
11126 from the tape drive, it is properly terminated. But if you write
11127 another file at the current position, the second tape mark will be
11128 erased by the new information, leaving only one tape mark between files.
11129
11130 So, you may now save @var{directory-2} as a second archive after the
11131 first on the same tape by issuing the command:
11132
11133 @smallexample
11134 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
11135 @end smallexample
11136
11137 @noindent
11138 and so on for all the archives you want to put on the same tape.
11139
11140 Another usual case is that you do not write all the archives the same
11141 day, and you need to remove and store the tape between two archive
11142 sessions. In general, you must remember how many files are already
11143 saved on your tape. Suppose your tape already has 16 files on it, and
11144 that you are ready to write the 17th. You have to take care of skipping
11145 the first 16 tape marks before saving @var{directory-17}, say, by using
11146 these commands:
11147
11148 @smallexample
11149 $ @kbd{mt -f /dev/nrtape rewind}
11150 $ @kbd{mt -f /dev/nrtape fsf 16}
11151 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
11152 @end smallexample
11153
11154 In all the previous examples, we put aside blocking considerations, but
11155 you should do the proper things for that as well. @xref{Blocking}.
11156
11157 @menu
11158 * Tape Positioning:: Tape Positions and Tape Marks
11159 * mt:: The @command{mt} Utility
11160 @end menu
11161
11162 @node Tape Positioning
11163 @subsection Tape Positions and Tape Marks
11164 @UNREVISED
11165
11166 Just as archives can store more than one file from the file system,
11167 tapes can store more than one archive file. To keep track of where
11168 archive files (or any other type of file stored on tape) begin and
11169 end, tape archive devices write magnetic @dfn{tape marks} on the
11170 archive media. Tape drives write one tape mark between files,
11171 two at the end of all the file entries.
11172
11173 If you think of data as a series of records "rrrr"'s, and tape marks as
11174 "*"'s, a tape might look like the following:
11175
11176 @smallexample
11177 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
11178 @end smallexample
11179
11180 Tape devices read and write tapes using a read/write @dfn{tape
11181 head}---a physical part of the device which can only access one
11182 point on the tape at a time. When you use @command{tar} to read or
11183 write archive data from a tape device, the device will begin reading
11184 or writing from wherever on the tape the tape head happens to be,
11185 regardless of which archive or what part of the archive the tape
11186 head is on. Before writing an archive, you should make sure that no
11187 data on the tape will be overwritten (unless it is no longer needed).
11188 Before reading an archive, you should make sure the tape head is at
11189 the beginning of the archive you want to read. You can do it manually
11190 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
11191 that automatically (@pxref{Scripted Restoration}).
11192
11193 If you want to add new archive file entries to a tape, you should
11194 advance the tape to the end of the existing file entries, backspace
11195 over the last tape mark, and write the new archive file. If you were
11196 to add two archives to the example above, the tape might look like the
11197 following:
11198
11199 @smallexample
11200 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
11201 @end smallexample
11202
11203 @node mt
11204 @subsection The @command{mt} Utility
11205 @UNREVISED
11206
11207 @FIXME{Is it true that this only works on non-block devices?
11208 should explain the difference, (fixed or variable).}
11209 @xref{Blocking Factor}.
11210
11211 You can use the @command{mt} utility to advance or rewind a tape past a
11212 specified number of archive files on the tape. This will allow you
11213 to move to the beginning of an archive before extracting or reading
11214 it, or to the end of all the archives before writing a new one.
11215 @FIXME{Why isn't there an "advance 'til you find two tape marks
11216 together"?}
11217
11218 The syntax of the @command{mt} command is:
11219
11220 @smallexample
11221 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
11222 @end smallexample
11223
11224 where @var{tapename} is the name of the tape device, @var{number} is
11225 the number of times an operation is performed (with a default of one),
11226 and @var{operation} is one of the following:
11227
11228 @FIXME{is there any use for record operations?}
11229
11230 @table @option
11231 @item eof
11232 @itemx weof
11233 Writes @var{number} tape marks at the current position on the tape.
11234
11235 @item fsf
11236 Moves tape position forward @var{number} files.
11237
11238 @item bsf
11239 Moves tape position back @var{number} files.
11240
11241 @item rewind
11242 Rewinds the tape. (Ignores @var{number}.)
11243
11244 @item offline
11245 @itemx rewoff1
11246 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}.)
11247
11248 @item status
11249 Prints status information about the tape unit.
11250
11251 @end table
11252
11253 If you don't specify a @var{tapename}, @command{mt} uses the environment
11254 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
11255 the default device specified in your @file{sys/mtio.h} file
11256 (@code{DEFTAPE} variable). If this is not defined, the program will
11257 display a descriptive error message and exit with code 1.
11258
11259 @command{mt} returns a 0 exit status when the operation(s) were
11260 successful, 1 if the command was unrecognized, and 2 if an operation
11261 failed.
11262
11263 @node Using Multiple Tapes
11264 @section Using Multiple Tapes
11265
11266 Often you might want to write a large archive, one larger than will fit
11267 on the actual tape you are using. In such a case, you can run multiple
11268 @command{tar} commands, but this can be inconvenient, particularly if you
11269 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
11270 Therefore, @command{tar} provides a special mode for creating
11271 multi-volume archives.
11272
11273 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
11274 on several media volumes of fixed size. Although in this section we will
11275 often call @samp{volume} a @dfn{tape}, there is absolutely no
11276 requirement for multi-volume archives to be stored on tapes. Instead,
11277 they can use whatever media type the user finds convenient, they can
11278 even be located on files.
11279
11280 When creating a multi-volume archive, @GNUTAR{} continues to fill
11281 current volume until it runs out of space, then it switches to
11282 next volume (usually the operator is queried to replace the tape on
11283 this point), and continues working on the new volume. This operation
11284 continues until all requested files are dumped. If @GNUTAR{} detects
11285 end of media while dumping a file, such a file is archived in split
11286 form. Some very big files can even be split across several volumes.
11287
11288 Each volume is itself a valid @GNUTAR{} archive, so it can be read
11289 without any special options. Consequently any file member residing
11290 entirely on one volume can be extracted or otherwise operated upon
11291 without needing the other volume. Sure enough, to extract a split
11292 member you would need all volumes its parts reside on.
11293
11294 Multi-volume archives suffer from several limitations. In particular,
11295 they cannot be compressed.
11296
11297 @GNUTAR{} is able to create multi-volume archives of two formats
11298 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
11299
11300 @menu
11301 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
11302 * Tape Files:: Tape Files
11303 * Tarcat:: Concatenate Volumes into a Single Archive
11304
11305 @end menu
11306
11307 @node Multi-Volume Archives
11308 @subsection Archives Longer than One Tape or Disk
11309 @cindex Multi-volume archives
11310
11311 @opindex multi-volume
11312 To create an archive that is larger than will fit on a single unit of
11313 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
11314 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
11315 archive can be manipulated like any other archive (provided the
11316 @option{--multi-volume} option is specified), but is stored on more
11317 than one tape or file.
11318
11319 When you specify @option{--multi-volume}, @command{tar} does not report an
11320 error when it comes to the end of an archive volume (when reading), or
11321 the end of the media (when writing). Instead, it prompts you to load
11322 a new storage volume. If the archive is on a magnetic tape, you
11323 should change tapes when you see the prompt; if the archive is on a
11324 floppy disk, you should change disks; etc.
11325
11326 @table @option
11327 @item --multi-volume
11328 @itemx -M
11329 Creates a multi-volume archive, when used in conjunction with
11330 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
11331 archive, specify @option{--multi-volume} in conjunction with that
11332 operation.
11333 For example:
11334
11335 @smallexample
11336 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
11337 @end smallexample
11338 @end table
11339
11340 The method @command{tar} uses to detect end of tape is not perfect, and
11341 fails on some operating systems or on some devices. If @command{tar}
11342 cannot detect the end of the tape itself, you can use
11343 @option{--tape-length} option to inform it about the capacity of the
11344 tape:
11345
11346 @anchor{tape-length}
11347 @table @option
11348 @opindex tape-length
11349 @item --tape-length=@var{size}[@var{suf}]
11350 @itemx -L @var{size}[@var{suf}]
11351 Set maximum length of a volume. The @var{suf}, if given, specifies
11352 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
11353 megabytes (@pxref{size-suffixes}, for a list of allowed size
11354 suffixes). Without @var{suf}, units of 1024 bytes (kilobyte) are
11355 assumed.
11356
11357 This option selects @option{--multi-volume} automatically. For example:
11358
11359 @smallexample
11360 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
11361 @end smallexample
11362
11363 @noindent
11364 or, which is equivalent:
11365
11366 @smallexample
11367 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
11368 @end smallexample
11369 @end table
11370
11371 @anchor{change volume prompt}
11372 When @GNUTAR{} comes to the end of a storage media, it asks you to
11373 change the volume. The built-in prompt for POSIX locale
11374 is@footnote{If you run @GNUTAR{} under a different locale, the
11375 translation to the locale's language will be used.}:
11376
11377 @smallexample
11378 Prepare volume #@var{n} for '@var{archive}' and hit return:
11379 @end smallexample
11380
11381 @noindent
11382 where @var{n} is the ordinal number of the volume to be created and
11383 @var{archive} is archive file or device name.
11384
11385 When prompting for a new tape, @command{tar} accepts any of the following
11386 responses:
11387
11388 @table @kbd
11389 @item ?
11390 Request @command{tar} to explain possible responses.
11391 @item q
11392 Request @command{tar} to exit immediately.
11393 @item n @var{file-name}
11394 Request @command{tar} to write the next volume on the file @var{file-name}.
11395 @item !
11396 Request @command{tar} to run a subshell. This option can be disabled
11397 by giving @option{--restrict} command line option to
11398 @command{tar}@footnote{@xref{--restrict}, for more information about
11399 this option.}.
11400 @item y
11401 Request @command{tar} to begin writing the next volume.
11402 @end table
11403
11404 (You should only type @samp{y} after you have changed the tape;
11405 otherwise @command{tar} will write over the volume it just finished.)
11406
11407 @cindex Volume number file
11408 @cindex volno file
11409 @anchor{volno-file}
11410 @opindex volno-file
11411 The volume number used by @command{tar} in its tape-changing prompt
11412 can be changed; if you give the
11413 @option{--volno-file=@var{file-of-number}} option, then
11414 @var{file-of-number} should be an non-existing file to be created, or
11415 else, a file already containing a decimal number. That number will be
11416 used as the volume number of the first volume written. When
11417 @command{tar} is finished, it will rewrite the file with the
11418 now-current volume number. (This does not change the volume number
11419 written on a tape label, as per @ref{label}, it @emph{only} affects
11420 the number used in the prompt.)
11421
11422 @cindex End-of-archive info script
11423 @cindex Info script
11424 @anchor{info-script}
11425 @opindex info-script
11426 @opindex new-volume-script
11427 If you want more elaborate behavior than this, you can write a special
11428 @dfn{new volume script}, that will be responsible for changing the
11429 volume, and instruct @command{tar} to use it instead of its normal
11430 prompting procedure:
11431
11432 @table @option
11433 @item --info-script=@var{command}
11434 @itemx --new-volume-script=@var{command}
11435 @itemx -F @var{command}
11436 Specify the command to invoke when switching volumes. The @var{command}
11437 can be used to eject cassettes, or to broadcast messages such as
11438 @samp{Someone please come change my tape} when performing unattended
11439 backups.
11440 @end table
11441
11442 The @var{command} can contain additional options, if such are needed.
11443 @xref{external, Running External Commands}, for a detailed discussion
11444 of the way @GNUTAR{} runs external commands. It inherits
11445 @command{tar}'s shell environment. Additional data is passed to it
11446 via the following environment variables:
11447
11448 @table @env
11449 @vrindex TAR_VERSION, info script environment variable
11450 @item TAR_VERSION
11451 @GNUTAR{} version number.
11452
11453 @vrindex TAR_ARCHIVE, info script environment variable
11454 @item TAR_ARCHIVE
11455 The name of the archive @command{tar} is processing.
11456
11457 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
11458 @item TAR_BLOCKING_FACTOR
11459 Current blocking factor (@pxref{Blocking}).
11460
11461 @vrindex TAR_VOLUME, info script environment variable
11462 @item TAR_VOLUME
11463 Ordinal number of the volume @command{tar} is about to start.
11464
11465 @vrindex TAR_SUBCOMMAND, info script environment variable
11466 @item TAR_SUBCOMMAND
11467 A short option describing the operation @command{tar} is executing.
11468 @xref{Operations}, for a complete list of subcommand options.
11469
11470 @vrindex TAR_FORMAT, info script environment variable
11471 @item TAR_FORMAT
11472 Format of the archive being processed. @xref{Formats}, for a complete
11473 list of archive format names.
11474
11475 @vrindex TAR_FD, info script environment variable
11476 @item TAR_FD
11477 File descriptor which can be used to communicate the new volume
11478 name to @command{tar}.
11479 @end table
11480
11481 These variables can be used in the @var{command} itself, provided that
11482 they are properly quoted to prevent them from being expanded by the
11483 shell that invokes @command{tar}.
11484
11485 The volume script can instruct @command{tar} to use new archive name,
11486 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
11487
11488 If the info script fails, @command{tar} exits; otherwise, it begins
11489 writing the next volume.
11490
11491 If you want @command{tar} to cycle through a series of files or tape
11492 drives, there are three approaches to choose from. First of all, you
11493 can give @command{tar} multiple @option{--file} options. In this case
11494 the specified files will be used, in sequence, as the successive
11495 volumes of the archive. Only when the first one in the sequence needs
11496 to be used again will @command{tar} prompt for a tape change (or run
11497 the info script). For example, suppose someone has two tape drives on
11498 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
11499 @GNUTAR{} to switch to the second drive when it needs to write the
11500 second tape, and then back to the first tape, etc., just do either of:
11501
11502 @smallexample
11503 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
11504 $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
11505 @end smallexample
11506
11507 The second method is to use the @samp{n} response to the tape-change
11508 prompt.
11509
11510 Finally, the most flexible approach is to use a volume script, that
11511 writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
11512 following volume script will create a series of archive files, named
11513 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
11514 archive being created (as given by @option{--file} option) and
11515 @var{vol} is the ordinal number of the archive being created:
11516
11517 @smallexample
11518 @group
11519 #! /bin/bash
11520 # For this script it's advisable to use a shell, such as Bash,
11521 # that supports a TAR_FD value greater than 9.
11522
11523 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
11524
11525 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
11526 case $TAR_SUBCOMMAND in
11527 -c) ;;
11528 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
11529 ;;
11530 *) exit 1
11531 esac
11532
11533 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
11534 @end group
11535 @end smallexample
11536
11537 The same script can be used while listing, comparing or extracting
11538 from the created archive. For example:
11539
11540 @smallexample
11541 @group
11542 # @r{Create a multi-volume archive:}
11543 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
11544 # @r{Extract from the created archive:}
11545 $ @kbd{tar -x -f archive.tar -F new-volume .}
11546 @end group
11547 @end smallexample
11548
11549 @noindent
11550 Notice, that the first command had to use @option{-L} option, since
11551 otherwise @GNUTAR{} will end up writing everything to file
11552 @file{archive.tar}.
11553
11554 You can read each individual volume of a multi-volume archive as if it
11555 were an archive by itself. For example, to list the contents of one
11556 volume, use @option{--list}, without @option{--multi-volume} specified.
11557 To extract an archive member from one volume (assuming it is described
11558 that volume), use @option{--extract}, again without
11559 @option{--multi-volume}.
11560
11561 If an archive member is split across volumes (i.e., its entry begins on
11562 one volume of the media and ends on another), you need to specify
11563 @option{--multi-volume} to extract it successfully. In this case, you
11564 should load the volume where the archive member starts, and use
11565 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
11566 volumes as it needs them. @xref{extracting archives}, for more
11567 information about extracting archives.
11568
11569 Multi-volume archives can be modified like any other archive. To add
11570 files to a multi-volume archive, you need to only mount the last
11571 volume of the archive media (and new volumes, if needed). For all
11572 other operations, you need to use the entire archive.
11573
11574 If a multi-volume archive was labeled using
11575 @option{--label=@var{archive-label}} (@pxref{label}) when it was
11576 created, @command{tar} will not automatically label volumes which are
11577 added later. To label subsequent volumes, specify
11578 @option{--label=@var{archive-label}} again in conjunction with the
11579 @option{--append}, @option{--update} or @option{--concatenate} operation.
11580
11581 Notice that multi-volume support is a GNU extension and the archives
11582 created in this mode should be read only using @GNUTAR{}. If you
11583 absolutely have to process such archives using a third-party @command{tar}
11584 implementation, read @ref{Split Recovery}.
11585
11586 @node Tape Files
11587 @subsection Tape Files
11588 @cindex labeling archives
11589 @opindex label
11590 @UNREVISED
11591
11592 To give the archive a name which will be recorded in it, use the
11593 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
11594 option. This will write a special block identifying
11595 @var{volume-label} as the name of the archive to the front of the
11596 archive which will be displayed when the archive is listed with
11597 @option{--list}. If you are creating a multi-volume archive with
11598 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
11599 volume label will have @samp{Volume @var{nnn}} appended to the name
11600 you give, where @var{nnn} is the number of the volume of the archive.
11601 If you use the @option{--label=@var{volume-label}} option when
11602 reading an archive, it checks to make sure the label on the tape
11603 matches the one you gave. @xref{label}.
11604
11605 When @command{tar} writes an archive to tape, it creates a single
11606 tape file. If multiple archives are written to the same tape, one
11607 after the other, they each get written as separate tape files. When
11608 extracting, it is necessary to position the tape at the right place
11609 before running @command{tar}. To do this, use the @command{mt} command.
11610 For more information on the @command{mt} command and on the organization
11611 of tapes into a sequence of tape files, see @ref{mt}.
11612
11613 People seem to often do:
11614
11615 @smallexample
11616 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
11617 @end smallexample
11618
11619 or such, for pushing a common date in all volumes or an archive set.
11620
11621 @node Tarcat
11622 @subsection Concatenate Volumes into a Single Archive
11623
11624 @pindex tarcat
11625 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
11626 archive to a single @command{tar} archive. Simply concatenating all
11627 volumes into one will not work, since each volume carries an additional
11628 information at the beginning. @GNUTAR{} is shipped with the shell
11629 script @command{tarcat} designed for this purpose.
11630
11631 The script takes a list of files comprising a multi-volume archive
11632 and creates the resulting archive at the standard output. For example:
11633
11634 @smallexample
11635 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
11636 @end smallexample
11637
11638 The script implements a simple heuristics to determine the format of
11639 the first volume file and to decide how to process the rest of the
11640 files. However, it makes no attempt to verify whether the files are
11641 given in order or even if they are valid @command{tar} archives.
11642 It uses @command{dd} and does not filter its standard error, so you
11643 will usually see lots of spurious messages.
11644
11645 @FIXME{The script is not installed. Should we install it?}
11646
11647 @node label
11648 @section Including a Label in the Archive
11649 @cindex Labeling an archive
11650 @cindex Labels on the archive media
11651 @cindex Labeling multi-volume archives
11652
11653 @opindex label
11654 To avoid problems caused by misplaced paper labels on the archive
11655 media, you can include a @dfn{label} entry --- an archive member which
11656 contains the name of the archive --- in the archive itself. Use the
11657 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11658 option@footnote{Until version 1.10, that option was called
11659 @option{--volume}, but is not available under that name anymore.} in
11660 conjunction with the @option{--create} operation to include a label
11661 entry in the archive as it is being created.
11662
11663 @table @option
11664 @item --label=@var{archive-label}
11665 @itemx -V @var{archive-label}
11666 Includes an @dfn{archive-label} at the beginning of the archive when
11667 the archive is being created, when used in conjunction with the
11668 @option{--create} operation. Checks to make sure the archive label
11669 matches the one specified (when used in conjunction with any other
11670 operation).
11671 @end table
11672
11673 If you create an archive using both
11674 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11675 and @option{--multi-volume} (@option{-M}), each volume of the archive
11676 will have an archive label of the form @samp{@var{archive-label}
11677 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
11678 next, and so on. @xref{Using Multiple Tapes}, for information on
11679 creating multiple volume archives.
11680
11681 @cindex Volume label, listing
11682 @cindex Listing volume label
11683 The volume label will be displayed by @option{--list} along with
11684 the file contents. If verbose display is requested, it will also be
11685 explicitly marked as in the example below:
11686
11687 @smallexample
11688 @group
11689 $ @kbd{tar --verbose --list --file=iamanarchive}
11690 V--------- 0/0 0 1992-03-07 12:01 iamalabel--Volume Header--
11691 -rw-r--r-- ringo/user 40 1990-05-21 13:30 iamafilename
11692 @end group
11693 @end smallexample
11694
11695 @opindex test-label
11696 @anchor{--test-label option}
11697 However, @option{--list} option will cause listing entire
11698 contents of the archive, which may be undesirable (for example, if the
11699 archive is stored on a tape). You can request checking only the volume
11700 label by specifying @option{--test-label} option. This option reads only the
11701 first block of an archive, so it can be used with slow storage
11702 devices. For example:
11703
11704 @smallexample
11705 @group
11706 $ @kbd{tar --test-label --file=iamanarchive}
11707 iamalabel
11708 @end group
11709 @end smallexample
11710
11711 If @option{--test-label} is used with one or more command line
11712 arguments, @command{tar} compares the volume label with each
11713 argument. It exits with code 0 if a match is found, and with code 1
11714 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
11715 mismatch with an exit code 2 and printed a spurious diagnostics on
11716 stderr.}. No output is displayed, unless you also used the
11717 @option{--verbose} option. For example:
11718
11719 @smallexample
11720 @group
11721 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
11722 @result{} 0
11723 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
11724 @result{} 1
11725 @end group
11726 @end smallexample
11727
11728 When used with the @option{--verbose} option, @command{tar}
11729 prints the actual volume label (if any), and a verbose diagnostics in
11730 case of a mismatch:
11731
11732 @smallexample
11733 @group
11734 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
11735 iamalabel
11736 @result{} 0
11737 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
11738 iamalabel
11739 tar: Archive label mismatch
11740 @result{} 1
11741 @end group
11742 @end smallexample
11743
11744 If you request any operation, other than @option{--create}, along
11745 with using @option{--label} option, @command{tar} will first check if
11746 the archive label matches the one specified and will refuse to proceed
11747 if it does not. Use this as a safety precaution to avoid accidentally
11748 overwriting existing archives. For example, if you wish to add files
11749 to @file{archive}, presumably labeled with string @samp{My volume},
11750 you will get:
11751
11752 @smallexample
11753 @group
11754 $ @kbd{tar -rf archive --label 'My volume' .}
11755 tar: Archive not labeled to match 'My volume'
11756 @end group
11757 @end smallexample
11758
11759 @noindent
11760 in case its label does not match. This will work even if
11761 @file{archive} is not labeled at all.
11762
11763 Similarly, @command{tar} will refuse to list or extract the
11764 archive if its label doesn't match the @var{archive-label}
11765 specified. In those cases, @var{archive-label} argument is interpreted
11766 as a globbing-style pattern which must match the actual magnetic
11767 volume label. @xref{exclude}, for a precise description of how match
11768 is attempted@footnote{Previous versions of @command{tar} used full
11769 regular expression matching, or before that, only exact string
11770 matching, instead of wildcard matchers. We decided for the sake of
11771 simplicity to use a uniform matching device through
11772 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
11773 the volume label matcher will also suffix @var{archive-label} by
11774 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
11775 up. Since the volume numbering is automatically added in labels at
11776 creation time, it sounded logical to equally help the user taking care
11777 of it when the archive is being read.
11778
11779 You can also use @option{--label} to get a common information on
11780 all tapes of a series. For having this information different in each
11781 series created through a single script used on a regular basis, just
11782 manage to get some date string as part of the label. For example:
11783
11784 @smallexample
11785 @group
11786 $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
11787 $ @kbd{tar --create --file=/dev/tape --multi-volume \
11788 --label="Daily backup for `date +%Y-%m-%d`"}
11789 @end group
11790 @end smallexample
11791
11792 Some more notes about volume labels:
11793
11794 @itemize @bullet
11795 @item Each label has its own date and time, which corresponds
11796 to the time when @GNUTAR{} initially attempted to write it,
11797 often soon after the operator launches @command{tar} or types the
11798 carriage return telling that the next tape is ready.
11799
11800 @item Comparing date labels to get an idea of tape throughput is
11801 unreliable. It gives correct results only if the delays for rewinding
11802 tapes and the operator switching them were negligible, which is
11803 usually not the case.
11804 @end itemize
11805
11806 @node verify
11807 @section Verifying Data as It is Stored
11808 @cindex Verifying a write operation
11809 @cindex Double-checking a write operation
11810
11811 @table @option
11812 @item -W
11813 @itemx --verify
11814 @opindex verify, short description
11815 Attempt to verify the archive after writing.
11816 @end table
11817
11818 This option causes @command{tar} to verify the archive after writing it.
11819 Each volume is checked after it is written, and any discrepancies
11820 are recorded on the standard error output.
11821
11822 Verification requires that the archive be on a back-space-able medium.
11823 This means pipes, some cartridge tape drives, and some other devices
11824 cannot be verified.
11825
11826 You can insure the accuracy of an archive by comparing files in the
11827 system with archive members. @command{tar} can compare an archive to the
11828 file system as the archive is being written, to verify a write
11829 operation, or can compare a previously written archive, to insure that
11830 it is up to date.
11831
11832 @xopindex{verify, using with @option{--create}}
11833 @xopindex{create, using with @option{--verify}}
11834 To check for discrepancies in an archive immediately after it is
11835 written, use the @option{--verify} (@option{-W}) option in conjunction with
11836 the @option{--create} operation. When this option is
11837 specified, @command{tar} checks archive members against their counterparts
11838 in the file system, and reports discrepancies on the standard error.
11839
11840 To verify an archive, you must be able to read it from before the end
11841 of the last written entry. This option is useful for detecting data
11842 errors on some tapes. Archives written to pipes, some cartridge tape
11843 drives, and some other devices cannot be verified.
11844
11845 One can explicitly compare an already made archive with the file
11846 system by using the @option{--compare} (@option{--diff}, @option{-d})
11847 option, instead of using the more automatic @option{--verify} option.
11848 @xref{compare}.
11849
11850 Note that these two options have a slightly different intent. The
11851 @option{--compare} option checks how identical are the logical contents of some
11852 archive with what is on your disks, while the @option{--verify} option is
11853 really for checking if the physical contents agree and if the recording
11854 media itself is of dependable quality. So, for the @option{--verify}
11855 operation, @command{tar} tries to defeat all in-memory cache pertaining to
11856 the archive, while it lets the speed optimization undisturbed for the
11857 @option{--compare} option. If you nevertheless use @option{--compare} for
11858 media verification, you may have to defeat the in-memory cache yourself,
11859 maybe by opening and reclosing the door latch of your recording unit,
11860 forcing some doubt in your operating system about the fact this is really
11861 the same volume as the one just written or read.
11862
11863 The @option{--verify} option would not be necessary if drivers were indeed
11864 able to detect dependably all write failures. This sometimes require many
11865 magnetic heads, some able to read after the writes occurred. One would
11866 not say that drivers unable to detect all cases are necessarily flawed,
11867 as long as programming is concerned.
11868
11869 The @option{--verify} (@option{-W}) option will not work in
11870 conjunction with the @option{--multi-volume} (@option{-M}) option or
11871 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
11872 and @option{--delete} operations. @xref{Operations}, for more
11873 information on these operations.
11874
11875 Also, since @command{tar} normally strips leading @samp{/} from file
11876 names (@pxref{absolute}), a command like @samp{tar --verify -cf
11877 /tmp/foo.tar /etc} will work as desired only if the working directory is
11878 @file{/}, as @command{tar} uses the archive's relative member names
11879 (e.g., @file{etc/motd}) when verifying the archive.
11880
11881 @node Write Protection
11882 @section Write Protection
11883
11884 Almost all tapes and diskettes, and in a few rare cases, even disks can
11885 be @dfn{write protected}, to protect data on them from being changed.
11886 Once an archive is written, you should write protect the media to prevent
11887 the archive from being accidentally overwritten or deleted. (This will
11888 protect the archive from being changed with a tape or floppy drive---it
11889 will not protect it from magnet fields or other physical hazards.)
11890
11891 The write protection device itself is usually an integral part of the
11892 physical media, and can be a two position (write enabled/write
11893 disabled) switch, a notch which can be popped out or covered, a ring
11894 which can be removed from the center of a tape reel, or some other
11895 changeable feature.
11896
11897 @node Reliability and security
11898 @chapter Reliability and Security
11899
11900 The @command{tar} command reads and writes files as any other
11901 application does, and is subject to the usual caveats about
11902 reliability and security. This section contains some commonsense
11903 advice on the topic.
11904
11905 @menu
11906 * Reliability::
11907 * Security::
11908 @end menu
11909
11910 @node Reliability
11911 @section Reliability
11912
11913 Ideally, when @command{tar} is creating an archive, it reads from a
11914 file system that is not being modified, and encounters no errors or
11915 inconsistencies while reading and writing. If this is the case, the
11916 archive should faithfully reflect what was read. Similarly, when
11917 extracting from an archive, ideally @command{tar} ideally encounters
11918 no errors and the extracted files faithfully reflect what was in the
11919 archive.
11920
11921 However, when reading or writing real-world file systems, several
11922 things can go wrong; these include permissions problems, corruption of
11923 data, and race conditions.
11924
11925 @menu
11926 * Permissions problems::
11927 * Data corruption and repair::
11928 * Race conditions::
11929 @end menu
11930
11931 @node Permissions problems
11932 @subsection Permissions Problems
11933
11934 If @command{tar} encounters errors while reading or writing files, it
11935 normally reports an error and exits with nonzero status. The work it
11936 does may therefore be incomplete. For example, when creating an
11937 archive, if @command{tar} cannot read a file then it cannot copy the
11938 file into the archive.
11939
11940 @node Data corruption and repair
11941 @subsection Data Corruption and Repair
11942
11943 If an archive becomes corrupted by an I/O error, this may corrupt the
11944 data in an extracted file. Worse, it may corrupt the file's metadata,
11945 which may cause later parts of the archive to become misinterpreted.
11946 An tar-format archive contains a checksum that most likely will detect
11947 errors in the metadata, but it will not detect errors in the data.
11948
11949 If data corruption is a concern, you can compute and check your own
11950 checksums of an archive by using other programs, such as
11951 @command{cksum}.
11952
11953 When attempting to recover from a read error or data corruption in an
11954 archive, you may need to skip past the questionable data and read the
11955 rest of the archive. This requires some expertise in the archive
11956 format and in other software tools.
11957
11958 @node Race conditions
11959 @subsection Race conditions
11960
11961 If some other process is modifying the file system while @command{tar}
11962 is reading or writing files, the result may well be inconsistent due
11963 to race conditions. For example, if another process creates some
11964 files in a directory while @command{tar} is creating an archive
11965 containing the directory's files, @command{tar} may see some of the
11966 files but not others, or it may see a file that is in the process of
11967 being created. The resulting archive may not be a snapshot of the
11968 file system at any point in time. If an application such as a
11969 database system depends on an accurate snapshot, restoring from the
11970 @command{tar} archive of a live file system may therefore break that
11971 consistency and may break the application. The simplest way to avoid
11972 the consistency issues is to avoid making other changes to the file
11973 system while tar is reading it or writing it.
11974
11975 When creating an archive, several options are available to avoid race
11976 conditions. Some hosts have a way of snapshotting a file system, or
11977 of temporarily suspending all changes to a file system, by (say)
11978 suspending the only virtual machine that can modify a file system; if
11979 you use these facilities and have @command{tar -c} read from a
11980 snapshot when creating an archive, you can avoid inconsistency
11981 problems. More drastically, before starting @command{tar} you could
11982 suspend or shut down all processes other than @command{tar} that have
11983 access to the file system, or you could unmount the file system and
11984 then mount it read-only.
11985
11986 When extracting from an archive, one approach to avoid race conditions
11987 is to create a directory that no other process can write to, and
11988 extract into that.
11989
11990 @node Security
11991 @section Security
11992
11993 In some cases @command{tar} may be used in an adversarial situation,
11994 where an untrusted user is attempting to gain information about or
11995 modify otherwise-inaccessible files. Dealing with untrusted data
11996 (that is, data generated by an untrusted user) typically requires
11997 extra care, because even the smallest mistake in the use of
11998 @command{tar} is more likely to be exploited by an adversary than by a
11999 race condition.
12000
12001 @menu
12002 * Privacy::
12003 * Integrity::
12004 * Live untrusted data::
12005 * Security rules of thumb::
12006 @end menu
12007
12008 @node Privacy
12009 @subsection Privacy
12010
12011 Standard privacy concerns apply when using @command{tar}. For
12012 example, suppose you are archiving your home directory into a file
12013 @file{/archive/myhome.tar}. Any secret information in your home
12014 directory, such as your SSH secret keys, are copied faithfully into
12015 the archive. Therefore, if your home directory contains any file that
12016 should not be read by some other user, the archive itself should be
12017 not be readable by that user. And even if the archive's data are
12018 inaccessible to untrusted users, its metadata (such as size or
12019 last-modified date) may reveal some information about your home
12020 directory; if the metadata are intended to be private, the archive's
12021 parent directory should also be inaccessible to untrusted users.
12022
12023 One precaution is to create @file{/archive} so that it is not
12024 accessible to any user, unless that user also has permission to access
12025 all the files in your home directory.
12026
12027 Similarly, when extracting from an archive, take care that the
12028 permissions of the extracted files are not more generous than what you
12029 want. Even if the archive itself is readable only to you, files
12030 extracted from it have their own permissions that may differ.
12031
12032 @node Integrity
12033 @subsection Integrity
12034
12035 When creating archives, take care that they are not writable by a
12036 untrusted user; otherwise, that user could modify the archive, and
12037 when you later extract from the archive you will get incorrect data.
12038
12039 When @command{tar} extracts from an archive, by default it writes into
12040 files relative to the working directory. If the archive was generated
12041 by an untrusted user, that user therefore can write into any file
12042 under the working directory. If the working directory contains a
12043 symbolic link to another directory, the untrusted user can also write
12044 into any file under the referenced directory. When extracting from an
12045 untrusted archive, it is therefore good practice to create an empty
12046 directory and run @command{tar} in that directory.
12047
12048 When extracting from two or more untrusted archives, each one should
12049 be extracted independently, into different empty directories.
12050 Otherwise, the first archive could create a symbolic link into an area
12051 outside the working directory, and the second one could follow the
12052 link and overwrite data that is not under the working directory. For
12053 example, when restoring from a series of incremental dumps, the
12054 archives should have been created by a trusted process, as otherwise
12055 the incremental restores might alter data outside the working
12056 directory.
12057
12058 If you use the @option{--absolute-names} (@option{-P}) option when
12059 extracting, @command{tar} respects any file names in the archive, even
12060 file names that begin with @file{/} or contain @file{..}. As this
12061 lets the archive overwrite any file in your system that you can write,
12062 the @option{--absolute-names} (@option{-P}) option should be used only
12063 for trusted archives.
12064
12065 Conversely, with the @option{--keep-old-files} (@option{-k}) and
12066 @option{--skip-old-files} options, @command{tar} refuses to replace
12067 existing files when extracting. The difference between the two
12068 options is that the former treats existing files as errors whereas the
12069 latter just silently ignores them.
12070
12071 Finally, with the @option{--no-overwrite-dir} option, @command{tar}
12072 refuses to replace the permissions or ownership of already-existing
12073 directories. These options may help when extracting from untrusted
12074 archives.
12075
12076 @node Live untrusted data
12077 @subsection Dealing with Live Untrusted Data
12078
12079 Extra care is required when creating from or extracting into a file
12080 system that is accessible to untrusted users. For example, superusers
12081 who invoke @command{tar} must be wary about its actions being hijacked
12082 by an adversary who is reading or writing the file system at the same
12083 time that @command{tar} is operating.
12084
12085 When creating an archive from a live file system, @command{tar} is
12086 vulnerable to denial-of-service attacks. For example, an adversarial
12087 user could create the illusion of an indefinitely-deep directory
12088 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
12089 @command{tar}, or the illusion of an indefinitely-long file by
12090 creating a sparse file but arranging for blocks to be allocated just
12091 before @command{tar} reads them. There is no easy way for
12092 @command{tar} to distinguish these scenarios from legitimate uses, so
12093 you may need to monitor @command{tar}, just as you'd need to monitor
12094 any other system service, to detect such attacks.
12095
12096 While a superuser is extracting from an archive into a live file
12097 system, an untrusted user might replace a directory with a symbolic
12098 link, in hopes that @command{tar} will follow the symbolic link and
12099 extract data into files that the untrusted user does not have access
12100 to. Even if the archive was generated by the superuser, it may
12101 contain a file such as @file{d/etc/passwd} that the untrusted user
12102 earlier created in order to break in; if the untrusted user replaces
12103 the directory @file{d/etc} with a symbolic link to @file{/etc} while
12104 @command{tar} is running, @command{tar} will overwrite
12105 @file{/etc/passwd}. This attack can be prevented by extracting into a
12106 directory that is inaccessible to untrusted users.
12107
12108 Similar attacks via symbolic links are also possible when creating an
12109 archive, if the untrusted user can modify an ancestor of a top-level
12110 argument of @command{tar}. For example, an untrusted user that can
12111 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
12112 - /home/eve/Documents/yesterday} by replacing
12113 @file{/home/eve/Documents} with a symbolic link to some other
12114 location. Attacks like these can be prevented by making sure that
12115 untrusted users cannot modify any files that are top-level arguments
12116 to @command{tar}, or any ancestor directories of these files.
12117
12118 @node Security rules of thumb
12119 @subsection Security Rules of Thumb
12120
12121 This section briefly summarizes rules of thumb for avoiding security
12122 pitfalls.
12123
12124 @itemize @bullet
12125
12126 @item
12127 Protect archives at least as much as you protect any of the files
12128 being archived.
12129
12130 @item
12131 Extract from an untrusted archive only into an otherwise-empty
12132 directory. This directory and its parent should be accessible only to
12133 trusted users. For example:
12134
12135 @example
12136 @group
12137 $ @kbd{chmod go-rwx .}
12138 $ @kbd{mkdir -m go-rwx dir}
12139 $ @kbd{cd dir}
12140 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
12141 @end group
12142 @end example
12143
12144 As a corollary, do not do an incremental restore from an untrusted archive.
12145
12146 @item
12147 Do not let untrusted users access files extracted from untrusted
12148 archives without checking first for problems such as setuid programs.
12149
12150 @item
12151 Do not let untrusted users modify directories that are ancestors of
12152 top-level arguments of @command{tar}. For example, while you are
12153 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
12154 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
12155
12156 @item
12157 Pay attention to the diagnostics and exit status of @command{tar}.
12158
12159 @item
12160 When archiving live file systems, monitor running instances of
12161 @command{tar} to detect denial-of-service attacks.
12162
12163 @item
12164 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
12165 @option{--dereference} (@option{-h}), @option{--overwrite},
12166 @option{--recursive-unlink}, and @option{--remove-files} unless you
12167 understand their security implications.
12168
12169 @end itemize
12170
12171 @node Changes
12172 @appendix Changes
12173
12174 This appendix lists some important user-visible changes between
12175 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
12176 version of this document is available at
12177 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
12178 @GNUTAR{} documentation page}.
12179
12180 @table @asis
12181 @item Use of globbing patterns when listing and extracting.
12182
12183 Previous versions of GNU tar assumed shell-style globbing when
12184 extracting from or listing an archive. For example:
12185
12186 @smallexample
12187 $ @kbd{tar xf foo.tar '*.c'}
12188 @end smallexample
12189
12190 would extract all files whose names end in @samp{.c}. This behavior
12191 was not documented and was incompatible with traditional tar
12192 implementations. Therefore, starting from version 1.15.91, GNU tar
12193 no longer uses globbing by default. For example, the above invocation
12194 is now interpreted as a request to extract from the archive the file
12195 named @file{*.c}.
12196
12197 To facilitate transition to the new behavior for those users who got
12198 used to the previous incorrect one, @command{tar} will print a warning
12199 if it finds out that a requested member was not found in the archive
12200 and its name looks like a globbing pattern. For example:
12201
12202 @smallexample
12203 $ @kbd{tar xf foo.tar '*.c'}
12204 tar: Pattern matching characters used in file names. Please,
12205 tar: use --wildcards to enable pattern matching, or --no-wildcards to
12206 tar: suppress this warning.
12207 tar: *.c: Not found in archive
12208 tar: Error exit delayed from previous errors
12209 @end smallexample
12210
12211 To treat member names as globbing patterns, use the @option{--wildcards} option.
12212 If you want to tar to mimic the behavior of versions prior to 1.15.91,
12213 add this option to your @env{TAR_OPTIONS} variable.
12214
12215 @xref{wildcards}, for the detailed discussion of the use of globbing
12216 patterns by @GNUTAR{}.
12217
12218 @item Use of short option @option{-o}.
12219
12220 Earlier versions of @GNUTAR{} understood @option{-o} command line
12221 option as a synonym for @option{--old-archive}.
12222
12223 @GNUTAR{} starting from version 1.13.90 understands this option as
12224 a synonym for @option{--no-same-owner}. This is compatible with
12225 UNIX98 @command{tar} implementations.
12226
12227 However, to facilitate transition, @option{-o} option retains its
12228 old semantics when it is used with one of archive-creation commands.
12229 Users are encouraged to use @option{--format=oldgnu} instead.
12230
12231 It is especially important, since versions of @acronym{GNU} Automake
12232 up to and including 1.8.4 invoke tar with this option to produce
12233 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
12234 of this issue and its implications.
12235
12236 @xref{Options, tar-formats, Changing Automake's Behavior,
12237 automake, GNU Automake}, for a description on how to use various
12238 archive formats with @command{automake}.
12239
12240 Future versions of @GNUTAR{} will understand @option{-o} only as a
12241 synonym for @option{--no-same-owner}.
12242
12243 @item Use of short option @option{-l}
12244
12245 Earlier versions of @GNUTAR{} understood @option{-l} option as a
12246 synonym for @option{--one-file-system}. Since such usage contradicted
12247 to UNIX98 specification and harmed compatibility with other
12248 implementations, it was declared deprecated in version 1.14. However,
12249 to facilitate transition to its new semantics, it was supported by
12250 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
12251 variant of @option{--check-links} was introduced in version 1.15.91.
12252
12253 @item Use of options @option{--portability} and @option{--old-archive}
12254
12255 These options are deprecated. Please use @option{--format=v7} instead.
12256
12257 @item Use of option @option{--posix}
12258
12259 This option is deprecated. Please use @option{--format=posix} instead.
12260 @end table
12261
12262 @node Configuring Help Summary
12263 @appendix Configuring Help Summary
12264
12265 Running @kbd{tar --help} displays the short @command{tar} option
12266 summary (@pxref{help}). This summary is organized by @dfn{groups} of
12267 semantically close options. The options within each group are printed
12268 in the following order: a short option, eventually followed by a list
12269 of corresponding long option names, followed by a short description of
12270 the option. For example, here is an excerpt from the actual @kbd{tar
12271 --help} output:
12272
12273 @verbatim
12274 Main operation mode:
12275
12276 -A, --catenate, --concatenate append tar files to an archive
12277 -c, --create create a new archive
12278 -d, --diff, --compare find differences between archive and
12279 file system
12280 --delete delete from the archive
12281 @end verbatim
12282
12283 @vrindex ARGP_HELP_FMT, environment variable
12284 The exact visual representation of the help output is configurable via
12285 @env{ARGP_HELP_FMT} environment variable. The value of this variable
12286 is a comma-separated list of @dfn{format variable} assignments. There
12287 are two kinds of format variables. An @dfn{offset variable} keeps the
12288 offset of some part of help output text from the leftmost column on
12289 the screen. A @dfn{boolean} variable is a flag that toggles some
12290 output feature on or off. Depending on the type of the corresponding
12291 variable, there are two kinds of assignments:
12292
12293 @table @asis
12294 @item Offset assignment
12295
12296 The assignment to an offset variable has the following syntax:
12297
12298 @smallexample
12299 @var{variable}=@var{value}
12300 @end smallexample
12301
12302 @noindent
12303 where @var{variable} is the variable name, and @var{value} is a
12304 numeric value to be assigned to the variable.
12305
12306 @item Boolean assignment
12307
12308 To assign @code{true} value to a variable, simply put this variable name. To
12309 assign @code{false} value, prefix the variable name with @samp{no-}. For
12310 example:
12311
12312 @smallexample
12313 @group
12314 # Assign @code{true} value:
12315 dup-args
12316 # Assign @code{false} value:
12317 no-dup-args
12318 @end group
12319 @end smallexample
12320 @end table
12321
12322 Following variables are declared:
12323
12324 @deftypevr {Help Output} boolean dup-args
12325 If true, arguments for an option are shown with both short and long
12326 options, even when a given option has both forms, for example:
12327
12328 @smallexample
12329 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
12330 @end smallexample
12331
12332 If false, then if an option has both short and long forms, the
12333 argument is only shown with the long one, for example:
12334
12335 @smallexample
12336 -f, --file=ARCHIVE use archive file or device ARCHIVE
12337 @end smallexample
12338
12339 @noindent
12340 and a message indicating that the argument is applicable to both
12341 forms is printed below the options. This message can be disabled
12342 using @code{dup-args-note} (see below).
12343
12344 The default is false.
12345 @end deftypevr
12346
12347 @deftypevr {Help Output} boolean dup-args-note
12348 If this variable is true, which is the default, the following notice
12349 is displayed at the end of the help output:
12350
12351 @quotation
12352 Mandatory or optional arguments to long options are also mandatory or
12353 optional for any corresponding short options.
12354 @end quotation
12355
12356 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
12357 variables @code{dup-args} or @code{dup-args-note} should be set.
12358 @end deftypevr
12359
12360 @deftypevr {Help Output} offset short-opt-col
12361 Column in which short options start. Default is 2.
12362
12363 @smallexample
12364 @group
12365 $ @kbd{tar --help|grep ARCHIVE}
12366 -f, --file=ARCHIVE use archive file or device ARCHIVE
12367 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
12368 -f, --file=ARCHIVE use archive file or device ARCHIVE
12369 @end group
12370 @end smallexample
12371 @end deftypevr
12372
12373 @deftypevr {Help Output} offset long-opt-col
12374 Column in which long options start. Default is 6. For example:
12375
12376 @smallexample
12377 @group
12378 $ @kbd{tar --help|grep ARCHIVE}
12379 -f, --file=ARCHIVE use archive file or device ARCHIVE
12380 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
12381 -f, --file=ARCHIVE use archive file or device ARCHIVE
12382 @end group
12383 @end smallexample
12384 @end deftypevr
12385
12386 @deftypevr {Help Output} offset doc-opt-col
12387 Column in which @dfn{doc options} start. A doc option isn't actually
12388 an option, but rather an arbitrary piece of documentation that is
12389 displayed in much the same manner as the options. For example, in
12390 the description of @option{--format} option:
12391
12392 @smallexample
12393 @group
12394 -H, --format=FORMAT create archive of the given format.
12395
12396 FORMAT is one of the following:
12397
12398 gnu GNU tar 1.13.x format
12399 oldgnu GNU format as per tar <= 1.12
12400 pax POSIX 1003.1-2001 (pax) format
12401 posix same as pax
12402 ustar POSIX 1003.1-1988 (ustar) format
12403 v7 old V7 tar format
12404 @end group
12405 @end smallexample
12406
12407 @noindent
12408 the format names are doc options. Thus, if you set
12409 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
12410 will look as follows:
12411
12412 @smallexample
12413 @group
12414 -H, --format=FORMAT create archive of the given format.
12415
12416 FORMAT is one of the following:
12417
12418 gnu GNU tar 1.13.x format
12419 oldgnu GNU format as per tar <= 1.12
12420 pax POSIX 1003.1-2001 (pax) format
12421 posix same as pax
12422 ustar POSIX 1003.1-1988 (ustar) format
12423 v7 old V7 tar format
12424 @end group
12425 @end smallexample
12426 @end deftypevr
12427
12428 @deftypevr {Help Output} offset opt-doc-col
12429 Column in which option description starts. Default is 29.
12430
12431 @smallexample
12432 @group
12433 $ @kbd{tar --help|grep ARCHIVE}
12434 -f, --file=ARCHIVE use archive file or device ARCHIVE
12435 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
12436 -f, --file=ARCHIVE use archive file or device ARCHIVE
12437 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
12438 -f, --file=ARCHIVE
12439 use archive file or device ARCHIVE
12440 @end group
12441 @end smallexample
12442
12443 @noindent
12444 Notice, that the description starts on a separate line if
12445 @code{opt-doc-col} value is too small.
12446 @end deftypevr
12447
12448 @deftypevr {Help Output} offset header-col
12449 Column in which @dfn{group headers} are printed. A group header is a
12450 descriptive text preceding an option group. For example, in the
12451 following text:
12452
12453 @verbatim
12454 Main operation mode:
12455
12456 -A, --catenate, --concatenate append tar files to
12457 an archive
12458 -c, --create create a new archive
12459 @end verbatim
12460 @noindent
12461 @samp{Main operation mode:} is the group header.
12462
12463 The default value is 1.
12464 @end deftypevr
12465
12466 @deftypevr {Help Output} offset usage-indent
12467 Indentation of wrapped usage lines. Affects @option{--usage}
12468 output. Default is 12.
12469 @end deftypevr
12470
12471 @deftypevr {Help Output} offset rmargin
12472 Right margin of the text output. Used for wrapping.
12473 @end deftypevr
12474
12475 @node Fixing Snapshot Files
12476 @appendix Fixing Snapshot Files
12477 @include tar-snapshot-edit.texi
12478
12479 @node Tar Internals
12480 @appendix Tar Internals
12481 @include intern.texi
12482
12483 @node Genfile
12484 @appendix Genfile
12485 @include genfile.texi
12486
12487 @node Free Software Needs Free Documentation
12488 @appendix Free Software Needs Free Documentation
12489 @include freemanuals.texi
12490
12491 @node GNU Free Documentation License
12492 @appendix GNU Free Documentation License
12493
12494 @include fdl.texi
12495
12496 @node Index of Command Line Options
12497 @appendix Index of Command Line Options
12498
12499 This appendix contains an index of all @GNUTAR{} long command line
12500 options. The options are listed without the preceding double-dash.
12501 For a cross-reference of short command line options, see
12502 @ref{Short Option Summary}.
12503
12504 @printindex op
12505
12506 @node Index
12507 @appendix Index
12508
12509 @printindex cp
12510
12511 @summarycontents
12512 @contents
12513 @bye
12514
12515 @c Local variables:
12516 @c texinfo-column-for-description: 32
12517 @c End:
This page took 0.600312 seconds and 5 git commands to generate.