1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
5 @settitle GNU tar @value{VERSION}
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
18 @c 2.2. Run `make master-menu' (see comment before the master menu).
20 @include rendition.texi
25 @c Put everything in one index (arbitrarily chosen to be the concept index).
33 This manual is for @acronym{GNU} @command{tar} (version
34 @value{VERSION}, @value{UPDATED}), which creates and extracts files
37 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
38 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
41 Permission is granted to copy, distribute and/or modify this document
42 under the terms of the GNU Free Documentation License, Version 1.1 or
43 any later version published by the Free Software Foundation; with no
44 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
45 and with the Back-Cover Texts as in (a) below. A copy of the license
46 is included in the section entitled "GNU Free Documentation License".
48 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
49 this GNU Manual. Buying copies from GNU Press supports the FSF in
50 developing GNU and promoting software freedom.''
54 @dircategory Archiving
56 * Tar: (tar). Making tape (or disk) archives.
59 @dircategory Individual utilities
61 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
64 @shorttitlepage @acronym{GNU} @command{tar}
67 @title @acronym{GNU} tar: an archiver tool
68 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
69 @author John Gilmore, Jay Fenlason et al.
72 @vskip 0pt plus 1filll
78 @top @acronym{GNU} tar: an archiver tool
83 @cindex archiving files
85 The first part of this master menu lists the major nodes in this Info
86 document. The rest of the menu lists all the lower level nodes.
89 @c The master menu goes here.
91 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
92 @c loaded and run texinfo-master-menu.
93 @c To update it from the command line, run
104 * Date input formats::
111 * Configuring Help Summary::
114 * Free Software Needs Free Documentation::
115 * Copying This Manual::
116 * Index of Command Line Options::
120 --- The Detailed Node Listing ---
124 * Book Contents:: What this Book Contains
125 * Definitions:: Some Definitions
126 * What tar Does:: What @command{tar} Does
127 * Naming tar Archives:: How @command{tar} Archives are Named
128 * Authors:: @GNUTAR{} Authors
129 * Reports:: Reporting bugs or suggestions
131 Tutorial Introduction to @command{tar}
134 * stylistic conventions::
135 * basic tar options:: Basic @command{tar} Operations and Options
136 * frequent operations::
137 * Two Frequent Options::
138 * create:: How to Create Archives
139 * list:: How to List Archives
140 * extract:: How to Extract Members from an Archive
143 Two Frequently Used Options
149 How to Create Archives
151 * prepare for examples::
152 * Creating the archive::
161 How to Extract Members from an Archive
163 * extracting archives::
166 * extracting untrusted archives::
172 * using tar options::
180 The Three Option Styles
182 * Long Options:: Long Option Style
183 * Short Options:: Short Option Style
184 * Old Options:: Old Option Style
185 * Mixing:: Mixing Option Styles
187 All @command{tar} Options
189 * Operation Summary::
191 * Short Option Summary::
203 Advanced @GNUTAR{} Operations
212 How to Add Files to Existing Archives: @option{--append}
214 * appending files:: Appending Files to an Archive
221 Options Used by @option{--create}
223 * override:: Overriding File Metadata.
224 * Ignore Failed Read::
226 Options Used by @option{--extract}
228 * Reading:: Options to Help Read Archives
229 * Writing:: Changing How @command{tar} Writes Files
230 * Scarce:: Coping with Scarce Resources
232 Options to Help Read Archives
234 * read full records::
237 Changing How @command{tar} Writes Files
239 * Dealing with Old Files::
240 * Overwrite Old Files::
245 * Data Modification Times::
246 * Setting Access Permissions::
247 * Directory Modification Times and Permissions::
248 * Writing to Standard Output::
249 * Writing to an External Program::
252 Coping with Scarce Resources
257 Performing Backups and Restoring Files
259 * Full Dumps:: Using @command{tar} to Perform Full Dumps
260 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
261 * Backup Levels:: Levels of Backups
262 * Backup Parameters:: Setting Parameters for Backups and Restoration
263 * Scripted Backups:: Using the Backup Scripts
264 * Scripted Restoration:: Using the Restore Script
266 Setting Parameters for Backups and Restoration
268 * General-Purpose Variables::
269 * Magnetic Tape Control::
271 * backup-specs example:: An Example Text of @file{Backup-specs}
273 Choosing Files and Names for @command{tar}
275 * file:: Choosing the Archive's Name
276 * Selecting Archive Members::
277 * files:: Reading Names from a File
278 * exclude:: Excluding Some Files
279 * wildcards:: Wildcards Patterns and Matching
280 * quoting styles:: Ways of Quoting Special Characters in Names
281 * transform:: Modifying File and Member Names
282 * after:: Operating Only on New Files
283 * recurse:: Descending into Directories
284 * one:: Crossing File System Boundaries
286 Reading Names from a File
292 * problems with exclude::
294 Wildcards Patterns and Matching
296 * controlling pattern-matching::
298 Crossing File System Boundaries
300 * directory:: Changing Directory
301 * absolute:: Absolute File Names
305 * General date syntax:: Common rules.
306 * Calendar date items:: 19 Dec 1994.
307 * Time of day items:: 9:20pm.
308 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
309 * Day of week items:: Monday and others.
310 * Relative items in date strings:: next tuesday, 2 years ago.
311 * Pure numbers in date strings:: 19931219, 1440.
312 * Seconds since the Epoch:: @@1078100502.
313 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
314 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
316 Controlling the Archive Format
318 * Portability:: Making @command{tar} Archives More Portable
319 * Compression:: Using Less Space through Compression
320 * Attributes:: Handling File Attributes
321 * cpio:: Comparison of @command{tar} and @command{cpio}
323 Making @command{tar} Archives More Portable
325 * Portable Names:: Portable Names
326 * dereference:: Symbolic Links
327 * old:: Old V7 Archives
328 * ustar:: Ustar Archives
329 * gnu:: GNU and old GNU format archives.
330 * posix:: @acronym{POSIX} archives
331 * Checksumming:: Checksumming Problems
332 * Large or Negative Values:: Large files, negative time stamps, etc.
333 * Other Tars:: How to Extract GNU-Specific Data Using
334 Other @command{tar} Implementations
336 @GNUTAR{} and @acronym{POSIX} @command{tar}
338 * PAX keywords:: Controlling Extended Header Keywords.
340 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
342 * Split Recovery:: Members Split Between Volumes
343 * Sparse Recovery:: Sparse Members
345 Using Less Space through Compression
347 * gzip:: Creating and Reading Compressed Archives
348 * sparse:: Archiving Sparse Files
350 Tapes and Other Archive Media
352 * Device:: Device selection and switching
353 * Remote Tape Server::
354 * Common Problems and Solutions::
355 * Blocking:: Blocking
356 * Many:: Many archives on one tape
357 * Using Multiple Tapes:: Using Multiple Tapes
358 * label:: Including a Label in the Archive
364 * Format Variations:: Format Variations
365 * Blocking Factor:: The Blocking Factor of an Archive
367 Many Archives on One Tape
369 * Tape Positioning:: Tape Positions and Tape Marks
370 * mt:: The @command{mt} Utility
374 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
375 * Tape Files:: Tape Files
376 * Tarcat:: Concatenate Volumes into a Single Archive
381 * Standard:: Basic Tar Format
382 * Extensions:: @acronym{GNU} Extensions to the Archive Format
383 * Sparse Formats:: Storing Sparse Files
390 * PAX 0:: PAX Format, Versions 0.0 and 0.1
391 * PAX 1:: PAX Format, Version 1.0
395 * Generate Mode:: File Generation Mode.
396 * Status Mode:: File Status Mode.
397 * Exec Mode:: Synchronous Execution mode.
401 * GNU Free Documentation License:: License for copying this manual
407 @chapter Introduction
410 and manipulates @dfn{archives} which are actually collections of
411 many other files; the program provides users with an organized and
412 systematic method for controlling a large amount of data.
413 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
414 archives need not (and these days, typically do not) reside on tapes.
417 * Book Contents:: What this Book Contains
418 * Definitions:: Some Definitions
419 * What tar Does:: What @command{tar} Does
420 * Naming tar Archives:: How @command{tar} Archives are Named
421 * Authors:: @GNUTAR{} Authors
422 * Reports:: Reporting bugs or suggestions
426 @section What this Book Contains
428 The first part of this chapter introduces you to various terms that will
429 recur throughout the book. It also tells you who has worked on @GNUTAR{}
430 and its documentation, and where you should send bug reports
433 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
434 gentle introduction for people who are new to using @command{tar}. It is
435 meant to be self contained, not requiring any reading from subsequent
436 chapters to make sense. It moves from topic to topic in a logical,
437 progressive order, building on information already explained.
439 Although the tutorial is paced and structured to allow beginners to
440 learn how to use @command{tar}, it is not intended solely for beginners.
441 The tutorial explains how to use the three most frequently used
442 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
443 two frequently used options (@samp{file} and @samp{verbose}). The other
444 chapters do not refer to the tutorial frequently; however, if a section
445 discusses something which is a complex variant of a basic concept, there
446 may be a cross reference to that basic concept. (The entire book,
447 including the tutorial, assumes that the reader understands some basic
448 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
450 The third chapter presents the remaining five operations, and
451 information about using @command{tar} options and option syntax.
453 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
454 than the reality. should think about whether this makes sense to say
455 here, or not.} The other chapters are meant to be used as a
456 reference. Each chapter presents everything that needs to be said
457 about a specific topic.
459 One of the chapters (@pxref{Date input formats}) exists in its
460 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
461 In addition, one section of this manual (@pxref{Standard}) contains a
462 big quote which is taken directly from @command{tar} sources.
464 In general, we give both long and short (abbreviated) option names
465 at least once in each section where the relevant option is covered, so
466 that novice readers will become familiar with both styles. (A few
467 options have no short versions, and the relevant sections will
471 @section Some Definitions
475 The @command{tar} program is used to create and manipulate @command{tar}
476 archives. An @dfn{archive} is a single file which contains the contents
477 of many files, while still identifying the names of the files, their
478 owner(s), and so forth. (In addition, archives record access
479 permissions, user and group, size in bytes, and data modification time.
480 Some archives also record the file names in each archived directory, as
481 well as other file and directory information.) You can use @command{tar}
482 to @dfn{create} a new archive in a specified directory.
485 @cindex archive member
488 The files inside an archive are called @dfn{members}. Within this
489 manual, we use the term @dfn{file} to refer only to files accessible in
490 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
491 @dfn{member} to refer only to the members of an archive. Similarly, a
492 @dfn{file name} is the name of a file, as it resides in the file system,
493 and a @dfn{member name} is the name of an archive member within the
498 The term @dfn{extraction} refers to the process of copying an archive
499 member (or multiple members) into a file in the file system. Extracting
500 all the members of an archive is often called @dfn{extracting the
501 archive}. The term @dfn{unpack} can also be used to refer to the
502 extraction of many or all the members of an archive. Extracting an
503 archive does not destroy the archive's structure, just as creating an
504 archive does not destroy the copies of the files that exist outside of
505 the archive. You may also @dfn{list} the members in a given archive
506 (this is often thought of as ``printing'' them to the standard output,
507 or the command line), or @dfn{append} members to a pre-existing archive.
508 All of these operations can be performed using @command{tar}.
511 @section What @command{tar} Does
514 The @command{tar} program provides the ability to create @command{tar}
515 archives, as well as various other kinds of manipulation. For example,
516 you can use @command{tar} on previously created archives to extract files,
517 to store additional files, or to update or list files which were already
520 Initially, @command{tar} archives were used to store files conveniently on
521 magnetic tape. The name @command{tar} comes from this use; it stands for
522 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
523 direct its output to available devices, files, or other programs (using
524 pipes). @command{tar} may even access remote devices or files (as archives).
526 You can use @command{tar} archives in many ways. We want to stress a few
527 of them: storage, backup, and transportation.
529 @FIXME{the following table entries need a bit of work.}
532 Often, @command{tar} archives are used to store related files for
533 convenient file transfer over a network. For example, the
534 @acronym{GNU} Project distributes its software bundled into
535 @command{tar} archives, so that all the files relating to a particular
536 program (or set of related programs) can be transferred as a single
539 A magnetic tape can store several files in sequence. However, the tape
540 has no names for these files; it only knows their relative position on
541 the tape. One way to store several files on one tape and retain their
542 names is by creating a @command{tar} archive. Even when the basic transfer
543 mechanism can keep track of names, as FTP can, the nuisance of handling
544 multiple files, directories, and multiple links makes @command{tar}
547 Archive files are also used for long-term storage. You can think of
548 this as transportation from the present into the future. (It is a
549 science-fiction idiom that you can move through time as well as in
550 space; the idea here is that @command{tar} can be used to move archives in
551 all dimensions, even time!)
554 Because the archive created by @command{tar} is capable of preserving
555 file information and directory structure, @command{tar} is commonly
556 used for performing full and incremental backups of disks. A backup
557 puts a collection of files (possibly pertaining to many users and
558 projects) together on a disk or a tape. This guards against
559 accidental destruction of the information in those files.
560 @GNUTAR{} has special features that allow it to be
561 used to make incremental and full dumps of all the files in a
565 You can create an archive on one system, transfer it to another system,
566 and extract the contents there. This allows you to transport a group of
567 files from one system to another.
570 @node Naming tar Archives
571 @section How @command{tar} Archives are Named
573 Conventionally, @command{tar} archives are given names ending with
574 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
575 but this manual follows that convention in order to accustom readers to
576 it and to make examples more clear.
581 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
582 archive members as ``files'' or ``entries''. For people familiar with
583 the operation of @command{tar}, this causes no difficulty. However, in
584 this manual, we consistently refer to ``archives'' and ``archive
585 members'' to make learning to use @command{tar} easier for novice users.
588 @section @GNUTAR{} Authors
590 @GNUTAR{} was originally written by John Gilmore,
591 and modified by many people. The @acronym{GNU} enhancements were
592 written by Jay Fenlason, then Joy Kendall, and the whole package has
593 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
594 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
595 numerous and kind users.
597 We wish to stress that @command{tar} is a collective work, and owes much to
598 all those people who reported problems, offered solutions and other
599 insights, or shared their thoughts and suggestions. An impressive, yet
600 partial list of those contributors can be found in the @file{THANKS}
601 file from the @GNUTAR{} distribution.
603 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
604 sure i want to spell out the history in this detail, at least not for
605 the printed book. i'm just not sure it needs to be said this way.
606 i'll think about it.}
608 @FIXME{History is more important, and surely more interesting, than
609 actual names. Quoting names without history would be meaningless. FP}
611 Jay Fenlason put together a draft of a @GNUTAR{}
612 manual, borrowing notes from the original man page from John Gilmore.
613 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
614 Gorin worked on a tutorial and manual for @GNUTAR{}.
615 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
616 taking information from all these sources and merging them. Melissa
617 Weisshaus finally edited and redesigned the book to create version
618 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
619 by the current maintainer, Sergey Poznyakoff.
621 For version 1.12, Daniel Hagerty contributed a great deal of technical
622 consulting. In particular, he is the primary author of @ref{Backups}.
624 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
625 (see @url{http://savannah.gnu.org/projects/tar}), and
626 active development and maintenance work has started
627 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
628 Poznyakoff and Jeff Bailey.
630 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
633 @section Reporting bugs or suggestions
636 @cindex reporting bugs
637 If you find problems or have suggestions about this program or manual,
638 please report them to @file{bug-tar@@gnu.org}.
640 When reporting a bug, please be sure to include as much detail as
641 possible, in order to reproduce it. @FIXME{Be more specific, I'd
642 like to make this node as detailed as 'Bug reporting' node in Emacs
646 @chapter Tutorial Introduction to @command{tar}
648 This chapter guides you through some basic examples of three @command{tar}
649 operations: @option{--create}, @option{--list}, and @option{--extract}. If
650 you already know how to use some other version of @command{tar}, then you
651 may not need to read this chapter. This chapter omits most complicated
652 details about how @command{tar} works.
656 * stylistic conventions::
657 * basic tar options:: Basic @command{tar} Operations and Options
658 * frequent operations::
659 * Two Frequent Options::
660 * create:: How to Create Archives
661 * list:: How to List Archives
662 * extract:: How to Extract Members from an Archive
667 @section Assumptions this Tutorial Makes
669 This chapter is paced to allow beginners to learn about @command{tar}
670 slowly. At the same time, we will try to cover all the basic aspects of
671 these three operations. In order to accomplish both of these tasks, we
672 have made certain assumptions about your knowledge before reading this
673 manual, and the hardware you will be using:
677 Before you start to work through this tutorial, you should understand
678 what the terms ``archive'' and ``archive member'' mean
679 (@pxref{Definitions}). In addition, you should understand something
680 about how Unix-type operating systems work, and you should know how to
681 use some basic utilities. For example, you should know how to create,
682 list, copy, rename, edit, and delete files and directories; how to
683 change between directories; and how to figure out where you are in the
684 file system. You should have some basic understanding of directory
685 structure and how files are named according to which directory they are
686 in. You should understand concepts such as standard output and standard
687 input, what various definitions of the term ``argument'' mean, and the
688 differences between relative and absolute path names. @FIXME{and what
692 This manual assumes that you are working from your own home directory
693 (unless we state otherwise). In this tutorial, you will create a
694 directory to practice @command{tar} commands in. When we show path names,
695 we will assume that those paths are relative to your home directory.
696 For example, my home directory path is @file{/home/fsf/melissa}. All of
697 my examples are in a subdirectory of the directory named by that path
698 name; the subdirectory is called @file{practice}.
701 In general, we show examples of archives which exist on (or can be
702 written to, or worked with from) a directory on a hard disk. In most
703 cases, you could write those archives to, or work with them on any other
704 device, such as a tape drive. However, some of the later examples in
705 the tutorial and next chapter will not work on tape drives.
706 Additionally, working with tapes is much more complicated than working
707 with hard disks. For these reasons, the tutorial does not cover working
708 with tape drives. @xref{Media}, for complete information on using
709 @command{tar} archives with tape drives.
711 @FIXME{this is a cop out. need to add some simple tape drive info.}
714 @node stylistic conventions
715 @section Stylistic Conventions
717 In the examples, @samp{$} represents a typical shell prompt. It
718 precedes lines you should type; to make this more clear, those lines are
719 shown in @kbd{this font}, as opposed to lines which represent the
720 computer's response; those lines are shown in @code{this font}, or
721 sometimes @samp{like this}.
723 @c When we have lines which are too long to be
724 @c displayed in any other way, we will show them like this:
726 @node basic tar options
727 @section Basic @command{tar} Operations and Options
729 @command{tar} can take a wide variety of arguments which specify and define
730 the actions it will have on the particular set of files or the archive.
731 The main types of arguments to @command{tar} fall into one of two classes:
732 operations, and options.
734 Some arguments fall into a class called @dfn{operations}; exactly one of
735 these is both allowed and required for any instance of using @command{tar};
736 you may @emph{not} specify more than one. People sometimes speak of
737 @dfn{operating modes}. You are in a particular operating mode when you
738 have specified the operation which specifies it; there are eight
739 operations in total, and thus there are eight operating modes.
741 The other arguments fall into the class known as @dfn{options}. You are
742 not required to specify any options, and you are allowed to specify more
743 than one at a time (depending on the way you are using @command{tar} at
744 that time). Some options are used so frequently, and are so useful for
745 helping you type commands more carefully that they are effectively
746 ``required''. We will discuss them in this chapter.
748 You can write most of the @command{tar} operations and options in any
749 of three forms: long (mnemonic) form, short form, and old style. Some
750 of the operations and options have no short or ``old'' forms; however,
751 the operations and options which we will cover in this tutorial have
752 corresponding abbreviations. @FIXME{make sure this is still the case,
753 at the end}We will indicate those abbreviations appropriately to get
754 you used to seeing them. (Note that the ``old style'' option forms
755 exist in @GNUTAR{} for compatibility with Unix
756 @command{tar}. In this book we present a full discussion of this way
757 of writing options and operations (@pxref{Old Options}), and we discuss
758 the other two styles of writing options (@xref{Long Options}, and
759 @pxref{Short Options}).
761 In the examples and in the text of this tutorial, we usually use the
762 long forms of operations and options; but the ``short'' forms produce
763 the same result and can make typing long @command{tar} commands easier.
764 For example, instead of typing
767 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
773 @kbd{tar -c -v -f afiles.tar apple angst aspic}
779 @kbd{tar -cvf afiles.tar apple angst aspic}
783 For more information on option syntax, see @ref{Advanced tar}. In
784 discussions in the text, when we name an option by its long form, we
785 also give the corresponding short option in parentheses.
787 The term, ``option'', can be confusing at times, since ``operations''
788 are often lumped in with the actual, @emph{optional} ``options'' in certain
789 general class statements. For example, we just talked about ``short and
790 long forms of options and operations''. However, experienced @command{tar}
791 users often refer to these by shorthand terms such as, ``short and long
792 options''. This term assumes that the ``operations'' are included, also.
793 Context will help you determine which definition of ``options'' to use.
795 Similarly, the term ``command'' can be confusing, as it is often used in
796 two different ways. People sometimes refer to @command{tar} ``commands''.
797 A @command{tar} @dfn{command} is the entire command line of user input
798 which tells @command{tar} what to do --- including the operation, options,
799 and any arguments (file names, pipes, other commands, etc.). However,
800 you will also sometimes hear the term ``the @command{tar} command''. When
801 the word ``command'' is used specifically like this, a person is usually
802 referring to the @command{tar} @emph{operation}, not the whole line.
803 Again, use context to figure out which of the meanings the speaker
806 @node frequent operations
807 @section The Three Most Frequently Used Operations
809 Here are the three most frequently used operations (both short and long
810 forms), as well as a brief description of their meanings. The rest of
811 this chapter will cover how to use these operations in detail. We will
812 present the rest of the operations in the next chapter.
817 Create a new @command{tar} archive.
820 List the contents of an archive.
823 Extract one or more members from an archive.
826 @node Two Frequent Options
827 @section Two Frequently Used Options
829 To understand how to run @command{tar} in the three operating modes listed
830 previously, you also need to understand how to use two of the options to
831 @command{tar}: @option{--file} (which takes an archive file as an argument)
832 and @option{--verbose}. (You are usually not @emph{required} to specify
833 either of these options when you run @command{tar}, but they can be very
834 useful in making things more clear and helping you avoid errors.)
843 @unnumberedsubsec The @option{--file} Option
846 @xopindex{file, tutorial}
847 @item --file=@var{archive-name}
848 @itemx -f @var{archive-name}
849 Specify the name of an archive file.
852 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
853 use @command{tar}; this option determines the name of the archive file
854 that @command{tar} will work on.
857 If you don't specify this argument, then @command{tar} will examine
858 the environment variable @env{TAPE}. If it is set, its value will be
859 used as the archive name. Otherwise, @command{tar} will use the
860 default archive, determined at the compile time. Usually it is
861 standard output or some physical tape drive attached to your machine
862 (you can verify what the default is by running @kbd{tar
863 --show-defaults}, @pxref{defaults}). If there is no tape drive
864 attached, or the default is not meaningful, then @command{tar} will
865 print an error message. The error message might look roughly like one
869 tar: can't open /dev/rmt8 : No such device or address
870 tar: can't open /dev/rsmt0 : I/O error
874 To avoid confusion, we recommend that you always specify an archive file
875 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
876 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
879 @node verbose tutorial
880 @unnumberedsubsec The @option{--verbose} Option
883 @xopindex{verbose, introduced}
886 Show the files being worked on as @command{tar} is running.
889 @option{--verbose} (@option{-v}) shows details about the results of running
890 @command{tar}. This can be especially useful when the results might not be
891 obvious. For example, if you want to see the progress of @command{tar} as
892 it writes files into the archive, you can use the @option{--verbose}
893 option. In the beginning, you may find it useful to use
894 @option{--verbose} at all times; when you are more accustomed to
895 @command{tar}, you will likely want to use it at certain times but not at
896 others. We will use @option{--verbose} at times to help make something
897 clear, and we will give many examples both using and not using
898 @option{--verbose} to show the differences.
900 Each instance of @option{--verbose} on the command line increases the
901 verbosity level by one, so if you need more details on the output,
904 When reading archives (@option{--list}, @option{--extract},
905 @option{--diff}), @command{tar} by default prints only the names of
906 the members being extracted. Using @option{--verbose} will show a full,
907 @command{ls} style member listing.
909 In contrast, when writing archives (@option{--create}, @option{--append},
910 @option{--update}), @command{tar} does not print file names by
911 default. So, a single @option{--verbose} option shows the file names
912 being added to the archive, while two @option{--verbose} options
913 enable the full listing.
915 For example, to create an archive in verbose mode:
918 $ @kbd{tar -cvf afiles.tar apple angst aspic}
925 Creating the same archive with the verbosity level 2 could give:
928 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
929 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
930 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
931 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
935 This works equally well using short or long forms of options. Using
936 long forms, you would simply write out the mnemonic form of the option
940 $ @kbd{tar --create --verbose --verbose @dots{}}
944 Note that you must double the hyphens properly each time.
946 Later in the tutorial, we will give examples using @w{@option{--verbose
949 @anchor{verbose member listing}
950 The full output consists of six fields:
953 @item File type and permissions in symbolic form.
954 These are displayed in the same format as the first column of
955 @command{ls -l} output (@pxref{What information is listed,
956 format=verbose, Verbose listing, fileutils, GNU file utilities}).
958 @item Owner name and group separated by a slash character.
959 If these data are not available (for example, when listing a @samp{v7} format
960 archive), numeric ID values are printed instead.
962 @item Size of the file, in bytes.
964 @item File modification date in ISO 8601 format.
966 @item File modification time.
969 If the name contains any special characters (white space, newlines,
970 etc.) these are displayed in an unambiguous form using so called
971 @dfn{quoting style}. For the detailed discussion of available styles
972 and on how to use them, see @ref{quoting styles}.
974 Depending on the file type, the name can be followed by some
975 additional information, described in the following table:
978 @item -> @var{link-name}
979 The file or archive member is a @dfn{symbolic link} and
980 @var{link-name} is the name of file it links to.
982 @item link to @var{link-name}
983 The file or archive member is a @dfn{hard link} and @var{link-name} is
984 the name of file it links to.
987 The archive member is an old GNU format long link. You will normally
991 The archive member is an old GNU format long name. You will normally
994 @item --Volume Header--
995 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
997 @item --Continued at byte @var{n}--
998 Encountered only at the beginning of a multi-volume archive
999 (@pxref{Using Multiple Tapes}). This archive member is a continuation
1000 from the previous volume. The number @var{n} gives the offset where
1001 the original file was split.
1003 @item unknown file type @var{c}
1004 An archive member of unknown type. @var{c} is the type character from
1005 the archive header. If you encounter such a message, it means that
1006 either your archive contains proprietary member types @GNUTAR{} is not
1007 able to handle, or the archive is corrupted.
1012 For example, here is an archive listing containing most of the special
1013 suffixes explained above:
1017 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1018 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1020 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1021 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1022 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1023 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1031 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1037 The @option{--help} option to @command{tar} prints out a very brief list of
1038 all operations and option available for the current version of
1039 @command{tar} available on your system.
1043 @section How to Create Archives
1046 @cindex Creation of the archive
1047 @cindex Archive, creation of
1048 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1049 you use to create a @command{tar} archive. We will explain
1050 @option{--create} first because, in order to learn about the other
1051 operations, you will find it useful to have an archive available to
1054 To make this easier, in this section you will first create a directory
1055 containing three files. Then, we will show you how to create an
1056 @emph{archive} (inside the new directory). Both the directory, and
1057 the archive are specifically for you to practice on. The rest of this
1058 chapter and the next chapter will show many examples using this
1059 directory and the files you will create: some of those files may be
1060 other directories and other archives.
1062 The three files you will archive in this example are called
1063 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1064 @file{collection.tar}.
1066 This section will proceed slowly, detailing how to use @option{--create}
1067 in @code{verbose} mode, and showing examples using both short and long
1068 forms. In the rest of the tutorial, and in the examples in the next
1069 chapter, we will proceed at a slightly quicker pace. This section
1070 moves more slowly to allow beginning users to understand how
1071 @command{tar} works.
1074 * prepare for examples::
1075 * Creating the archive::
1081 @node prepare for examples
1082 @subsection Preparing a Practice Directory for Examples
1084 To follow along with this and future examples, create a new directory
1085 called @file{practice} containing files called @file{blues}, @file{folk}
1086 and @file{jazz}. The files can contain any information you like:
1087 ideally, they should contain information which relates to their names,
1088 and be of different lengths. Our examples assume that @file{practice}
1089 is a subdirectory of your home directory.
1091 Now @command{cd} to the directory named @file{practice}; @file{practice}
1092 is now your @dfn{working directory}. (@emph{Please note}: Although
1093 the full path name of this directory is
1094 @file{/@var{homedir}/practice}, in our examples we will refer to
1095 this directory as @file{practice}; the @var{homedir} is presumed.
1097 In general, you should check that the files to be archived exist where
1098 you think they do (in the working directory) by running @command{ls}.
1099 Because you just created the directory and the files and have changed to
1100 that directory, you probably don't need to do that this time.
1102 It is very important to make sure there isn't already a file in the
1103 working directory with the archive name you intend to use (in this case,
1104 @samp{collection.tar}), or that you don't care about its contents.
1105 Whenever you use @samp{create}, @command{tar} will erase the current
1106 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1107 will not tell you if you are about to overwrite an archive unless you
1108 specify an option which does this (@pxref{backup}, for the
1109 information on how to do so). To add files to an existing archive,
1110 you need to use a different option, such as @option{--append} (@option{-r}); see
1111 @ref{append} for information on how to do this.
1113 @node Creating the archive
1114 @subsection Creating the Archive
1116 @xopindex{create, introduced}
1117 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1118 archive named @file{collection.tar}, use the following command:
1121 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1124 The order of the arguments is not very important, @emph{when using long
1125 option forms}. You could also say:
1128 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1132 However, you can see that this order is harder to understand; this is
1133 why we will list the arguments in the order that makes the commands
1134 easiest to understand (and we encourage you to do the same when you use
1135 @command{tar}, to avoid errors).
1137 Note that the sequence
1138 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1139 If you substituted any other string of characters for
1140 @kbd{collection.tar}, then that string would become the name of the
1141 archive file you create.
1143 The order of the options becomes more important when you begin to use
1144 short forms. With short forms, if you type commands in the wrong order
1145 (even if you type them correctly in all other ways), you may end up with
1146 results you don't expect. For this reason, it is a good idea to get
1147 into the habit of typing options in the order that makes inherent sense.
1148 @xref{short create}, for more information on this.
1150 In this example, you type the command as shown above: @option{--create}
1151 is the operation which creates the new archive
1152 (@file{collection.tar}), and @option{--file} is the option which lets
1153 you give it the name you chose. The files, @file{blues}, @file{folk},
1154 and @file{jazz}, are now members of the archive, @file{collection.tar}
1155 (they are @dfn{file name arguments} to the @option{--create} operation.
1156 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1157 in the archive, they are called @emph{archive members}, not files.
1158 (@pxref{Definitions,members}).
1160 When you create an archive, you @emph{must} specify which files you
1161 want placed in the archive. If you do not specify any archive
1162 members, @GNUTAR{} will complain.
1164 If you now list the contents of the working directory (@command{ls}), you will
1165 find the archive file listed as well as the files you saw previously:
1168 blues folk jazz collection.tar
1172 Creating the archive @samp{collection.tar} did not destroy the copies of
1173 the files in the directory.
1175 Keep in mind that if you don't indicate an operation, @command{tar} will not
1176 run and will prompt you for one. If you don't name any files, @command{tar}
1177 will complain. You must have write access to the working directory,
1178 or else you will not be able to create an archive in that directory.
1180 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1181 an existing archive; it will delete the archive and write a new one.
1182 Use @option{--append} (@option{-r}) instead. @xref{append}.
1184 @node create verbose
1185 @subsection Running @option{--create} with @option{--verbose}
1187 @xopindex{create, using with @option{--verbose}}
1188 @xopindex{verbose, using with @option{--create}}
1189 If you include the @option{--verbose} (@option{-v}) option on the command line,
1190 @command{tar} will list the files it is acting on as it is working. In
1191 verbose mode, the @code{create} example above would appear as:
1194 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1200 This example is just like the example we showed which did not use
1201 @option{--verbose}, except that @command{tar} generated the remaining lines
1203 (note the different font styles).
1209 In the rest of the examples in this chapter, we will frequently use
1210 @code{verbose} mode so we can show actions or @command{tar} responses that
1211 you would otherwise not see, and which are important for you to
1215 @subsection Short Forms with @samp{create}
1217 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1218 basic uses of @command{tar}, and you will use it countless times.
1219 Eventually, you will probably want to use abbreviated (or ``short'')
1220 forms of options. A full discussion of the three different forms that
1221 options can take appears in @ref{Styles}; for now, here is what the
1222 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1223 using short option forms:
1226 $ @kbd{tar -cvf collection.tar blues folk jazz}
1233 As you can see, the system responds the same no matter whether you use
1234 long or short option forms.
1236 @FIXME{i don't like how this is worded:} One difference between using
1237 short and long option forms is that, although the exact placement of
1238 arguments following options is no more specific when using short forms,
1239 it is easier to become confused and make a mistake when using short
1240 forms. For example, suppose you attempted the above example in the
1244 $ @kbd{tar -cfv collection.tar blues folk jazz}
1248 In this case, @command{tar} will make an archive file called @file{v},
1249 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1250 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1251 is thus taken to be the chosen archive file name. @command{tar} will try
1252 to add a file called @file{collection.tar} to the @file{v} archive file;
1253 if the file @file{collection.tar} did not already exist, @command{tar} will
1254 report an error indicating that this file does not exist. If the file
1255 @file{collection.tar} does already exist (e.g., from a previous command
1256 you may have run), then @command{tar} will add this file to the archive.
1257 Because the @option{-v} option did not get registered, @command{tar} will not
1258 run under @samp{verbose} mode, and will not report its progress.
1260 The end result is that you may be quite confused about what happened,
1261 and possibly overwrite a file. To illustrate this further, we will show
1262 you how an example we showed previously would look using short forms.
1267 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1271 is confusing as it is. When shown using short forms, however, it
1272 becomes much more so:
1275 $ @kbd{tar blues -c folk -f collection.tar jazz}
1279 It would be very easy to put the wrong string of characters
1280 immediately following the @option{-f}, but doing that could sacrifice
1283 For this reason, we recommend that you pay very careful attention to
1284 the order of options and placement of file and archive names,
1285 especially when using short option forms. Not having the option name
1286 written out mnemonically can affect how well you remember which option
1287 does what, and therefore where different names have to be placed.
1290 @subsection Archiving Directories
1292 @cindex Archiving Directories
1293 @cindex Directories, Archiving
1294 You can archive a directory by specifying its directory name as a
1295 file name argument to @command{tar}. The files in the directory will be
1296 archived relative to the working directory, and the directory will be
1297 re-created along with its contents when the archive is extracted.
1299 To archive a directory, first move to its superior directory. If you
1300 have followed the previous instructions in this tutorial, you should
1309 This will put you into the directory which contains @file{practice},
1310 i.e., your home directory. Once in the superior directory, you can
1311 specify the subdirectory, @file{practice}, as a file name argument. To
1312 store @file{practice} in the new archive file @file{music.tar}, type:
1315 $ @kbd{tar --create --verbose --file=music.tar practice}
1319 @command{tar} should output:
1326 practice/collection.tar
1329 Note that the archive thus created is not in the subdirectory
1330 @file{practice}, but rather in the current working directory---the
1331 directory from which @command{tar} was invoked. Before trying to archive a
1332 directory from its superior directory, you should make sure you have
1333 write access to the superior directory itself, not only the directory
1334 you are trying archive with @command{tar}. For example, you will probably
1335 not be able to store your home directory in an archive by invoking
1336 @command{tar} from the root directory; @xref{absolute}. (Note
1337 also that @file{collection.tar}, the original archive file, has itself
1338 been archived. @command{tar} will accept any file as a file to be
1339 archived, regardless of its content. When @file{music.tar} is
1340 extracted, the archive file @file{collection.tar} will be re-written
1341 into the file system).
1343 If you give @command{tar} a command such as
1346 $ @kbd{tar --create --file=foo.tar .}
1350 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1351 dumped}. This happens because @command{tar} creates the archive
1352 @file{foo.tar} in the current directory before putting any files into
1353 it. Then, when @command{tar} attempts to add all the files in the
1354 directory @file{.} to the archive, it notices that the file
1355 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1356 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1357 will continue in this case, and create the archive
1358 normally, except for the exclusion of that one file. (@emph{Please
1359 note:} Other implementations of @command{tar} may not be so clever;
1360 they will enter an infinite loop when this happens, so you should not
1361 depend on this behavior unless you are certain you are running
1362 @GNUTAR{}. In general, it is wise to always place the archive outside
1363 of the directory being dumped.
1366 @section How to List Archives
1369 Frequently, you will find yourself wanting to determine exactly what a
1370 particular archive contains. You can use the @option{--list}
1371 (@option{-t}) operation to get the member names as they currently
1372 appear in the archive, as well as various attributes of the files at
1373 the time they were archived. For example, you can examine the archive
1374 @file{collection.tar} that you created in the last section with the
1378 $ @kbd{tar --list --file=collection.tar}
1382 The output of @command{tar} would then be:
1391 The archive @file{bfiles.tar} would list as follows:
1400 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1401 @var{archive-name}}) option just as with @option{--create}
1402 (@option{-c}) to specify the name of the archive.
1404 @xopindex{list, using with @option{--verbose}}
1405 @xopindex{verbose, using with @option{--list}}
1406 If you use the @option{--verbose} (@option{-v}) option with
1407 @option{--list}, then @command{tar} will print out a listing
1408 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1409 forth. This output is described in detail in @ref{verbose member listing}.
1411 If you had used @option{--verbose} (@option{-v}) mode, the example
1412 above would look like:
1415 $ @kbd{tar --list --verbose --file=collection.tar folk}
1416 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1419 @cindex listing member and file names
1420 @anchor{listing member and file names}
1421 It is important to notice that the output of @kbd{tar --list
1422 --verbose} does not necessarily match that produced by @kbd{tar
1423 --create --verbose} while creating the archive. It is because
1424 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1425 prefixes from file names before storing them in the archive
1426 (@xref{absolute}, for more information). In other
1427 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1428 an archive and @dfn{member names} when listing it. Consider this
1433 $ @kbd{tar cfv archive /etc/mail}
1434 tar: Removing leading `/' from member names
1436 /etc/mail/sendmail.cf
1438 $ @kbd{tar tf archive}
1440 etc/mail/sendmail.cf
1445 @opindex show-stored-names
1446 This default behavior can sometimes be inconvenient. You can force
1447 @GNUTAR{} show member names when creating archive by supplying
1448 @option{--show-stored-names} option.
1451 @item --show-stored-names
1452 Print member (as opposed to @emph{file}) names when creating the archive.
1455 @cindex File name arguments, using @option{--list} with
1456 @xopindex{list, using with file name arguments}
1457 You can specify one or more individual member names as arguments when
1458 using @samp{list}. In this case, @command{tar} will only list the
1459 names of members you identify. For example, @w{@kbd{tar --list
1460 --file=afiles.tar apple}} would only print @file{apple}.
1462 Because @command{tar} preserves paths, file names must be specified as
1463 they appear in the archive (i.e., relative to the directory from which
1464 the archive was created). Therefore, it is essential when specifying
1465 member names to @command{tar} that you give the exact member names.
1466 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1467 error message something like @samp{tar: birds: Not found in archive},
1468 because there is no member named @file{birds}, only one named
1469 @file{./birds}. While the names @file{birds} and @file{./birds} name
1470 the same file, @emph{member} names by default are compared verbatim.
1472 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1473 with @file{baboon}, because this exact member name is in the archive file
1474 @file{bfiles.tar}. If you are not sure of the exact file name,
1475 use @dfn{globbing patterns}, for example:
1478 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1482 will list all members whose name contains @samp{b}. @xref{wildcards},
1483 for a detailed discussion of globbing patterns and related
1484 @command{tar} command line options.
1491 @unnumberedsubsec Listing the Contents of a Stored Directory
1493 To get information about the contents of an archived directory,
1494 use the directory name as a file name argument in conjunction with
1495 @option{--list} (@option{-t}). To find out file attributes, include the
1496 @option{--verbose} (@option{-v}) option.
1498 For example, to find out about files in the directory @file{practice}, in
1499 the archive file @file{music.tar}, type:
1502 $ @kbd{tar --list --verbose --file=music.tar practice}
1505 @command{tar} responds:
1508 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1509 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1510 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1511 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1512 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1515 When you use a directory name as a file name argument, @command{tar} acts on
1516 all the files (including sub-directories) in that directory.
1519 @section How to Extract Members from an Archive
1522 @cindex Retrieving files from an archive
1523 @cindex Resurrecting files from an archive
1526 Creating an archive is only half the job---there is no point in storing
1527 files in an archive if you can't retrieve them. The act of retrieving
1528 members from an archive so they can be used and manipulated as
1529 unarchived files again is called @dfn{extraction}. To extract files
1530 from an archive, use the @option{--extract} (@option{--get} or
1531 @option{-x}) operation. As with @option{--create}, specify the name
1532 of the archive with @option{--file} (@option{-f}) option. Extracting
1533 an archive does not modify the archive in any way; you can extract it
1534 multiple times if you want or need to.
1536 Using @option{--extract}, you can extract an entire archive, or specific
1537 files. The files can be directories containing other files, or not. As
1538 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1539 long form of the operation without affecting the performance.
1542 * extracting archives::
1543 * extracting files::
1545 * extracting untrusted archives::
1546 * failing commands::
1549 @node extracting archives
1550 @subsection Extracting an Entire Archive
1552 To extract an entire archive, specify the archive file name only, with
1553 no individual file names as arguments. For example,
1556 $ @kbd{tar -xvf collection.tar}
1563 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1564 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1565 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1568 @node extracting files
1569 @subsection Extracting Specific Files
1571 To extract specific archive members, give their exact member names as
1572 arguments, as printed by @option{--list} (@option{-t}). If you had
1573 mistakenly deleted one of the files you had placed in the archive
1574 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1575 from the archive without changing the archive's structure. Its
1576 contents will be identical to the original file @file{blues} that you
1579 First, make sure you are in the @file{practice} directory, and list the
1580 files in the directory. Now, delete the file, @samp{blues}, and list
1581 the files in the directory again.
1583 You can now extract the member @file{blues} from the archive file
1584 @file{collection.tar} like this:
1587 $ @kbd{tar --extract --file=collection.tar blues}
1591 If you list the files in the directory again, you will see that the file
1592 @file{blues} has been restored, with its original permissions, data
1593 modification times, and owner.@footnote{This is only accidentally
1594 true, but not in general. Whereas modification times are always
1595 restored, in most cases, one has to be root for restoring the owner,
1596 and use a special option for restoring permissions. Here, it just
1597 happens that the restoring user is also the owner of the archived
1598 members, and that the current @code{umask} is compatible with original
1599 permissions.} (These parameters will be identical to those which
1600 the file had when you originally placed it in the archive; any changes
1601 you may have made before deleting the file from the file system,
1602 however, will @emph{not} have been made to the archive member.) The
1603 archive file, @samp{collection.tar}, is the same as it was before you
1604 extracted @samp{blues}. You can confirm this by running @command{tar} with
1605 @option{--list} (@option{-t}).
1607 Remember that as with other operations, specifying the exact member
1608 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1609 will fail, because there is no member named @file{birds}. To extract
1610 the member named @file{./birds}, you must specify @w{@kbd{tar
1611 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1612 exact member names, use @option{--list} (@option{-t}) option
1613 (@pxref{list}). You can also extract those members that match a
1614 specific @dfn{globbing pattern}. For example, to extract from
1615 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1616 directory prefix, you could type:
1619 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1623 Here, @option{--wildcards} instructs @command{tar} to treat
1624 command line arguments as globbing patterns and @option{--no-anchored}
1625 informs it that the patterns apply to member names after any @samp{/}
1626 delimiter. The use of globbing patterns is discussed in detail in
1629 You can extract a file to standard output by combining the above options
1630 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1633 If you give the @option{--verbose} option, then @option{--extract}
1634 will print the names of the archive members as it extracts them.
1637 @subsection Extracting Files that are Directories
1639 Extracting directories which are members of an archive is similar to
1640 extracting other files. The main difference to be aware of is that if
1641 the extracted directory has the same name as any directory already in
1642 the working directory, then files in the extracted directory will be
1643 placed into the directory of the same name. Likewise, if there are
1644 files in the pre-existing directory with the same names as the members
1645 which you extract, the files from the extracted archive will replace
1646 the files already in the working directory (and possible
1647 subdirectories). This will happen regardless of whether or not the
1648 files in the working directory were more recent than those extracted
1649 (there exist, however, special options that alter this behavior
1652 However, if a file was stored with a directory name as part of its file
1653 name, and that directory does not exist under the working directory when
1654 the file is extracted, @command{tar} will create the directory.
1656 We can demonstrate how to use @option{--extract} to extract a directory
1657 file with an example. Change to the @file{practice} directory if you
1658 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1659 go back to the parent directory and extract the archive
1660 @file{music.tar}. You may either extract the entire archive, or you may
1661 extract only the files you just deleted. To extract the entire archive,
1662 don't give any file names as arguments after the archive name
1663 @file{music.tar}. To extract only the files you deleted, use the
1667 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1673 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1674 would have displayed more detail about the extracted files, as shown
1675 in the example below:
1678 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1679 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1680 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1684 Because you created the directory with @file{practice} as part of the
1685 file names of each of the files by archiving the @file{practice}
1686 directory as @file{practice}, you must give @file{practice} as part
1687 of the file names when you extract those files from the archive.
1689 @node extracting untrusted archives
1690 @subsection Extracting Archives from Untrusted Sources
1692 Extracting files from archives can overwrite files that already exist.
1693 If you receive an archive from an untrusted source, you should make a
1694 new directory and extract into that directory, so that you don't have
1695 to worry about the extraction overwriting one of your existing files.
1696 For example, if @file{untrusted.tar} came from somewhere else on the
1697 Internet, and you don't necessarily trust its contents, you can
1698 extract it as follows:
1701 $ @kbd{mkdir newdir}
1703 $ @kbd{tar -xvf ../untrusted.tar}
1706 It is also a good practice to examine contents of the archive
1707 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1708 with @option{--verbose} (@option{-v}).
1710 @node failing commands
1711 @subsection Commands That Will Fail
1713 Here are some sample commands you might try which will not work, and why
1716 If you try to use this command,
1719 $ @kbd{tar -xvf music.tar folk jazz}
1723 you will get the following response:
1726 tar: folk: Not found in archive
1727 tar: jazz: Not found in archive
1732 This is because these files were not originally @emph{in} the parent
1733 directory @file{..}, where the archive is located; they were in the
1734 @file{practice} directory, and their file names reflect this:
1737 $ @kbd{tar -tvf music.tar}
1743 @FIXME{make sure the above works when going through the examples in
1747 Likewise, if you try to use this command,
1750 $ @kbd{tar -tvf music.tar folk jazz}
1754 you would get a similar response. Members with those names are not in the
1755 archive. You must use the correct member names, or wildcards, in order
1756 to extract the files from the archive.
1758 If you have forgotten the correct names of the files in the archive,
1759 use @w{@kbd{tar --list --verbose}} to list them correctly.
1761 @FIXME{more examples, here? hag thinks it's a good idea.}
1764 @section Going Further Ahead in this Manual
1766 @FIXME{need to write up a node here about the things that are going to
1767 be in the rest of the manual.}
1769 @node tar invocation
1770 @chapter Invoking @GNUTAR{}
1773 This chapter is about how one invokes the @GNUTAR{}
1774 command, from the command synopsis (@pxref{Synopsis}). There are
1775 numerous options, and many styles for writing them. One mandatory
1776 option specifies the operation @command{tar} should perform
1777 (@pxref{Operation Summary}), other options are meant to detail how
1778 this operation should be performed (@pxref{Option Summary}).
1779 Non-option arguments are not always interpreted the same way,
1780 depending on what the operation is.
1782 You will find in this chapter everything about option styles and rules for
1783 writing them (@pxref{Styles}). On the other hand, operations and options
1784 are fully described elsewhere, in other chapters. Here, you will find
1785 only synthetic descriptions for operations and options, together with
1786 pointers to other parts of the @command{tar} manual.
1788 Some options are so special they are fully described right in this
1789 chapter. They have the effect of inhibiting the normal operation of
1790 @command{tar} or else, they globally alter the amount of feedback the user
1791 receives about what is going on. These are the @option{--help} and
1792 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1793 and @option{--interactive} options (@pxref{interactive}).
1797 * using tar options::
1807 @section General Synopsis of @command{tar}
1809 The @GNUTAR{} program is invoked as either one of:
1812 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1813 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1816 The second form is for when old options are being used.
1818 You can use @command{tar} to store files in an archive, to extract them from
1819 an archive, and to do other types of archive manipulation. The primary
1820 argument to @command{tar}, which is called the @dfn{operation}, specifies
1821 which action to take. The other arguments to @command{tar} are either
1822 @dfn{options}, which change the way @command{tar} performs an operation,
1823 or file names or archive members, which specify the files or members
1824 @command{tar} is to act on.
1826 You can actually type in arguments in any order, even if in this manual
1827 the options always precede the other arguments, to make examples easier
1828 to understand. Further, the option stating the main operation mode
1829 (the @command{tar} main command) is usually given first.
1831 Each @var{name} in the synopsis above is interpreted as an archive member
1832 name when the main command is one of @option{--compare}
1833 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1834 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1835 @option{--update} (@option{-u}). When naming archive members, you
1836 must give the exact name of the member in the archive, as it is
1837 printed by @option{--list}. For @option{--append} (@option{-r}) and
1838 @option{--create} (@option{-c}), these @var{name} arguments specify
1839 the names of either files or directory hierarchies to place in the archive.
1840 These files or hierarchies should already exist in the file system,
1841 prior to the execution of the @command{tar} command.
1843 @command{tar} interprets relative file names as being relative to the
1844 working directory. @command{tar} will make all file names relative
1845 (by removing leading slashes when archiving or restoring files),
1846 unless you specify otherwise (using the @option{--absolute-names}
1847 option). @xref{absolute}, for more information about
1848 @option{--absolute-names}.
1850 If you give the name of a directory as either a file name or a member
1851 name, then @command{tar} acts recursively on all the files and directories
1852 beneath that directory. For example, the name @file{/} identifies all
1853 the files in the file system to @command{tar}.
1855 The distinction between file names and archive member names is especially
1856 important when shell globbing is used, and sometimes a source of confusion
1857 for newcomers. @xref{wildcards}, for more information about globbing.
1858 The problem is that shells may only glob using existing files in the
1859 file system. Only @command{tar} itself may glob on archive members, so when
1860 needed, you must ensure that wildcard characters reach @command{tar} without
1861 being interpreted by the shell first. Using a backslash before @samp{*}
1862 or @samp{?}, or putting the whole argument between quotes, is usually
1863 sufficient for this.
1865 Even if @var{name}s are often specified on the command line, they
1866 can also be read from a text file in the file system, using the
1867 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1869 If you don't use any file name arguments, @option{--append} (@option{-r}),
1870 @option{--delete} and @option{--concatenate} (@option{--catenate},
1871 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1872 will usually yield a diagnostic and inhibit @command{tar} execution.
1873 The other operations of @command{tar} (@option{--list},
1874 @option{--extract}, @option{--compare}, and @option{--update})
1875 will act on the entire contents of the archive.
1878 @cindex return status
1879 Besides successful exits, @GNUTAR{} may fail for
1880 many reasons. Some reasons correspond to bad usage, that is, when the
1881 @command{tar} command is improperly written. Errors may be
1882 encountered later, while encountering an error processing the archive
1883 or the files. Some errors are recoverable, in which case the failure
1884 is delayed until @command{tar} has completed all its work. Some
1885 errors are such that it would not meaningful, or at least risky, to
1886 continue processing: @command{tar} then aborts processing immediately.
1887 All abnormal exits, whether immediate or delayed, should always be
1888 clearly diagnosed on @code{stderr}, after a line stating the nature of
1891 Possible exit codes of @GNUTAR{} are summarized in the following
1896 @samp{Successful termination}.
1899 @samp{Some files differ}. If tar was invoked with @option{--compare}
1900 (@option{--diff}, @option{-d}) command line option, this means that
1901 some files in the archive differ from their disk counterparts
1902 (@pxref{compare}). If tar was given @option{--create},
1903 @option{--append} or @option{--update} option, this exit code means
1904 that some files were changed while being archived and so the resulting
1905 archive does not contain the exact copy of the file set.
1908 @samp{Fatal error}. This means that some fatal, unrecoverable error
1912 If @command{tar} has invoked a subprocess and that subprocess exited with a
1913 nonzero exit code, @command{tar} exits with that code as well.
1914 This can happen, for example, if @command{tar} was given some
1915 compression option (@pxref{gzip}) and the external compressor program
1916 failed. Another example is @command{rmt} failure during backup to the
1917 remote device (@pxref{Remote Tape Server}).
1919 @node using tar options
1920 @section Using @command{tar} Options
1922 @GNUTAR{} has a total of eight operating modes which
1923 allow you to perform a variety of tasks. You are required to choose
1924 one operating mode each time you employ the @command{tar} program by
1925 specifying one, and only one operation as an argument to the
1926 @command{tar} command (two lists of four operations each may be found
1927 at @ref{frequent operations} and @ref{Operations}). Depending on
1928 circumstances, you may also wish to customize how the chosen operating
1929 mode behaves. For example, you may wish to change the way the output
1930 looks, or the format of the files that you wish to archive may require
1931 you to do something special in order to make the archive look right.
1933 You can customize and control @command{tar}'s performance by running
1934 @command{tar} with one or more options (such as @option{--verbose}
1935 (@option{-v}), which we used in the tutorial). As we said in the
1936 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1937 their name suggests) optional. Depending on the operating mode, you
1938 may specify one or more options. Different options will have different
1939 effects, but in general they all change details of the operation, such
1940 as archive format, archive name, or level of user interaction. Some
1941 options make sense with all operating modes, while others are
1942 meaningful only with particular modes. You will likely use some
1943 options frequently, while you will only use others infrequently, or
1944 not at all. (A full list of options is available in @pxref{All Options}.)
1946 @vrindex TAR_OPTIONS, environment variable
1947 @anchor{TAR_OPTIONS}
1948 The @env{TAR_OPTIONS} environment variable specifies default options to
1949 be placed in front of any explicit options. For example, if
1950 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1951 if the two options @option{-v} and @option{--unlink-first} had been
1952 specified before any explicit options. Option specifications are
1953 separated by whitespace. A backslash escapes the next character, so it
1954 can be used to specify an option containing whitespace or a backslash.
1956 Note that @command{tar} options are case sensitive. For example, the
1957 options @option{-T} and @option{-t} are different; the first requires an
1958 argument for stating the name of a file providing a list of @var{name}s,
1959 while the second does not require an argument and is another way to
1960 write @option{--list} (@option{-t}).
1962 In addition to the eight operations, there are many options to
1963 @command{tar}, and three different styles for writing both: long (mnemonic)
1964 form, short form, and old style. These styles are discussed below.
1965 Both the options and the operations can be written in any of these three
1968 @FIXME{menu at end of this node. need to think of an actual outline
1969 for this chapter; probably do that after stuff from chapter 4 is
1973 @section The Three Option Styles
1975 There are three styles for writing operations and options to the command
1976 line invoking @command{tar}. The different styles were developed at
1977 different times during the history of @command{tar}. These styles will be
1978 presented below, from the most recent to the oldest.
1980 Some options must take an argument. (For example, @option{--file}
1981 (@option{-f})) takes the name of an archive file as an argument. If
1982 you do not supply an archive file name, @command{tar} will use a
1983 default, but this can be confusing; thus, we recommend that you always
1984 supply a specific archive file name.) Where you @emph{place} the
1985 arguments generally depends on which style of options you choose. We
1986 will detail specific information relevant to each option style in the
1987 sections on the different option styles, below. The differences are
1988 subtle, yet can often be very important; incorrect option placement
1989 can cause you to overwrite a number of important files. We urge you
1990 to note these differences, and only use the option style(s) which
1991 makes the most sense to you until you feel comfortable with the others.
1993 Some options @emph{may} take an argument. Such options may have at
1994 most long and short forms, they do not have old style equivalent. The
1995 rules for specifying an argument for such options are stricter than
1996 those for specifying mandatory arguments. Please, pay special
2000 * Long Options:: Long Option Style
2001 * Short Options:: Short Option Style
2002 * Old Options:: Old Option Style
2003 * Mixing:: Mixing Option Styles
2007 @subsection Long Option Style
2009 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2010 dashes in a row, e.g., @option{--list}. The long names are more clear than
2011 their corresponding short or old names. It sometimes happens that a
2012 single long option has many different different names which are
2013 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2014 long option names can be given unique abbreviations. For example,
2015 @option{--cre} can be used in place of @option{--create} because there is no
2016 other long option which begins with @samp{cre}. (One way to find
2017 this out is by trying it and seeing what happens; if a particular
2018 abbreviation could represent more than one option, @command{tar} will tell
2019 you that that abbreviation is ambiguous and you'll know that that
2020 abbreviation won't work. You may also choose to run @samp{tar --help}
2021 to see a list of options. Be aware that if you run @command{tar} with a
2022 unique abbreviation for the long name of an option you didn't want to
2023 use, you are stuck; @command{tar} will perform the command as ordered.)
2025 Long options are meant to be obvious and easy to remember, and their
2026 meanings are generally easier to discern than those of their
2027 corresponding short options (see below). For example:
2030 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2034 gives a fairly good set of hints about what the command does, even
2035 for those not fully acquainted with @command{tar}.
2037 Long options which require arguments take those arguments
2038 immediately following the option name. There are two ways of
2039 specifying a mandatory argument. It can be separated from the
2040 option name either by an equal sign, or by any amount of
2041 white space characters. For example, the @option{--file} option (which
2042 tells the name of the @command{tar} archive) is given a file such as
2043 @file{archive.tar} as argument by using any of the following notations:
2044 @option{--file=archive.tar} or @option{--file archive.tar}.
2046 In contrast, optional arguments must always be introduced using
2047 an equal sign. For example, the @option{--backup} option takes
2048 an optional argument specifying backup type. It must be used
2049 as @option{--backup=@var{backup-type}}.
2052 @subsection Short Option Style
2054 Most options also have a @dfn{short option} name. Short options start with
2055 a single dash, and are followed by a single character, e.g., @option{-t}
2056 (which is equivalent to @option{--list}). The forms are absolutely
2057 identical in function; they are interchangeable.
2059 The short option names are faster to type than long option names.
2061 Short options which require arguments take their arguments immediately
2062 following the option, usually separated by white space. It is also
2063 possible to stick the argument right after the short option name, using
2064 no intervening space. For example, you might write @w{@option{-f
2065 archive.tar}} or @option{-farchive.tar} instead of using
2066 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2067 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2068 specific archive, here named @file{archive.tar}.
2070 Short options which take optional arguments take their arguments
2071 immediately following the option letter, @emph{without any intervening
2072 white space characters}.
2074 Short options' letters may be clumped together, but you are not
2075 required to do this (as compared to old options; see below). When
2076 short options are clumped as a set, use one (single) dash for them
2077 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2078 such a set is allowed to have an argument@footnote{Clustering many
2079 options, the last of which has an argument, is a rather opaque way to
2080 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2081 even be made helpful enough for considering such usages as invalid.}.
2083 When the options are separated, the argument for each option which requires
2084 an argument directly follows that option, as is usual for Unix programs.
2088 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2091 If you reorder short options' locations, be sure to move any arguments
2092 that belong to them. If you do not move the arguments properly, you may
2093 end up overwriting files.
2096 @subsection Old Option Style
2099 Like short options, @dfn{old options} are single letters. However, old options
2100 must be written together as a single clumped set, without spaces separating
2101 them or dashes preceding them@footnote{Beware that if you precede options
2102 with a dash, you are announcing the short option style instead of the
2103 old option style; short options are decoded differently.}. This set
2104 of letters must be the first to appear on the command line, after the
2105 @command{tar} program name and some white space; old options cannot appear
2106 anywhere else. The letter of an old option is exactly the same letter as
2107 the corresponding short option. For example, the old option @samp{t} is
2108 the same as the short option @option{-t}, and consequently, the same as the
2109 long option @option{--list}. So for example, the command @w{@samp{tar
2110 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2112 When options that need arguments are given together with the command,
2113 all the associated arguments follow, in the same order as the options.
2114 Thus, the example given previously could also be written in the old
2118 $ @kbd{tar cvbf 20 /dev/rmt0}
2122 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2123 the argument of @option{-f}.
2125 On the other hand, this old style syntax makes it difficult to match
2126 option letters with their corresponding arguments, and is often
2127 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2128 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2129 argument for @option{-f}, and @option{-v} does not have a corresponding
2130 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2131 /dev/rmt0}} is clearer, putting all arguments next to the option they
2134 If you want to reorder the letters in the old option argument, be
2135 sure to reorder any corresponding argument appropriately.
2137 This old way of writing @command{tar} options can surprise even experienced
2138 users. For example, the two commands:
2141 @kbd{tar cfz archive.tar.gz file}
2142 @kbd{tar -cfz archive.tar.gz file}
2146 are quite different. The first example uses @file{archive.tar.gz} as
2147 the value for option @samp{f} and recognizes the option @samp{z}. The
2148 second example, however, uses @file{z} as the value for option
2149 @samp{f} --- probably not what was intended.
2151 Old options are kept for compatibility with old versions of @command{tar}.
2153 This second example could be corrected in many ways, among which the
2154 following are equivalent:
2157 @kbd{tar -czf archive.tar.gz file}
2158 @kbd{tar -cf archive.tar.gz -z file}
2159 @kbd{tar cf archive.tar.gz -z file}
2162 @cindex option syntax, traditional
2163 As far as we know, all @command{tar} programs, @acronym{GNU} and
2164 non-@acronym{GNU}, support old options. @GNUTAR{}
2165 supports them not only for historical reasons, but also because many
2166 people are used to them. For compatibility with Unix @command{tar},
2167 the first argument is always treated as containing command and option
2168 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2169 equivalent to @w{@samp{tar -c}:} both of them specify the
2170 @option{--create} (@option{-c}) command to create an archive.
2173 @subsection Mixing Option Styles
2175 All three styles may be intermixed in a single @command{tar} command,
2176 so long as the rules for each style are fully
2177 respected@footnote{Before @GNUTAR{} version 1.11.6,
2178 a bug prevented intermixing old style options with long options in
2179 some cases.}. Old style options and either of the modern styles of
2180 options may be mixed within a single @command{tar} command. However,
2181 old style options must be introduced as the first arguments only,
2182 following the rule for old options (old options must appear directly
2183 after the @command{tar} command and some white space). Modern options
2184 may be given only after all arguments to the old options have been
2185 collected. If this rule is not respected, a modern option might be
2186 falsely interpreted as the value of the argument to one of the old
2189 For example, all the following commands are wholly equivalent, and
2190 illustrate the many combinations and orderings of option styles.
2193 @kbd{tar --create --file=archive.tar}
2194 @kbd{tar --create -f archive.tar}
2195 @kbd{tar --create -farchive.tar}
2196 @kbd{tar --file=archive.tar --create}
2197 @kbd{tar --file=archive.tar -c}
2198 @kbd{tar -c --file=archive.tar}
2199 @kbd{tar -c -f archive.tar}
2200 @kbd{tar -c -farchive.tar}
2201 @kbd{tar -cf archive.tar}
2202 @kbd{tar -cfarchive.tar}
2203 @kbd{tar -f archive.tar --create}
2204 @kbd{tar -f archive.tar -c}
2205 @kbd{tar -farchive.tar --create}
2206 @kbd{tar -farchive.tar -c}
2207 @kbd{tar c --file=archive.tar}
2208 @kbd{tar c -f archive.tar}
2209 @kbd{tar c -farchive.tar}
2210 @kbd{tar cf archive.tar}
2211 @kbd{tar f archive.tar --create}
2212 @kbd{tar f archive.tar -c}
2213 @kbd{tar fc archive.tar}
2216 On the other hand, the following commands are @emph{not} equivalent to
2220 @kbd{tar -f -c archive.tar}
2221 @kbd{tar -fc archive.tar}
2222 @kbd{tar -fcarchive.tar}
2223 @kbd{tar -farchive.tarc}
2224 @kbd{tar cfarchive.tar}
2228 These last examples mean something completely different from what the
2229 user intended (judging based on the example in the previous set which
2230 uses long options, whose intent is therefore very clear). The first
2231 four specify that the @command{tar} archive would be a file named
2232 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2233 respectively. The first two examples also specify a single non-option,
2234 @var{name} argument having the value @samp{archive.tar}. The last
2235 example contains only old style option letters (repeating option
2236 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2237 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2238 the first sentence of this paragraph..}
2241 @section All @command{tar} Options
2243 The coming manual sections contain an alphabetical listing of all
2244 @command{tar} operations and options, with brief descriptions and cross
2245 references to more in-depth explanations in the body of the manual.
2246 They also contain an alphabetically arranged table of the short option
2247 forms with their corresponding long option. You can use this table as
2248 a reference for deciphering @command{tar} commands in scripts.
2251 * Operation Summary::
2253 * Short Option Summary::
2256 @node Operation Summary
2257 @subsection Operations
2265 Appends files to the end of the archive. @xref{append}.
2267 @opsummary{catenate}
2271 Same as @option{--concatenate}. @xref{concatenate}.
2277 Compares archive members with their counterparts in the file
2278 system, and reports differences in file size, mode, owner,
2279 modification date and contents. @xref{compare}.
2281 @opsummary{concatenate}
2285 Appends other @command{tar} archives to the end of the archive.
2292 Creates a new @command{tar} archive. @xref{create}.
2297 Deletes members from the archive. Don't try this on a archive on a
2298 tape! @xref{delete}.
2304 Same @option{--compare}. @xref{compare}.
2310 Extracts members from the archive into the file system. @xref{extract}.
2316 Same as @option{--extract}. @xref{extract}.
2322 Lists the members in an archive. @xref{list}.
2328 Adds files to the end of the archive, but only if they are newer than
2329 their counterparts already in the archive, or if they do not already
2330 exist in the archive. @xref{update}.
2334 @node Option Summary
2335 @subsection @command{tar} Options
2339 @opsummary{absolute-names}
2340 @item --absolute-names
2343 Normally when creating an archive, @command{tar} strips an initial
2344 @samp{/} from member names. This option disables that behavior.
2347 @opsummary{after-date}
2350 (See @option{--newer}, @pxref{after})
2352 @opsummary{anchored}
2354 A pattern must match an initial subsequence of the name's components.
2355 @xref{controlling pattern-matching}.
2357 @opsummary{atime-preserve}
2358 @item --atime-preserve
2359 @itemx --atime-preserve=replace
2360 @itemx --atime-preserve=system
2362 Attempt to preserve the access time of files when reading them. This
2363 option currently is effective only on files that you own, unless you
2364 have superuser privileges.
2366 @option{--atime-preserve=replace} remembers the access time of a file
2367 before reading it, and then restores the access time afterwards. This
2368 may cause problems if other programs are reading the file at the same
2369 time, as the times of their accesses will be lost. On most platforms
2370 restoring the access time also requires @command{tar} to restore the
2371 data modification time too, so this option may also cause problems if
2372 other programs are writing the file at the same time. (Tar attempts
2373 to detect this situation, but cannot do so reliably due to race
2374 conditions.) Worse, on most platforms restoring the access time also
2375 updates the status change time, which means that this option is
2376 incompatible with incremental backups.
2378 @option{--atime-preserve=system} avoids changing time stamps on files,
2379 without interfering with time stamp updates
2380 caused by other programs, so it works better with incremental backups.
2381 However, it requires a special @code{O_NOATIME} option from the
2382 underlying operating and file system implementation, and it also requires
2383 that searching directories does not update their access times. As of
2384 this writing (November 2005) this works only with Linux, and only with
2385 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2386 way to know whether this feature actually works. Sometimes
2387 @command{tar} knows that it does not work, and if you use
2388 @option{--atime-preserve=system} then @command{tar} complains and
2389 exits right away. But other times @command{tar} might think that the
2390 option works when it actually does not.
2392 Currently @option{--atime-preserve} with no operand defaults to
2393 @option{--atime-preserve=replace}, but this may change in the future
2394 as support for @option{--atime-preserve=system} improves.
2396 If your operating system does not support
2397 @option{--atime-preserve=@-system}, you might be able to preserve access
2398 times reliably by by using the @command{mount} command. For example,
2399 you can mount the file system read-only, or access the file system via
2400 a read-only loopback mount, or use the @samp{noatime} mount option
2401 available on some systems. However, mounting typically requires
2402 superuser privileges and can be a pain to manage.
2405 @item --backup=@var{backup-type}
2407 Rather than deleting files from the file system, @command{tar} will
2408 back them up using simple or numbered backups, depending upon
2409 @var{backup-type}. @xref{backup}.
2411 @opsummary{block-number}
2412 @item --block-number
2415 With this option present, @command{tar} prints error messages for read errors
2416 with the block number in the archive file. @xref{block-number}.
2418 @opsummary{blocking-factor}
2419 @item --blocking-factor=@var{blocking}
2420 @itemx -b @var{blocking}
2422 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2423 record. @xref{Blocking Factor}.
2429 This option tells @command{tar} to read or write archives through
2430 @code{bzip2}. @xref{gzip}.
2432 @opsummary{checkpoint}
2433 @item --checkpoint[=@var{number}]
2435 This option directs @command{tar} to print periodic checkpoint
2436 messages as it reads through the archive. It is intended for when you
2437 want a visual indication that @command{tar} is still running, but
2438 don't want to see @option{--verbose} output. For a detailed
2439 description, see @ref{Progress information}.
2441 @opsummary{check-links}
2444 If this option was given, @command{tar} will check the number of links
2445 dumped for each processed file. If this number does not match the
2446 total number of hard links for the file, a warning message will be
2447 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2448 synonym for @option{--one-file-system}. The current semantics, which
2449 complies to UNIX98, was introduced with version
2450 1.15.91. @xref{Changes}, for more information.}.
2452 @opsummary{compress}
2453 @opsummary{uncompress}
2458 @command{tar} will use the @command{compress} program when reading or
2459 writing the archive. This allows you to directly act on archives
2460 while saving space. @xref{gzip}.
2462 @opsummary{confirmation}
2463 @item --confirmation
2465 (See @option{--interactive}.) @xref{interactive}.
2467 @opsummary{delay-directory-restore}
2468 @item --delay-directory-restore
2470 Delay setting modification times and permissions of extracted
2471 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2473 @opsummary{dereference}
2477 When creating a @command{tar} archive, @command{tar} will archive the
2478 file that a symbolic link points to, rather than archiving the
2479 symlink. @xref{dereference}.
2481 @opsummary{directory}
2482 @item --directory=@var{dir}
2485 When this option is specified, @command{tar} will change its current directory
2486 to @var{dir} before performing any operations. When this option is used
2487 during archive creation, it is order sensitive. @xref{directory}.
2490 @item --exclude=@var{pattern}
2492 When performing operations, @command{tar} will skip files that match
2493 @var{pattern}. @xref{exclude}.
2495 @opsummary{exclude-from}
2496 @item --exclude-from=@var{file}
2497 @itemx -X @var{file}
2499 Similar to @option{--exclude}, except @command{tar} will use the list of
2500 patterns in the file @var{file}. @xref{exclude}.
2502 @opsummary{exclude-caches}
2503 @item --exclude-caches
2505 Automatically excludes all directories
2506 containing a cache directory tag. @xref{exclude}.
2509 @item --file=@var{archive}
2510 @itemx -f @var{archive}
2512 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2513 performs operations on, rather than @command{tar}'s compilation dependent
2514 default. @xref{file tutorial}.
2516 @opsummary{files-from}
2517 @item --files-from=@var{file}
2518 @itemx -T @var{file}
2520 @command{tar} will use the contents of @var{file} as a list of archive members
2521 or files to operate on, in addition to those specified on the
2522 command-line. @xref{files}.
2524 @opsummary{force-local}
2527 Forces @command{tar} to interpret the filename given to @option{--file}
2528 as a local file, even if it looks like a remote tape drive name.
2529 @xref{local and remote archives}.
2532 @item --format=@var{format}
2533 @itemx -H @var{format}
2535 Selects output archive format. @var{Format} may be one of the
2540 Creates an archive that is compatible with Unix V7 @command{tar}.
2543 Creates an archive that is compatible with GNU @command{tar} version
2547 Creates archive in GNU tar 1.13 format. Basically it is the same as
2548 @samp{oldgnu} with the only difference in the way it handles long
2552 Creates a @acronym{POSIX.1-1988} compatible archive.
2555 Creates a @acronym{POSIX.1-2001 archive}.
2559 @xref{Formats}, for a detailed discussion of these formats.
2562 @item --group=@var{group}
2564 Files added to the @command{tar} archive will have a group id of @var{group},
2565 rather than the group from the source file. @var{group} is first decoded
2566 as a group symbolic name, but if this interpretation fails, it has to be
2567 a decimal numeric group ID. @xref{override}.
2569 Also see the comments for the @option{--owner=@var{user}} option.
2579 This option tells @command{tar} to read or write archives through
2580 @command{gzip}, allowing @command{tar} to directly operate on several
2581 kinds of compressed archives transparently. @xref{gzip}.
2587 @command{tar} will print out a short message summarizing the operations and
2588 options to @command{tar} and exit. @xref{help}.
2590 @opsummary{ignore-case}
2592 Ignore case when matching member or file names with
2593 patterns. @xref{controlling pattern-matching}.
2595 @opsummary{ignore-command-error}
2596 @item --ignore-command-error
2597 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2599 @opsummary{ignore-failed-read}
2600 @item --ignore-failed-read
2602 Do not exit unsuccessfully merely because an unreadable file was encountered.
2605 @opsummary{ignore-zeros}
2606 @item --ignore-zeros
2609 With this option, @command{tar} will ignore zeroed blocks in the
2610 archive, which normally signals EOF. @xref{Reading}.
2612 @opsummary{incremental}
2616 Used to inform @command{tar} that it is working with an old
2617 @acronym{GNU}-format incremental backup archive. It is intended
2618 primarily for backwards compatibility only. @xref{Incremental Dumps},
2619 for a detailed discussion of incremental archives.
2621 @opsummary{index-file}
2622 @item --index-file=@var{file}
2624 Send verbose output to @var{file} instead of to standard output.
2626 @opsummary{info-script}
2627 @opsummary{new-volume-script}
2628 @item --info-script=@var{script-file}
2629 @itemx --new-volume-script=@var{script-file}
2630 @itemx -F @var{script-file}
2632 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2633 at the end of each tape. If @var{script-file} exits with nonzero status,
2634 @command{tar} fails immediately. @xref{info-script}, for a detailed
2635 discussion of @var{script-file}.
2637 @opsummary{interactive}
2639 @itemx --confirmation
2642 Specifies that @command{tar} should ask the user for confirmation before
2643 performing potentially destructive options, such as overwriting files.
2646 @opsummary{keep-newer-files}
2647 @item --keep-newer-files
2649 Do not replace existing files that are newer than their archive copies
2650 when extracting files from an archive.
2652 @opsummary{keep-old-files}
2653 @item --keep-old-files
2656 Do not overwrite existing files when extracting files from an archive.
2657 @xref{Keep Old Files}.
2660 @item --label=@var{name}
2661 @itemx -V @var{name}
2663 When creating an archive, instructs @command{tar} to write @var{name}
2664 as a name record in the archive. When extracting or listing archives,
2665 @command{tar} will only operate on archives that have a label matching
2666 the pattern specified in @var{name}. @xref{Tape Files}.
2668 @opsummary{listed-incremental}
2669 @item --listed-incremental=@var{snapshot-file}
2670 @itemx -g @var{snapshot-file}
2672 During a @option{--create} operation, specifies that the archive that
2673 @command{tar} creates is a new @acronym{GNU}-format incremental
2674 backup, using @var{snapshot-file} to determine which files to backup.
2675 With other operations, informs @command{tar} that the archive is in
2676 incremental format. @xref{Incremental Dumps}.
2679 @item --mode=@var{permissions}
2681 When adding files to an archive, @command{tar} will use
2682 @var{permissions} for the archive members, rather than the permissions
2683 from the files. @var{permissions} can be specified either as an octal
2684 number or as symbolic permissions, like with
2685 @command{chmod}. @xref{override}.
2688 @item --mtime=@var{date}
2690 When adding files to an archive, @command{tar} will use @var{date} as
2691 the modification time of members when creating archives, instead of
2692 their actual modification times. The value of @var{date} can be
2693 either a textual date representation (@pxref{Date input formats}) or a
2694 name of the existing file, starting with @samp{/} or @samp{.}. In the
2695 latter case, the modification time of that file is used. @xref{override}.
2697 @opsummary{multi-volume}
2698 @item --multi-volume
2701 Informs @command{tar} that it should create or otherwise operate on a
2702 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2704 @opsummary{new-volume-script}
2705 @item --new-volume-script
2713 Assume that the archive media supports seeks to arbitrary
2714 locations. Usually @command{tar} determines automatically whether
2715 the archive can be seeked or not. This option is intended for use
2716 in cases when such recognition fails.
2719 @item --newer=@var{date}
2720 @itemx --after-date=@var{date}
2723 When creating an archive, @command{tar} will only add files that have changed
2724 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2725 is taken to be the name of a file whose data modification time specifies
2726 the date. @xref{after}.
2728 @opsummary{newer-mtime}
2729 @item --newer-mtime=@var{date}
2731 Like @option{--newer}, but add only files whose
2732 contents have changed (as opposed to just @option{--newer}, which will
2733 also back up files for which any status information has
2734 changed). @xref{after}.
2736 @opsummary{no-anchored}
2738 An exclude pattern can match any subsequence of the name's components.
2739 @xref{controlling pattern-matching}.
2741 @opsummary{no-delay-directory-restore}
2742 @item --no-delay-directory-restore
2744 Setting modification times and permissions of extracted
2745 directories when all files from this directory has been
2746 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2748 @opsummary{no-ignore-case}
2749 @item --no-ignore-case
2750 Use case-sensitive matching.
2751 @xref{controlling pattern-matching}.
2753 @opsummary{no-ignore-command-error}
2754 @item --no-ignore-command-error
2755 Print warnings about subprocesses terminated with a non-zero exit
2756 code. @xref{Writing to an External Program}.
2758 @opsummary{no-overwrite-dir}
2759 @item --no-overwrite-dir
2761 Preserve metadata of existing directories when extracting files
2762 from an archive. @xref{Overwrite Old Files}.
2764 @opsummary{no-quote-chars}
2765 @item --no-quote-chars=@var{string}
2766 Remove characters listed in @var{string} from the list of quoted
2767 characters set by the previous @option{--quote-chars} option
2768 (@pxref{quoting styles}).
2770 @opsummary{no-recursion}
2771 @item --no-recursion
2773 With this option, @command{tar} will not recurse into directories.
2776 @opsummary{no-same-owner}
2777 @item --no-same-owner
2780 When extracting an archive, do not attempt to preserve the owner
2781 specified in the @command{tar} archive. This the default behavior
2784 @opsummary{no-same-permissions}
2785 @item --no-same-permissions
2787 When extracting an archive, subtract the user's umask from files from
2788 the permissions specified in the archive. This is the default behavior
2791 @opsummary{no-unquote}
2793 Treat all input file or member names literally, do not interpret
2794 escape sequences. @xref{input name quoting}.
2796 @opsummary{no-wildcards}
2797 @item --no-wildcards
2798 Do not use wildcards.
2799 @xref{controlling pattern-matching}.
2801 @opsummary{no-wildcards-match-slash}
2802 @item --no-wildcards-match-slash
2803 Wildcards do not match @samp{/}.
2804 @xref{controlling pattern-matching}.
2809 When @command{tar} is using the @option{--files-from} option, this option
2810 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2811 @command{tar} can correctly work with file names that contain newlines.
2814 @opsummary{numeric-owner}
2815 @item --numeric-owner
2817 This option will notify @command{tar} that it should use numeric user
2818 and group IDs when creating a @command{tar} file, rather than names.
2822 The function of this option depends on the action @command{tar} is
2823 performing. When extracting files, @option{-o} is a synonym for
2824 @option{--no-same-owner}, i.e., it prevents @command{tar} from
2825 restoring ownership of files being extracted.
2827 When creating an archive, it is a synonym for
2828 @option{--old-archive}. This behavior is for compatibility
2829 with previous versions of @GNUTAR{}, and will be
2830 removed in the future releases.
2832 @xref{Changes}, for more information.
2834 @opsummary{occurrence}
2835 @item --occurrence[=@var{number}]
2837 This option can be used in conjunction with one of the subcommands
2838 @option{--delete}, @option{--diff}, @option{--extract} or
2839 @option{--list} when a list of files is given either on the command
2840 line or via @option{-T} option.
2842 This option instructs @command{tar} to process only the @var{number}th
2843 occurrence of each named file. @var{Number} defaults to 1, so
2846 tar -x -f archive.tar --occurrence filename
2850 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2851 and will terminate without scanning to the end of the archive.
2853 @opsummary{old-archive}
2855 Synonym for @option{--format=v7}.
2857 @opsummary{one-file-system}
2858 @item --one-file-system
2859 Used when creating an archive. Prevents @command{tar} from recursing into
2860 directories that are on different file systems from the current
2861 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2862 synonym for @option{--one-file-system}. This has changed in version
2863 1.15.91. @xref{Changes}, for more information.}.
2865 @opsummary{overwrite}
2868 Overwrite existing files and directory metadata when extracting files
2869 from an archive. @xref{Overwrite Old Files}.
2871 @opsummary{overwrite-dir}
2872 @item --overwrite-dir
2874 Overwrite the metadata of existing directories when extracting files
2875 from an archive. @xref{Overwrite Old Files}.
2878 @item --owner=@var{user}
2880 Specifies that @command{tar} should use @var{user} as the owner of members
2881 when creating archives, instead of the user associated with the source
2882 file. @var{user} is first decoded as a user symbolic name, but if
2883 this interpretation fails, it has to be a decimal numeric user ID.
2886 This option does not affect extraction from archives.
2888 @opsummary{transform}
2889 @item --transform=@var{sed-expr}
2891 Transform file or member names using @command{sed} replacement expression
2892 @var{sed-expr}. For example,
2895 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2899 will add to @file{archive} files from the current working directory,
2900 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2901 discussion, @xref{transform}.
2903 To see transformed member names in verbose listings, use
2904 @option{--show-transformed-names} option
2905 (@pxref{show-transformed-names}).
2907 @opsummary{quote-chars}
2908 @item --quote-chars=@var{string}
2909 Always quote characters from @var{string}, even if the selected
2910 quoting style would not quote them (@pxref{quoting styles}).
2912 @opsummary{quoting-style}
2913 @item --quoting-style=@var{style}
2914 Set quoting style to use when printing member and file names
2915 (@pxref{quoting styles}). Valid @var{style} values are:
2916 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2917 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2918 style is @code{escape}, unless overridden while configuring the
2921 @opsummary{pax-option}
2922 @item --pax-option=@var{keyword-list}
2923 This option is meaningful only with @acronym{POSIX.1-2001} archives
2924 (@pxref{posix}). It modifies the way @command{tar} handles the
2925 extended header keywords. @var{Keyword-list} is a comma-separated
2926 list of keyword options. @xref{PAX keywords}, for a detailed
2929 @opsummary{portability}
2931 @itemx --old-archive
2932 Synonym for @option{--format=v7}.
2936 Same as @option{--format=posix}.
2938 @opsummary{preserve}
2941 Synonymous with specifying both @option{--preserve-permissions} and
2942 @option{--same-order}. @xref{Setting Access Permissions}.
2944 @opsummary{preserve-order}
2945 @item --preserve-order
2947 (See @option{--same-order}; @pxref{Reading}.)
2949 @opsummary{preserve-permissions}
2950 @opsummary{same-permissions}
2951 @item --preserve-permissions
2952 @itemx --same-permissions
2955 When @command{tar} is extracting an archive, it normally subtracts the
2956 users' umask from the permissions specified in the archive and uses
2957 that number as the permissions to create the destination file.
2958 Specifying this option instructs @command{tar} that it should use the
2959 permissions directly from the archive. @xref{Setting Access Permissions}.
2961 @opsummary{read-full-records}
2962 @item --read-full-records
2965 Specifies that @command{tar} should reblock its input, for reading
2966 from pipes on systems with buggy implementations. @xref{Reading}.
2968 @opsummary{record-size}
2969 @item --record-size=@var{size}
2971 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2972 archive. @xref{Blocking Factor}.
2974 @opsummary{recursion}
2977 With this option, @command{tar} recurses into directories.
2980 @opsummary{recursive-unlink}
2981 @item --recursive-unlink
2984 directory hierarchies before extracting directories of the same name
2985 from the archive. @xref{Recursive Unlink}.
2987 @opsummary{remove-files}
2988 @item --remove-files
2990 Directs @command{tar} to remove the source file from the file system after
2991 appending it to an archive. @xref{remove files}.
2993 @opsummary{restrict}
2996 Disable use of some potentially harmful @command{tar} options.
2997 Currently this option disables shell invocation from multi-volume menu
2998 (@pxref{Using Multiple Tapes}).
3000 @opsummary{rmt-command}
3001 @item --rmt-command=@var{cmd}
3003 Notifies @command{tar} that it should use @var{cmd} instead of
3004 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3006 @opsummary{rsh-command}
3007 @item --rsh-command=@var{cmd}
3009 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3010 devices. @xref{Device}.
3012 @opsummary{same-order}
3014 @itemx --preserve-order
3017 This option is an optimization for @command{tar} when running on machines with
3018 small amounts of memory. It informs @command{tar} that the list of file
3019 arguments has already been sorted to match the order of files in the
3020 archive. @xref{Reading}.
3022 @opsummary{same-owner}
3025 When extracting an archive, @command{tar} will attempt to preserve the owner
3026 specified in the @command{tar} archive with this option present.
3027 This is the default behavior for the superuser; this option has an
3028 effect only for ordinary users. @xref{Attributes}.
3030 @opsummary{same-permissions}
3031 @item --same-permissions
3033 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3035 @opsummary{show-defaults}
3036 @item --show-defaults
3038 Displays the default options used by @command{tar} and exits
3039 successfully. This option is intended for use in shell scripts.
3040 Here is an example of what you can see using this option:
3043 $ tar --show-defaults
3044 --format=gnu -f- -b20 --quoting-style=escape \
3045 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3048 @opsummary{show-omitted-dirs}
3049 @item --show-omitted-dirs
3051 Instructs @command{tar} to mention directories its skipping over when
3052 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3054 @opsummary{show-transformed-names}
3055 @opsummary{show-stored-names}
3056 @item --show-transformed-names
3057 @itemx --show-stored-names
3059 Display file or member names after applying any transformations
3060 (@pxref{transform}). In particular, when used in conjunction with one of
3061 archive creation operations it instructs tar to list the member names
3062 stored in the archive, as opposed to the actual file
3063 names. @xref{listing member and file names}.
3069 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3070 sparse files efficiently. @xref{sparse}.
3072 @opsummary{sparse-version}
3073 @item --sparse-version=@var{version}
3075 Specified the @dfn{format version} to use when archiving sparse
3076 files. Implies @option{--sparse}. @xref{sparse}. For the description
3077 of the supported sparse formats, @xref{Sparse Formats}.
3079 @opsummary{starting-file}
3080 @item --starting-file=@var{name}
3081 @itemx -K @var{name}
3083 This option affects extraction only; @command{tar} will skip extracting
3084 files in the archive until it finds one that matches @var{name}.
3087 @opsummary{strip-components}
3088 @item --strip-components=@var{number}
3089 Strip given @var{number} of leading components from file names before
3090 extraction.@footnote{This option was called @option{--strip-path} in
3091 version 1.14.} For example, if archive @file{archive.tar} contained
3092 @file{/some/file/name}, then running
3095 tar --extract --file archive.tar --strip-components=2
3099 would extract this file to file @file{name}.
3101 @opsummary{suffix}, summary
3102 @item --suffix=@var{suffix}
3104 Alters the suffix @command{tar} uses when backing up files from the default
3105 @samp{~}. @xref{backup}.
3107 @opsummary{tape-length}
3108 @item --tape-length=@var{num}
3111 Specifies the length of tapes that @command{tar} is writing as being
3112 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3114 @opsummary{test-label}
3117 Reads the volume label. If an argument is specified, test whether it
3118 matches the volume label. @xref{--test-label option}.
3120 @opsummary{to-command}
3121 @item --to-command=@var{command}
3123 During extraction @command{tar} will pipe extracted files to the
3124 standard input of @var{command}. @xref{Writing to an External Program}.
3126 @opsummary{to-stdout}
3130 During extraction, @command{tar} will extract files to stdout rather
3131 than to the file system. @xref{Writing to Standard Output}.
3134 @item --totals[=@var{signo}]
3136 Displays the total number of bytes transferred when processing an
3137 archive. If an argument is given, these data are displayed on
3138 request, when signal @var{signo} is delivered to @command{tar}.
3145 Sets the data modification time of extracted files to the extraction time,
3146 rather than the data modification time stored in the archive.
3147 @xref{Data Modification Times}.
3149 @opsummary{uncompress}
3152 (See @option{--compress}. @pxref{gzip})
3157 (See @option{--gzip}. @pxref{gzip})
3159 @opsummary{unlink-first}
3160 @item --unlink-first
3163 Directs @command{tar} to remove the corresponding file from the file
3164 system before extracting it from the archive. @xref{Unlink First}.
3168 Enable unquoting input file or member names (default). @xref{input
3171 @opsummary{use-compress-program}
3172 @item --use-compress-program=@var{prog}
3174 Instructs @command{tar} to access the archive through @var{prog}, which is
3175 presumed to be a compression program of some sort. @xref{gzip}.
3180 Display file modification dates in @acronym{UTC}. This option implies
3187 Specifies that @command{tar} should be more verbose about the operations its
3188 performing. This option can be specified multiple times for some
3189 operations to increase the amount of information displayed.
3196 Verifies that the archive was correctly written when creating an
3197 archive. @xref{verify}.
3202 Print information about the program's name, version, origin and legal
3203 status, all on standard output, and then exit successfully.
3206 @opsummary{volno-file}
3207 @item --volno-file=@var{file}
3209 Used in conjunction with @option{--multi-volume}. @command{tar} will
3210 keep track of which volume of a multi-volume archive its working in
3211 @var{file}. @xref{volno-file}.
3213 @opsummary{wildcards}
3215 Use wildcards when matching member names with patterns.
3216 @xref{controlling pattern-matching}.
3218 @opsummary{wildcards-match-slash}
3219 @item --wildcards-match-slash
3220 Wildcards match @samp{/}.
3221 @xref{controlling pattern-matching}.
3224 @node Short Option Summary
3225 @subsection Short Options Cross Reference
3227 Here is an alphabetized list of all of the short option forms, matching
3228 them with the equivalent long option.
3230 @multitable @columnfractions 0.20 0.80
3231 @headitem Short Option @tab Reference
3233 @item -A @tab @ref{--concatenate}.
3235 @item -B @tab @ref{--read-full-records}.
3237 @item -C @tab @ref{--directory}.
3239 @item -F @tab @ref{--info-script}.
3241 @item -G @tab @ref{--incremental}.
3243 @item -K @tab @ref{--starting-file}.
3245 @item -L @tab @ref{--tape-length}.
3247 @item -M @tab @ref{--multi-volume}.
3249 @item -N @tab @ref{--newer}.
3251 @item -O @tab @ref{--to-stdout}.
3253 @item -P @tab @ref{--absolute-names}.
3255 @item -R @tab @ref{--block-number}.
3257 @item -S @tab @ref{--sparse}.
3259 @item -T @tab @ref{--files-from}.
3261 @item -U @tab @ref{--unlink-first}.
3263 @item -V @tab @ref{--label}.
3265 @item -W @tab @ref{--verify}.
3267 @item -X @tab @ref{--exclude-from}.
3269 @item -Z @tab @ref{--compress}.
3271 @item -b @tab @ref{--blocking-factor}.
3273 @item -c @tab @ref{--create}.
3275 @item -d @tab @ref{--compare}.
3277 @item -f @tab @ref{--file}.
3279 @item -g @tab @ref{--listed-incremental}.
3281 @item -h @tab @ref{--dereference}.
3283 @item -i @tab @ref{--ignore-zeros}.
3285 @item -j @tab @ref{--bzip2}.
3287 @item -k @tab @ref{--keep-old-files}.
3289 @item -l @tab @ref{--check-links}.
3291 @item -m @tab @ref{--touch}.
3293 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3294 @ref{--portability}.
3296 The later usage is deprecated. It is retained for compatibility with
3297 the earlier versions of @GNUTAR{}. In the future releases
3298 @option{-o} will be equivalent to @option{--no-same-owner} only.
3300 @item -p @tab @ref{--preserve-permissions}.
3302 @item -r @tab @ref{--append}.
3304 @item -s @tab @ref{--same-order}.
3306 @item -t @tab @ref{--list}.
3308 @item -u @tab @ref{--update}.
3310 @item -v @tab @ref{--verbose}.
3312 @item -w @tab @ref{--interactive}.
3314 @item -x @tab @ref{--extract}.
3316 @item -z @tab @ref{--gzip}.
3321 @section @GNUTAR{} documentation
3323 @cindex Getting program version number
3325 @cindex Version of the @command{tar} program
3326 Being careful, the first thing is really checking that you are using
3327 @GNUTAR{}, indeed. The @option{--version} option
3328 causes @command{tar} to print information about its name, version,
3329 origin and legal status, all on standard output, and then exit
3330 successfully. For example, @w{@samp{tar --version}} might print:
3333 tar (GNU tar) @value{VERSION}
3334 Copyright (C) 2006 Free Software Foundation, Inc.
3335 This is free software. You may redistribute copies of it under the terms
3336 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3337 There is NO WARRANTY, to the extent permitted by law.
3339 Written by John Gilmore and Jay Fenlason.
3343 The first occurrence of @samp{tar} in the result above is the program
3344 name in the package (for example, @command{rmt} is another program),
3345 while the second occurrence of @samp{tar} is the name of the package
3346 itself, containing possibly many programs. The package is currently
3347 named @samp{tar}, after the name of the main program it
3348 contains@footnote{There are plans to merge the @command{cpio} and
3349 @command{tar} packages into a single one which would be called
3350 @code{paxutils}. So, who knows if, one of this days, the
3351 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3354 @cindex Obtaining help
3355 @cindex Listing all @command{tar} options
3356 @xopindex{help, introduction}
3357 Another thing you might want to do is checking the spelling or meaning
3358 of some particular @command{tar} option, without resorting to this
3359 manual, for once you have carefully read it. @GNUTAR{}
3360 has a short help feature, triggerable through the
3361 @option{--help} option. By using this option, @command{tar} will
3362 print a usage message listing all available options on standard
3363 output, then exit successfully, without doing anything else and
3364 ignoring all other options. Even if this is only a brief summary, it
3365 may be several screens long. So, if you are not using some kind of
3366 scrollable window, you might prefer to use something like:
3369 $ @kbd{tar --help | less}
3373 presuming, here, that you like using @command{less} for a pager. Other
3374 popular pagers are @command{more} and @command{pg}. If you know about some
3375 @var{keyword} which interests you and do not want to read all the
3376 @option{--help} output, another common idiom is doing:
3379 tar --help | grep @var{keyword}
3383 for getting only the pertinent lines. Notice, however, that some
3384 @command{tar} options have long description lines and the above
3385 command will list only the first of them.
3387 The exact look of the option summary displayed by @kbd{tar --help} is
3388 configurable. @xref{Configuring Help Summary}, for a detailed description.
3391 If you only wish to check the spelling of an option, running @kbd{tar
3392 --usage} may be a better choice. This will display a terse list of
3393 @command{tar} option without accompanying explanations.
3395 The short help output is quite succinct, and you might have to get
3396 back to the full documentation for precise points. If you are reading
3397 this paragraph, you already have the @command{tar} manual in some
3398 form. This manual is available in a variety of forms from
3399 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3400 distribution, provided you have @TeX{} already installed somewhere,
3401 and a laser printer around. Just configure the distribution, execute
3402 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3403 usual way (contact your local guru to know how). If @GNUTAR{}
3404 has been conveniently installed at your place, this
3405 manual is also available in interactive, hypertextual form as an Info
3406 file. Just call @w{@samp{info tar}} or, if you do not have the
3407 @command{info} program handy, use the Info reader provided within
3408 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3410 There is currently no @code{man} page for @GNUTAR{}.
3411 If you observe such a @code{man} page on the system you are running,
3412 either it does not belong to @GNUTAR{}, or it has not
3413 been produced by @acronym{GNU}. Some package maintainers convert
3414 @kbd{tar --help} output to a man page, using @command{help2man}. In
3415 any case, please bear in mind that the authoritative source of
3416 information about @GNUTAR{} is this Texinfo documentation.
3419 @section Obtaining @GNUTAR{} default values
3421 @opindex show-defaults
3422 @GNUTAR{} has some predefined defaults that are used when you do not
3423 explicitly specify another values. To obtain a list of such
3424 defaults, use @option{--show-defaults} option. This will output the
3425 values in the form of @command{tar} command line options:
3429 @kbd{tar --show-defaults}
3430 --format=gnu -f- -b20 --quoting-style=escape
3431 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3436 Notice, that this option outputs only one line. The example output above
3437 has been split to fit page boundaries.
3440 The above output shows that this version of @GNUTAR{} defaults to
3441 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3442 output as the archive, if no @option{--file} option has been given
3443 (@pxref{file tutorial}), the default blocking factor is 20
3444 (@pxref{Blocking Factor}). It also shows the default locations where
3445 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3448 @section Checking @command{tar} progress
3450 Typically, @command{tar} performs most operations without reporting any
3451 information to the user except error messages. When using @command{tar}
3452 with many options, particularly ones with complicated or
3453 difficult-to-predict behavior, it is possible to make serious mistakes.
3454 @command{tar} provides several options that make observing @command{tar}
3455 easier. These options cause @command{tar} to print information as it
3456 progresses in its job, and you might want to use them just for being
3457 more careful about what is going on, or merely for entertaining
3458 yourself. If you have encountered a problem when operating on an
3459 archive, however, you may need more information than just an error
3460 message in order to solve the problem. The following options can be
3461 helpful diagnostic tools.
3463 @cindex Verbose operation
3465 Normally, the @option{--list} (@option{-t}) command to list an archive
3466 prints just the file names (one per line) and the other commands are
3467 silent. When used with most operations, the @option{--verbose}
3468 (@option{-v}) option causes @command{tar} to print the name of each
3469 file or archive member as it is processed. This and the other options
3470 which make @command{tar} print status information can be useful in
3471 monitoring @command{tar}.
3473 With @option{--create} or @option{--extract}, @option{--verbose} used
3474 once just prints the names of the files or members as they are processed.
3475 Using it twice causes @command{tar} to print a longer listing
3476 (@xref{verbose member listing}, for the description) for each member.
3477 Since @option{--list} already prints the names of the members,
3478 @option{--verbose} used once with @option{--list} causes @command{tar}
3479 to print an @samp{ls -l} type listing of the files in the archive.
3480 The following examples both extract members with long list output:
3483 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3484 $ @kbd{tar xvvf archive.tar}
3487 Verbose output appears on the standard output except when an archive is
3488 being written to the standard output, as with @samp{tar --create
3489 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3490 installer let standard output be the default archive). In that case
3491 @command{tar} writes verbose output to the standard error stream.
3493 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3494 verbose output to @var{file} rather than to standard output or standard
3498 @cindex Obtaining total status information
3500 The @option{--totals} option causes @command{tar} to print on the
3501 standard error the total amount of bytes transferred when processing
3502 an archive. When creating or appending to an archive, this option
3503 prints the number of bytes written to the archive and the average
3504 speed at which they have been written, e.g.:
3508 $ @kbd{tar -c -f archive.tar --totals /home}
3509 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3513 When reading an archive, this option displays the number of bytes
3518 $ @kbd{tar -x -f archive.tar --totals}
3519 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3523 Finally, when deleting from an archive, the @option{--totals} option
3524 displays both numbers plus number of bytes removed from the archive:
3528 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3529 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3530 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3531 Total bytes deleted: 1474048
3535 You can also obtain this information on request. When
3536 @option{--totals} is used with an argument, this argument is
3537 interpreted as a symbolic name of a signal, upon delivery of which the
3538 statistics is to be printed:
3541 @item --totals=@var{signo}
3542 Print statistics upon delivery of signal @var{signo}. Valid arguments
3543 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3544 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3548 Both forms of @option{--totals} option can be used simultaneously.
3549 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3550 extract all members from its default archive and print statistics
3551 after finishing the extraction, as well as when receiving signal
3554 @anchor{Progress information}
3555 @cindex Progress information
3557 The @option{--checkpoint} option prints an occasional message
3558 as @command{tar} reads or writes the archive. It is designed for
3559 those who don't need the more detailed (and voluminous) output of
3560 @option{--block-number} (@option{-R}), but do want visual confirmation
3561 that @command{tar} is actually making forward progress. By default it
3562 prints a message each 10 records read or written. This can be changed
3563 by giving it a numeric argument after an equal sign:
3566 $ @kbd{tar -c --checkpoint=1000} /var
3567 tar: Write checkpoint 1000
3568 tar: Write checkpoint 2000
3569 tar: Write checkpoint 3000
3572 This example shows the default checkpoint message used by
3573 @command{tar}. If you place a dot immediately after the equal
3574 sign, it will print a @samp{.} at each checkpoint. For example:
3577 $ @kbd{tar -c --checkpoint=.1000} /var
3581 @opindex show-omitted-dirs
3582 @anchor{show-omitted-dirs}
3583 The @option{--show-omitted-dirs} option, when reading an archive---with
3584 @option{--list} or @option{--extract}, for example---causes a message
3585 to be printed for each directory in the archive which is skipped.
3586 This happens regardless of the reason for skipping: the directory might
3587 not have been named on the command line (implicitly or explicitly),
3588 it might be excluded by the use of the
3589 @option{--exclude=@var{pattern}} option, or some other reason.
3591 @opindex block-number
3592 @cindex Block number where error occurred
3593 @anchor{block-number}
3594 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3595 every message it would normally produce, the block number within the
3596 archive where the message was triggered. Also, supplementary messages
3597 are triggered when reading blocks full of NULs, or when hitting end of
3598 file on the archive. As of now, if the archive if properly terminated
3599 with a NUL block, the reading of the file may stop before end of file
3600 is met, so the position of end of file will not usually show when
3601 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3602 drains the archive before exiting when reading the
3603 archive from a pipe.
3605 @cindex Error message, block number of
3606 This option is especially useful when reading damaged archives, since
3607 it helps pinpoint the damaged sections. It can also be used with
3608 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3609 choose among several backup tapes when retrieving a file later, in
3610 favor of the tape where the file appears earliest (closest to the
3611 front of the tape). @xref{backup}.
3614 @section Asking for Confirmation During Operations
3615 @cindex Interactive operation
3617 Typically, @command{tar} carries out a command without stopping for
3618 further instructions. In some situations however, you may want to
3619 exclude some files and archive members from the operation (for instance
3620 if disk or storage space is tight). You can do this by excluding
3621 certain files automatically (@pxref{Choosing}), or by performing
3622 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3623 @command{tar} also accepts @option{--confirmation} for this option.
3625 @opindex interactive
3626 When the @option{--interactive} (@option{-w}) option is specified, before
3627 reading, writing, or deleting files, @command{tar} first prints a message
3628 for each such file, telling what operation it intends to take, then asks
3629 for confirmation on the terminal. The actions which require
3630 confirmation include adding a file to the archive, extracting a file
3631 from the archive, deleting a file from the archive, and deleting a file
3632 from disk. To confirm the action, you must type a line of input
3633 beginning with @samp{y}. If your input line begins with anything other
3634 than @samp{y}, @command{tar} skips that file.
3636 If @command{tar} is reading the archive from the standard input,
3637 @command{tar} opens the file @file{/dev/tty} to support the interactive
3640 Verbose output is normally sent to standard output, separate from
3641 other error messages. However, if the archive is produced directly
3642 on standard output, then verbose output is mixed with errors on
3643 @code{stderr}. Producing the archive on standard output may be used
3644 as a way to avoid using disk space, when the archive is soon to be
3645 consumed by another process reading it, say. Some people felt the need
3646 of producing an archive on stdout, still willing to segregate between
3647 verbose output and error output. A possible approach would be using a
3648 named pipe to receive the archive, and having the consumer process to
3649 read from that named pipe. This has the advantage of letting standard
3650 output free to receive verbose output, all separate from errors.
3653 @chapter @GNUTAR{} Operations
3666 @section Basic @GNUTAR{} Operations
3668 The basic @command{tar} operations, @option{--create} (@option{-c}),
3669 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3670 @option{-x}), are currently presented and described in the tutorial
3671 chapter of this manual. This section provides some complementary notes
3672 for these operations.
3675 @xopindex{create, complementary notes}
3679 Creating an empty archive would have some kind of elegance. One can
3680 initialize an empty archive and later use @option{--append}
3681 (@option{-r}) for adding all members. Some applications would not
3682 welcome making an exception in the way of adding the first archive
3683 member. On the other hand, many people reported that it is
3684 dangerously too easy for @command{tar} to destroy a magnetic tape with
3685 an empty archive@footnote{This is well described in @cite{Unix-haters
3686 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3687 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3691 Mistakingly using @code{create} instead of @code{extract}, when the
3692 intent was to extract the full contents of an archive. This error
3693 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3694 the QWERTY keyboard. Instead of being unpacked, the archive then
3695 gets wholly destroyed. When users speak about @dfn{exploding} an
3696 archive, they usually mean something else :-).
3699 Forgetting the argument to @code{file}, when the intent was to create
3700 an archive with a single file in it. This error is likely because a
3701 tired user can easily add the @kbd{f} key to the cluster of option
3702 letters, by the mere force of habit, without realizing the full
3703 consequence of doing so. The usual consequence is that the single
3704 file, which was meant to be saved, is rather destroyed.
3707 So, recognizing the likelihood and the catastrophic nature of these
3708 errors, @GNUTAR{} now takes some distance from elegance, and
3709 cowardly refuses to create an archive when @option{--create} option is
3710 given, there are no arguments besides options, and
3711 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3712 around the cautiousness of @GNUTAR{} and nevertheless create an
3713 archive with nothing in it, one may still use, as the value for the
3714 @option{--files-from} option, a file with no names in it, as shown in
3715 the following commands:
3718 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3719 @kbd{tar cfT empty-archive.tar /dev/null}
3722 @xopindex{extract, complementary notes}
3727 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3729 @item @option{--list} (@option{-t})
3731 @GNUTAR{} now shows dates as @samp{1996-08-30},
3732 while it used to show them as @samp{Aug 30 1996}. Preferably,
3733 people should get used to ISO 8601 dates. Local American dates should
3734 be made available again with full date localization support, once
3735 ready. In the meantime, programs not being localizable for dates
3736 should prefer international dates, that's really the way to go.
3738 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
3739 are curious, it contains a detailed explanation of the ISO 8601 standard.
3744 @section Advanced @GNUTAR{} Operations
3746 Now that you have learned the basics of using @GNUTAR{}, you may want
3747 to learn about further ways in which @command{tar} can help you.
3749 This chapter presents five, more advanced operations which you probably
3750 won't use on a daily basis, but which serve more specialized functions.
3751 We also explain the different styles of options and why you might want
3752 to use one or another, or a combination of them in your @command{tar}
3753 commands. Additionally, this chapter includes options which allow you to
3754 define the output from @command{tar} more carefully, and provide help and
3755 error correction in special circumstances.
3757 @FIXME{check this after the chapter is actually revised to make sure
3758 it still introduces the info in the chapter correctly : ).}
3770 @subsection The Five Advanced @command{tar} Operations
3773 In the last chapter, you learned about the first three operations to
3774 @command{tar}. This chapter presents the remaining five operations to
3775 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3776 @option{--delete}, and @option{--compare}.
3778 You are not likely to use these operations as frequently as those
3779 covered in the last chapter; however, since they perform specialized
3780 functions, they are quite useful when you do need to use them. We
3781 will give examples using the same directory and files that you created
3782 in the last chapter. As you may recall, the directory is called
3783 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3784 @samp{rock}, and the two archive files you created are
3785 @samp{collection.tar} and @samp{music.tar}.
3787 We will also use the archive files @samp{afiles.tar} and
3788 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
3789 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
3790 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3792 Unless we state otherwise, all practicing you do and examples you follow
3793 in this chapter will take place in the @file{practice} directory that
3794 you created in the previous chapter; see @ref{prepare for examples}.
3795 (Below in this section, we will remind you of the state of the examples
3796 where the last chapter left them.)
3798 The five operations that we will cover in this chapter are:
3803 Add new entries to an archive that already exists.
3806 Add more recent copies of archive members to the end of an archive, if
3811 Add one or more pre-existing archives to the end of another archive.
3813 Delete items from an archive (does not work on tapes).
3817 Compare archive members to their counterparts in the file system.
3821 @subsection How to Add Files to Existing Archives: @option{--append}
3825 If you want to add files to an existing archive, you don't need to
3826 create a new archive; you can use @option{--append} (@option{-r}).
3827 The archive must already exist in order to use @option{--append}. (A
3828 related operation is the @option{--update} operation; you can use this
3829 to add newer versions of archive members to an existing archive. To learn how to
3830 do this with @option{--update}, @pxref{update}.)
3832 If you use @option{--append} to add a file that has the same name as an
3833 archive member to an archive containing that archive member, then the
3834 old member is not deleted. What does happen, however, is somewhat
3835 complex. @command{tar} @emph{allows} you to have infinite number of files
3836 with the same name. Some operations treat these same-named members no
3837 differently than any other set of archive members: for example, if you
3838 view an archive with @option{--list} (@option{-t}), you will see all
3839 of those members listed, with their data modification times, owners, etc.
3841 Other operations don't deal with these members as perfectly as you might
3842 prefer; if you were to use @option{--extract} to extract the archive,
3843 only the most recently added copy of a member with the same name as four
3844 other members would end up in the working directory. This is because
3845 @option{--extract} extracts an archive in the order the members appeared
3846 in the archive; the most recently archived members will be extracted
3847 last. Additionally, an extracted member will @emph{replace} a file of
3848 the same name which existed in the directory already, and @command{tar}
3849 will not prompt you about this@footnote{Unless you give it
3850 @option{--keep-old-files} option, or the disk copy is newer than the
3851 the one in the archive and you invoke @command{tar} with
3852 @option{--keep-newer-files} option}. Thus, only the most recently archived
3853 member will end up being extracted, as it will replace the one
3854 extracted before it, and so on.
3856 There exists a special option that allows you to get around this
3857 behavior and extract (or list) only a particular copy of the file.
3858 This is @option{--occurrence} option. If you run @command{tar} with
3859 this option, it will extract only the first copy of the file. You
3860 may also give this option an argument specifying the number of
3861 copy to be extracted. Thus, for example if the archive
3862 @file{archive.tar} contained three copies of file @file{myfile}, then
3866 tar --extract --file archive.tar --occurrence=2 myfile
3870 would extract only the second copy. @xref{Option
3871 Summary,---occurrence}, for the description of @option{--occurrence}
3874 @FIXME{ hag -- you might want to incorporate some of the above into the
3875 MMwtSN node; not sure. i didn't know how to make it simpler...
3877 There are a few ways to get around this. (maybe xref Multiple Members
3878 with the Same Name.}
3880 @cindex Members, replacing with other members
3881 @cindex Replacing members with other members
3882 If you want to replace an archive member, use @option{--delete} to
3883 delete the member you want to remove from the archive, , and then use
3884 @option{--append} to add the member you want to be in the archive. Note
3885 that you can not change the order of the archive; the most recently
3886 added member will still appear last. In this sense, you cannot truly
3887 ``replace'' one member with another. (Replacing one member with another
3888 will not work on certain types of media, such as tapes; see @ref{delete}
3889 and @ref{Media}, for more information.)
3892 * appending files:: Appending Files to an Archive
3896 @node appending files
3897 @subsubsection Appending Files to an Archive
3899 @cindex Adding files to an Archive
3900 @cindex Appending files to an Archive
3901 @cindex Archives, Appending files to
3903 The simplest way to add a file to an already existing archive is the
3904 @option{--append} (@option{-r}) operation, which writes specified
3905 files into the archive whether or not they are already among the
3908 When you use @option{--append}, you @emph{must} specify file name
3909 arguments, as there is no default. If you specify a file that already
3910 exists in the archive, another copy of the file will be added to the
3911 end of the archive. As with other operations, the member names of the
3912 newly added files will be exactly the same as their names given on the
3913 command line. The @option{--verbose} (@option{-v}) option will print
3914 out the names of the files as they are written into the archive.
3916 @option{--append} cannot be performed on some tape drives, unfortunately,
3917 due to deficiencies in the formats those tape drives use. The archive
3918 must be a valid @command{tar} archive, or else the results of using this
3919 operation will be unpredictable. @xref{Media}.
3921 To demonstrate using @option{--append} to add a file to an archive,
3922 create a file called @file{rock} in the @file{practice} directory.
3923 Make sure you are in the @file{practice} directory. Then, run the
3924 following @command{tar} command to add @file{rock} to
3925 @file{collection.tar}:
3928 $ @kbd{tar --append --file=collection.tar rock}
3932 If you now use the @option{--list} (@option{-t}) operation, you will see that
3933 @file{rock} has been added to the archive:
3936 $ @kbd{tar --list --file=collection.tar}
3937 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3938 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3939 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3940 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3944 @subsubsection Multiple Members with the Same Name
3946 You can use @option{--append} (@option{-r}) to add copies of files
3947 which have been updated since the archive was created. (However, we
3948 do not recommend doing this since there is another @command{tar}
3949 option called @option{--update}; @xref{update}, for more information.
3950 We describe this use of @option{--append} here for the sake of
3951 completeness.) When you extract the archive, the older version will
3952 be effectively lost. This works because files are extracted from an
3953 archive in the order in which they were archived. Thus, when the
3954 archive is extracted, a file archived later in time will replace a
3955 file of the same name which was archived earlier, even though the
3956 older version of the file will remain in the archive unless you delete
3957 all versions of the file.
3959 Supposing you change the file @file{blues} and then append the changed
3960 version to @file{collection.tar}. As you saw above, the original
3961 @file{blues} is in the archive @file{collection.tar}. If you change the
3962 file and append the new version of the file to the archive, there will
3963 be two copies in the archive. When you extract the archive, the older
3964 version of the file will be extracted first, and then replaced by the
3965 newer version when it is extracted.
3967 You can append the new, changed copy of the file @file{blues} to the
3968 archive in this way:
3971 $ @kbd{tar --append --verbose --file=collection.tar blues}
3976 Because you specified the @option{--verbose} option, @command{tar} has
3977 printed the name of the file being appended as it was acted on. Now
3978 list the contents of the archive:
3981 $ @kbd{tar --list --verbose --file=collection.tar}
3982 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3983 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3984 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3985 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3986 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3990 The newest version of @file{blues} is now at the end of the archive
3991 (note the different creation dates and file sizes). If you extract
3992 the archive, the older version of the file @file{blues} will be
3993 replaced by the newer version. You can confirm this by extracting
3994 the archive and running @samp{ls} on the directory.
3996 If you wish to extract the first occurrence of the file @file{blues}
3997 from the archive, use @option{--occurrence} option, as shown in
3998 the following example:
4001 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4002 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4005 @xref{Writing}, for more information on @option{--extract} and
4006 @xref{Option Summary, --occurrence}, for the description of
4007 @option{--occurrence} option.
4010 @subsection Updating an Archive
4012 @cindex Updating an archive
4015 In the previous section, you learned how to use @option{--append} to
4016 add a file to an existing archive. A related operation is
4017 @option{--update} (@option{-u}). The @option{--update} operation
4018 updates a @command{tar} archive by comparing the date of the specified
4019 archive members against the date of the file with the same name. If
4020 the file has been modified more recently than the archive member, then
4021 the newer version of the file is added to the archive (as with
4024 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4025 The operation will fail.
4027 @FIXME{other examples of media on which --update will fail? need to ask
4028 charles and/or mib/thomas/dave shevett..}
4030 Both @option{--update} and @option{--append} work by adding to the end
4031 of the archive. When you extract a file from the archive, only the
4032 version stored last will wind up in the file system, unless you use
4033 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4040 @subsubsection How to Update an Archive Using @option{--update}
4042 You must use file name arguments with the @option{--update}
4043 (@option{-u}) operation. If you don't specify any files,
4044 @command{tar} won't act on any files and won't tell you that it didn't
4045 do anything (which may end up confusing you).
4047 @c note: the above parenthetical added because in fact, this
4048 @c behavior just confused the author. :-)
4050 To see the @option{--update} option at work, create a new file,
4051 @file{classical}, in your practice directory, and some extra text to the
4052 file @file{blues}, using any text editor. Then invoke @command{tar} with
4053 the @samp{update} operation and the @option{--verbose} (@option{-v})
4054 option specified, using the names of all the files in the practice
4055 directory as file name arguments:
4058 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4065 Because we have specified verbose mode, @command{tar} prints out the names
4066 of the files it is working on, which in this case are the names of the
4067 files that needed to be updated. If you run @samp{tar --list} and look
4068 at the archive, you will see @file{blues} and @file{classical} at its
4069 end. There will be a total of two versions of the member @samp{blues};
4070 the one at the end will be newer and larger, since you added text before
4073 (The reason @command{tar} does not overwrite the older file when updating
4074 it is because writing to the middle of a section of tape is a difficult
4075 process. Tapes are not designed to go backward. @xref{Media}, for more
4076 information about tapes.
4078 @option{--update} (@option{-u}) is not suitable for performing backups for two
4079 reasons: it does not change directory content entries, and it
4080 lengthens the archive every time it is used. The @GNUTAR{}
4081 options intended specifically for backups are more
4082 efficient. If you need to run backups, please consult @ref{Backups}.
4085 @subsection Combining Archives with @option{--concatenate}
4087 @cindex Adding archives to an archive
4088 @cindex Concatenating Archives
4089 @opindex concatenate
4091 @c @cindex @option{-A} described
4092 Sometimes it may be convenient to add a second archive onto the end of
4093 an archive rather than adding individual files to the archive. To add
4094 one or more archives to the end of another archive, you should use the
4095 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4097 To use @option{--concatenate}, give the first archive with
4098 @option{--file} option and name the rest of archives to be
4099 concatenated on the command line. The members, and their member
4100 names, will be copied verbatim from those archives to the first one.
4101 @footnote{This can cause multiple members to have the same name, for
4102 information on how this affects reading the archive, @ref{multiple}.}
4103 The new, concatenated archive will be called by the same name as the
4104 one given with the @option{--file} option. As usual, if you omit
4105 @option{--file}, @command{tar} will use the value of the environment
4106 variable @env{TAPE}, or, if this has not been set, the default archive name.
4108 @FIXME{There is no way to specify a new name...}
4110 To demonstrate how @option{--concatenate} works, create two small archives
4111 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4112 files from @file{practice}:
4115 $ @kbd{tar -cvf bluesrock.tar blues rock}
4118 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4124 If you like, You can run @samp{tar --list} to make sure the archives
4125 contain what they are supposed to:
4128 $ @kbd{tar -tvf bluesrock.tar}
4129 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4130 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4131 $ @kbd{tar -tvf jazzfolk.tar}
4132 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4133 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4136 We can concatenate these two archives with @command{tar}:
4140 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4143 If you now list the contents of the @file{bluesrock.tar}, you will see
4144 that now it also contains the archive members of @file{jazzfolk.tar}:
4147 $ @kbd{tar --list --file=bluesrock.tar}
4154 When you use @option{--concatenate}, the source and target archives must
4155 already exist and must have been created using compatible format
4156 parameters. Notice, that @command{tar} does not check whether the
4157 archives it concatenates have compatible formats, it does not
4158 even check if the files are really tar archives.
4160 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4161 tape drives, due to deficiencies in the formats those tape drives use.
4163 @cindex @code{concatenate} vs @command{cat}
4164 @cindex @command{cat} vs @code{concatenate}
4165 It may seem more intuitive to you to want or try to use @command{cat} to
4166 concatenate two archives instead of using the @option{--concatenate}
4167 operation; after all, @command{cat} is the utility for combining files.
4169 However, @command{tar} archives incorporate an end-of-file marker which
4170 must be removed if the concatenated archives are to be read properly as
4171 one archive. @option{--concatenate} removes the end-of-archive marker
4172 from the target archive before each new archive is appended. If you use
4173 @command{cat} to combine the archives, the result will not be a valid
4174 @command{tar} format archive. If you need to retrieve files from an
4175 archive that was added to using the @command{cat} utility, use the
4176 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4177 information on dealing with archives improperly combined using the
4178 @command{cat} shell utility.
4181 @subsection Removing Archive Members Using @option{--delete}
4183 @cindex Deleting files from an archive
4184 @cindex Removing files from an archive
4187 You can remove members from an archive by using the @option{--delete}
4188 option. Specify the name of the archive with @option{--file}
4189 (@option{-f}) and then specify the names of the members to be deleted;
4190 if you list no member names, nothing will be deleted. The
4191 @option{--verbose} option will cause @command{tar} to print the names
4192 of the members as they are deleted. As with @option{--extract}, you
4193 must give the exact member names when using @samp{tar --delete}.
4194 @option{--delete} will remove all versions of the named file from the
4195 archive. The @option{--delete} operation can run very slowly.
4197 Unlike other operations, @option{--delete} has no short form.
4199 @cindex Tapes, using @option{--delete} and
4200 @cindex Deleting from tape archives
4201 This operation will rewrite the archive. You can only use
4202 @option{--delete} on an archive if the archive device allows you to
4203 write to any point on the media, such as a disk; because of this, it
4204 does not work on magnetic tapes. Do not try to delete an archive member
4205 from a magnetic tape; the action will not succeed, and you will be
4206 likely to scramble the archive and damage your tape. There is no safe
4207 way (except by completely re-writing the archive) to delete files from
4208 most kinds of magnetic tape. @xref{Media}.
4210 To delete all versions of the file @file{blues} from the archive
4211 @file{collection.tar} in the @file{practice} directory, make sure you
4212 are in that directory, and then,
4215 $ @kbd{tar --list --file=collection.tar}
4220 $ @kbd{tar --delete --file=collection.tar blues}
4221 $ @kbd{tar --list --file=collection.tar}
4228 @FIXME{Check if the above listing is actually produced after running
4229 all the examples on collection.tar.}
4231 The @option{--delete} option has been reported to work properly when
4232 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4235 @subsection Comparing Archive Members with the File System
4236 @cindex Verifying the currency of an archive
4240 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4241 specified archive members against files with the same names, and then
4242 reports differences in file size, mode, owner, modification date and
4243 contents. You should @emph{only} specify archive member names, not file
4244 names. If you do not name any members, then @command{tar} will compare the
4245 entire archive. If a file is represented in the archive but does not
4246 exist in the file system, @command{tar} reports a difference.
4248 You have to specify the record size of the archive when modifying an
4249 archive with a non-default record size.
4251 @command{tar} ignores files in the file system that do not have
4252 corresponding members in the archive.
4254 The following example compares the archive members @file{rock},
4255 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4256 files of the same name in the file system. (Note that there is no file,
4257 @file{funk}; @command{tar} will report an error message.)
4260 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4263 tar: funk not found in archive
4266 The spirit behind the @option{--compare} (@option{--diff},
4267 @option{-d}) option is to check whether the archive represents the
4268 current state of files on disk, more than validating the integrity of
4269 the archive media. For this later goal, @xref{verify}.
4271 @node create options
4272 @section Options Used by @option{--create}
4274 @xopindex{create, additional options}
4275 The previous chapter described the basics of how to use
4276 @option{--create} (@option{-c}) to create an archive from a set of files.
4277 @xref{create}. This section described advanced options to be used with
4281 * override:: Overriding File Metadata.
4282 * Ignore Failed Read::
4286 @subsection Overriding File Metadata
4288 As described above, a @command{tar} archive keeps, for each member it contains,
4289 its @dfn{metadata}, such as modification time, mode and ownership of
4290 the file. @GNUTAR{} allows to replace these data with other values
4291 when adding files to the archive. The options described in this
4292 section affect creation of archives of any type. For POSIX archives,
4293 see also @ref{PAX keywords}, for additional ways of controlling
4294 metadata, stored in the archive.
4298 @item --mode=@var{permissions}
4300 When adding files to an archive, @command{tar} will use
4301 @var{permissions} for the archive members, rather than the permissions
4302 from the files. @var{permissions} can be specified either as an octal
4303 number or as symbolic permissions, like with
4304 @command{chmod} (@xref{File permissions, Permissions, File
4305 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4306 also has useful information for those not being overly familiar with
4307 the UNIX permission system). Using latter syntax allows for
4308 more flexibility. For example, the value @samp{a+rw} adds read and write
4309 permissions for everybody, while retaining executable bits on directories
4310 or on any other file already marked as executable:
4313 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4316 @item --mtime=@var{date}
4319 When adding files to an archive, @command{tar} will use @var{date} as
4320 the modification time of members when creating archives, instead of
4321 their actual modification times. The argument @var{date} can be
4322 either a textual date representation in almost arbitrary format
4323 (@pxref{Date input formats}) or a name of the existing file, starting
4324 with @samp{/} or @samp{.}. In the latter case, the modification time
4325 of that file will be used.
4327 The following example will set the modification date to 00:00:00 UTC,
4331 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4335 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4336 will try to convert the specified date back to its textual
4337 representation and compare it with the one given with
4338 @option{--mtime} options. If the two dates differ, @command{tar} will
4339 print a warning saying what date it will use. This is to help user
4340 ensure he is using the right date.
4345 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4346 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4351 @item --owner=@var{user}
4354 Specifies that @command{tar} should use @var{user} as the owner of members
4355 when creating archives, instead of the user associated with the source
4356 file. The argument @var{user} can be either an existing user symbolic
4357 name, or a decimal numeric user ID.
4359 There is no value indicating a missing number, and @samp{0} usually means
4360 @code{root}. Some people like to force @samp{0} as the value to offer in
4361 their distributions for the owner of files, because the @code{root} user is
4362 anonymous anyway, so that might as well be the owner of anonymous
4363 archives. For example:
4367 $ @kbd{tar -c -f archive.tar --owner=0 .}
4369 $ @kbd{tar -c -f archive.tar --owner=root .}
4373 @item --group=@var{group}
4376 Files added to the @command{tar} archive will have a group id of @var{group},
4377 rather than the group from the source file. The argument @var{group}
4378 can be either an existing group symbolic name, or a decimal numeric group ID.
4381 @node Ignore Failed Read
4382 @subsection Ignore Fail Read
4385 @item --ignore-failed-read
4386 @opindex ignore-failed-read
4387 Do not exit with nonzero on unreadable files or directories.
4390 @node extract options
4391 @section Options Used by @option{--extract}
4394 @xopindex{extract, additional options}
4395 The previous chapter showed how to use @option{--extract} to extract
4396 an archive into the file system. Various options cause @command{tar} to
4397 extract more information than just file contents, such as the owner,
4398 the permissions, the modification date, and so forth. This section
4399 presents options to be used with @option{--extract} when certain special
4400 considerations arise. You may review the information presented in
4401 @ref{extract} for more basic information about the
4402 @option{--extract} operation.
4405 * Reading:: Options to Help Read Archives
4406 * Writing:: Changing How @command{tar} Writes Files
4407 * Scarce:: Coping with Scarce Resources
4411 @subsection Options to Help Read Archives
4412 @cindex Options when reading archives
4415 @cindex Reading incomplete records
4416 @cindex Records, incomplete
4417 @opindex read-full-records
4418 Normally, @command{tar} will request data in full record increments from
4419 an archive storage device. If the device cannot return a full record,
4420 @command{tar} will report an error. However, some devices do not always
4421 return full records, or do not require the last record of an archive to
4422 be padded out to the next record boundary. To keep reading until you
4423 obtain a full record, or to accept an incomplete record if it contains
4424 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4425 in conjunction with the @option{--extract} or @option{--list} operations.
4428 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4429 @command{tar} reads an archive from standard input, or from a remote
4430 machine. This is because on BSD Unix systems, attempting to read a
4431 pipe returns however much happens to be in the pipe, even if it is
4432 less than was requested. If this option were not enabled, @command{tar}
4433 would fail as soon as it read an incomplete record from the pipe.
4435 If you're not sure of the blocking factor of an archive, you can
4436 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4437 @option{--blocking-factor=@var{512-size}} (@option{-b
4438 @var{512-size}}), using a blocking factor larger than what the archive
4439 uses. This lets you avoid having to determine the blocking factor
4440 of an archive. @xref{Blocking Factor}.
4443 * read full records::
4447 @node read full records
4448 @unnumberedsubsubsec Reading Full Records
4450 @FIXME{need sentence or so of intro here}
4453 @opindex read-full-records
4454 @item --read-full-records
4456 Use in conjunction with @option{--extract} (@option{--get},
4457 @option{-x}) to read an archive which contains incomplete records, or
4458 one which has a blocking factor less than the one specified.
4462 @unnumberedsubsubsec Ignoring Blocks of Zeros
4464 @cindex End-of-archive blocks, ignoring
4465 @cindex Ignoring end-of-archive blocks
4466 @opindex ignore-zeros
4467 Normally, @command{tar} stops reading when it encounters a block of zeros
4468 between file entries (which usually indicates the end of the archive).
4469 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4470 completely read an archive which contains a block of zeros before the
4471 end (i.e., a damaged archive, or one that was created by concatenating
4472 several archives together).
4474 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4475 versions of @command{tar} write garbage after the end-of-archive entry,
4476 since that part of the media is never supposed to be read. @GNUTAR{}
4477 does not write after the end of an archive, but seeks to
4478 maintain compatibility among archiving utilities.
4481 @item --ignore-zeros
4483 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4484 encountered while reading an archive. Use in conjunction with
4485 @option{--extract} or @option{--list}.
4489 @subsection Changing How @command{tar} Writes Files
4492 @FIXME{Introductory paragraph}
4495 * Dealing with Old Files::
4496 * Overwrite Old Files::
4498 * Keep Newer Files::
4500 * Recursive Unlink::
4501 * Data Modification Times::
4502 * Setting Access Permissions::
4503 * Directory Modification Times and Permissions::
4504 * Writing to Standard Output::
4505 * Writing to an External Program::
4509 @node Dealing with Old Files
4510 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4512 @xopindex{overwrite-dir, introduced}
4513 When extracting files, if @command{tar} discovers that the extracted
4514 file already exists, it normally replaces the file by removing it before
4515 extracting it, to prevent confusion in the presence of hard or symbolic
4516 links. (If the existing file is a symbolic link, it is removed, not
4517 followed.) However, if a directory cannot be removed because it is
4518 nonempty, @command{tar} normally overwrites its metadata (ownership,
4519 permission, etc.). The @option{--overwrite-dir} option enables this
4520 default behavior. To be more cautious and preserve the metadata of
4521 such a directory, use the @option{--no-overwrite-dir} option.
4523 @cindex Overwriting old files, prevention
4524 @xopindex{keep-old-files, introduced}
4525 To be even more cautious and prevent existing files from being replaced, use
4526 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4527 to replace or update a file that already exists, i.e., a file with the
4528 same name as an archive member prevents extraction of that archive
4529 member. Instead, it reports an error.
4531 @xopindex{overwrite, introduced}
4532 To be more aggressive about altering existing files, use the
4533 @option{--overwrite} option. It causes @command{tar} to overwrite
4534 existing files and to follow existing symbolic links when extracting.
4536 @cindex Protecting old files
4537 Some people argue that @GNUTAR{} should not hesitate
4538 to overwrite files with other files when extracting. When extracting
4539 a @command{tar} archive, they expect to see a faithful copy of the
4540 state of the file system when the archive was created. It is debatable
4541 that this would always be a proper behavior. For example, suppose one
4542 has an archive in which @file{usr/local} is a link to
4543 @file{usr/local2}. Since then, maybe the site removed the link and
4544 renamed the whole hierarchy from @file{/usr/local2} to
4545 @file{/usr/local}. Such things happen all the time. I guess it would
4546 not be welcome at all that @GNUTAR{} removes the
4547 whole hierarchy just to make room for the link to be reinstated
4548 (unless it @emph{also} simultaneously restores the full
4549 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4550 able to remove a whole hierarchy to reestablish a symbolic link, for
4551 example, but @emph{only if} @option{--recursive-unlink} is specified
4552 to allow this behavior. In any case, single files are silently
4555 @xopindex{unlink-first, introduced}
4556 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4557 some cases by causing @command{tar} to remove files unconditionally
4558 before extracting them.
4560 @node Overwrite Old Files
4561 @unnumberedsubsubsec Overwrite Old Files
4566 Overwrite existing files and directory metadata when extracting files
4569 This causes @command{tar} to write extracted files into the file system without
4570 regard to the files already on the system; i.e., files with the same
4571 names as archive members are overwritten when the archive is extracted.
4572 It also causes @command{tar} to extract the ownership, permissions,
4573 and time stamps onto any preexisting files or directories.
4574 If the name of a corresponding file name is a symbolic link, the file
4575 pointed to by the symbolic link will be overwritten instead of the
4576 symbolic link itself (if this is possible). Moreover, special devices,
4577 empty directories and even symbolic links are automatically removed if
4578 they are in the way of extraction.
4580 Be careful when using the @option{--overwrite} option, particularly when
4581 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4582 can change the contents, ownership or permissions of any file on your
4583 system. Also, many systems do not take kindly to overwriting files that
4584 are currently being executed.
4586 @opindex overwrite-dir
4587 @item --overwrite-dir
4588 Overwrite the metadata of directories when extracting files from an
4589 archive, but remove other files before extracting.
4592 @node Keep Old Files
4593 @unnumberedsubsubsec Keep Old Files
4596 @opindex keep-old-files
4597 @item --keep-old-files
4599 Do not replace existing files from archive. The
4600 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4601 from replacing existing files with files with the same name from the
4602 archive. The @option{--keep-old-files} option is meaningless with
4603 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4604 files in the file system during extraction.
4607 @node Keep Newer Files
4608 @unnumberedsubsubsec Keep Newer Files
4611 @opindex keep-newer-files
4612 @item --keep-newer-files
4613 Do not replace existing files that are newer than their archive
4614 copies. This option is meaningless with @option{--list} (@option{-t}).
4618 @unnumberedsubsubsec Unlink First
4621 @opindex unlink-first
4622 @item --unlink-first
4624 Remove files before extracting over them.
4625 This can make @command{tar} run a bit faster if you know in advance
4626 that the extracted files all need to be removed. Normally this option
4627 slows @command{tar} down slightly, so it is disabled by default.
4630 @node Recursive Unlink
4631 @unnumberedsubsubsec Recursive Unlink
4634 @opindex recursive-unlink
4635 @item --recursive-unlink
4636 When this option is specified, try removing files and directory hierarchies
4637 before extracting over them. @emph{This is a dangerous option!}
4640 If you specify the @option{--recursive-unlink} option,
4641 @command{tar} removes @emph{anything} that keeps you from extracting a file
4642 as far as current permissions will allow it. This could include removal
4643 of the contents of a full directory hierarchy.
4645 @node Data Modification Times
4646 @unnumberedsubsubsec Setting Data Modification Times
4648 @cindex Data modification times of extracted files
4649 @cindex Modification times of extracted files
4650 Normally, @command{tar} sets the data modification times of extracted
4651 files to the corresponding times recorded for the files in the archive, but
4652 limits the permissions of extracted files by the current @code{umask}
4655 To set the data modification times of extracted files to the time when
4656 the files were extracted, use the @option{--touch} (@option{-m}) option in
4657 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4663 Sets the data modification time of extracted archive members to the time
4664 they were extracted, not the time recorded for them in the archive.
4665 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4668 @node Setting Access Permissions
4669 @unnumberedsubsubsec Setting Access Permissions
4671 @cindex Permissions of extracted files
4672 @cindex Modes of extracted files
4673 To set the modes (access permissions) of extracted files to those
4674 recorded for those files in the archive, use @option{--same-permissions}
4675 in conjunction with the @option{--extract} (@option{--get},
4676 @option{-x}) operation.
4679 @opindex preserve-permissions
4680 @opindex same-permissions
4681 @item --preserve-permissions
4682 @itemx --same-permissions
4683 @c @itemx --ignore-umask
4685 Set modes of extracted archive members to those recorded in the
4686 archive, instead of current umask settings. Use in conjunction with
4687 @option{--extract} (@option{--get}, @option{-x}).
4690 @node Directory Modification Times and Permissions
4691 @unnumberedsubsubsec Directory Modification Times and Permissions
4693 After successfully extracting a file member, @GNUTAR{} normally
4694 restores its permissions and modification times, as described in the
4695 previous sections. This cannot be done for directories, because
4696 after extracting a directory @command{tar} will almost certainly
4697 extract files into that directory and this will cause the directory
4698 modification time to be updated. Moreover, restoring that directory
4699 permissions may not permit file creation within it. Thus, restoring
4700 directory permissions and modification times must be delayed at least
4701 until all files have been extracted into that directory. @GNUTAR{}
4702 restores directories using the following approach.
4704 The extracted directories are created with the mode specified in the
4705 archive, as modified by the umask of the user, which gives sufficient
4706 permissions to allow file creation. The meta-information about the
4707 directory is recorded in the temporary list of directories. When
4708 preparing to extract next archive member, @GNUTAR{} checks if the
4709 directory prefix of this file contains the remembered directory. If
4710 it does not, the program assumes that all files have been extracted
4711 into that directory, restores its modification time and permissions
4712 and removes its entry from the internal list. This approach allows
4713 to correctly restore directory meta-information in the majority of
4714 cases, while keeping memory requirements sufficiently small. It is
4715 based on the fact, that most @command{tar} archives use the predefined
4716 order of members: first the directory, then all the files and
4717 subdirectories in that directory.
4719 However, this is not always true. The most important exception are
4720 incremental archives (@pxref{Incremental Dumps}). The member order in
4721 an incremental archive is reversed: first all directory members are
4722 stored, followed by other (non-directory) members. So, when extracting
4723 from incremental archives, @GNUTAR{} alters the above procedure. It
4724 remembers all restored directories, and restores their meta-data
4725 only after the entire archive has been processed. Notice, that you do
4726 not need to specify any special options for that, as @GNUTAR{}
4727 automatically detects archives in incremental format.
4729 There may be cases, when such processing is required for normal archives
4730 too. Consider the following example:
4734 $ @kbd{tar --no-recursion -cvf archive \
4735 foo foo/file1 bar bar/file foo/file2}
4744 During the normal operation, after encountering @file{bar}
4745 @GNUTAR{} will assume that all files from the directory @file{foo}
4746 were already extracted and will therefore restore its timestamp and
4747 permission bits. However, after extracting @file{foo/file2} the
4748 directory timestamp will be offset again.
4750 To correctly restore directory meta-information in such cases, use
4751 @option{delay-directory-restore} command line option:
4754 @opindex delay-directory-restore
4755 @item --delay-directory-restore
4756 Delays restoring of the modification times and permissions of extracted
4757 directories until the end of extraction. This way, correct
4758 meta-information is restored even if the archive has unusual member
4761 @opindex no-delay-directory-restore
4762 @item --no-delay-directory-restore
4763 Cancel the effect of the previous @option{--delay-directory-restore}.
4764 Use this option if you have used @option{--delay-directory-restore} in
4765 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4766 temporarily disable it.
4769 @node Writing to Standard Output
4770 @unnumberedsubsubsec Writing to Standard Output
4772 @cindex Writing extracted files to standard output
4773 @cindex Standard output, writing extracted files to
4774 To write the extracted files to the standard output, instead of
4775 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4776 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4777 extracting files to send them through a pipe, and do not need to
4778 preserve them in the file system. If you extract multiple members,
4779 they appear on standard output concatenated, in the order they are
4780 found in the archive.
4786 Writes files to the standard output. Use only in conjunction with
4787 @option{--extract} (@option{--get}, @option{-x}). When this option is
4788 used, instead of creating the files specified, @command{tar} writes
4789 the contents of the files extracted to its standard output. This may
4790 be useful if you are only extracting the files in order to send them
4791 through a pipe. This option is meaningless with @option{--list}
4795 This can be useful, for example, if you have a tar archive containing
4796 a big file and don't want to store the file on disk before processing
4797 it. You can use a command like this:
4800 tar -xOzf foo.tgz bigfile | process
4803 or even like this if you want to process the concatenation of the files:
4806 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4809 However, @option{--to-command} may be more convenient for use with
4810 multiple files. See the next section.
4812 @node Writing to an External Program
4813 @unnumberedsubsubsec Writing to an External Program
4815 You can instruct @command{tar} to send the contents of each extracted
4816 file to the standard input of an external program:
4820 @item --to-command=@var{command}
4821 Extract files and pipe their contents to the standard input of
4822 @var{command}. When this option is used, instead of creating the
4823 files specified, @command{tar} invokes @var{command} and pipes the
4824 contents of the files to its standard output. @var{Command} may
4825 contain command line arguments. The program is executed via
4826 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4827 extracted. Non-regular files (directories, etc.) are ignored when this
4831 The command can obtain the information about the file it processes
4832 from the following environment variables:
4835 @vrindex TAR_FILETYPE, to-command environment
4837 Type of the file. It is a single letter with the following meaning:
4839 @multitable @columnfractions 0.10 0.90
4840 @item f @tab Regular file
4841 @item d @tab Directory
4842 @item l @tab Symbolic link
4843 @item h @tab Hard link
4844 @item b @tab Block device
4845 @item c @tab Character device
4848 Currently only regular files are supported.
4850 @vrindex TAR_MODE, to-command environment
4852 File mode, an octal number.
4854 @vrindex TAR_FILENAME, to-command environment
4856 The name of the file.
4858 @vrindex TAR_REALNAME, to-command environment
4860 Name of the file as stored in the archive.
4862 @vrindex TAR_UNAME, to-command environment
4864 Name of the file owner.
4866 @vrindex TAR_GNAME, to-command environment
4868 Name of the file owner group.
4870 @vrindex TAR_ATIME, to-command environment
4872 Time of last access. It is a decimal number, representing seconds
4873 since the epoch. If the archive provides times with nanosecond
4874 precision, the nanoseconds are appended to the timestamp after a
4877 @vrindex TAR_MTIME, to-command environment
4879 Time of last modification.
4881 @vrindex TAR_CTIME, to-command environment
4883 Time of last status change.
4885 @vrindex TAR_SIZE, to-command environment
4889 @vrindex TAR_UID, to-command environment
4891 UID of the file owner.
4893 @vrindex TAR_GID, to-command environment
4895 GID of the file owner.
4898 In addition to these variables, @env{TAR_VERSION} contains the
4899 @GNUTAR{} version number.
4901 If @var{command} exits with a non-0 status, @command{tar} will print
4902 an error message similar to the following:
4905 tar: 2345: Child returned status 1
4908 Here, @samp{2345} is the PID of the finished process.
4910 If this behavior is not wanted, use @option{--ignore-command-error}:
4913 @opindex ignore-command-error
4914 @item --ignore-command-error
4915 Ignore exit codes of subprocesses. Notice that if the program
4916 exits on signal or otherwise terminates abnormally, the error message
4917 will be printed even if this option is used.
4919 @opindex no-ignore-command-error
4920 @item --no-ignore-command-error
4921 Cancel the effect of any previous @option{--ignore-command-error}
4922 option. This option is useful if you have set
4923 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4924 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4928 @unnumberedsubsubsec Removing Files
4930 @FIXME{The section is too terse. Something more to add? An example,
4934 @opindex remove-files
4935 @item --remove-files
4936 Remove files after adding them to the archive.
4940 @subsection Coping with Scarce Resources
4943 @cindex Small memory
4944 @cindex Running out of space
4952 @unnumberedsubsubsec Starting File
4955 @opindex starting-file
4956 @item --starting-file=@var{name}
4957 @itemx -K @var{name}
4958 Starts an operation in the middle of an archive. Use in conjunction
4959 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4962 @cindex Middle of the archive, starting in the
4963 If a previous attempt to extract files failed due to lack of disk
4964 space, you can use @option{--starting-file=@var{name}} (@option{-K
4965 @var{name}}) to start extracting only after member @var{name} of the
4966 archive. This assumes, of course, that there is now free space, or
4967 that you are now extracting into a different file system. (You could
4968 also choose to suspend @command{tar}, remove unnecessary files from
4969 the file system, and then restart the same @command{tar} operation.
4970 In this case, @option{--starting-file} is not necessary.
4971 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4974 @unnumberedsubsubsec Same Order
4977 @cindex Large lists of file names on small machines
4979 @opindex preserve-order
4981 @itemx --preserve-order
4983 To process large lists of file names on machines with small amounts of
4984 memory. Use in conjunction with @option{--compare} (@option{--diff},
4985 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4986 (@option{--get}, @option{-x}).
4989 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4990 names to be listed or extracted is sorted in the same order as the
4991 files in the archive. This allows a large list of names to be used,
4992 even on a small machine that would not otherwise be able to hold all
4993 the names in memory at the same time. Such a sorted list can easily be
4994 created by running @samp{tar -t} on the archive and editing its output.
4996 This option is probably never needed on modern computer systems.
4999 @section Backup options
5001 @cindex backup options
5003 @GNUTAR{} offers options for making backups of files
5004 before writing new versions. These options control the details of
5005 these backups. They may apply to the archive itself before it is
5006 created or rewritten, as well as individual extracted members. Other
5007 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5008 and @command{mv}, for example) offer similar options.
5010 Backup options may prove unexpectedly useful when extracting archives
5011 containing many members having identical name, or when extracting archives
5012 on systems having file name limitations, making different members appear
5013 has having similar names through the side-effect of name truncation.
5014 (This is true only if we have a good scheme for truncated backup names,
5015 which I'm not sure at all: I suspect work is needed in this area.)
5016 When any existing file is backed up before being overwritten by extraction,
5017 then clashing files are automatically be renamed to be unique, and the
5018 true name is kept for only the last file of a series of clashing files.
5019 By using verbose mode, users may track exactly what happens.
5021 At the detail level, some decisions are still experimental, and may
5022 change in the future, we are waiting comments from our users. So, please
5023 do not learn to depend blindly on the details of the backup features.
5024 For example, currently, directories themselves are never renamed through
5025 using these options, so, extracting a file over a directory still has
5026 good chances to fail. Also, backup options apply to created archives,
5027 not only to extracted members. For created archives, backups will not
5028 be attempted when the archive is a block or character device, or when it
5029 refers to a remote file.
5031 For the sake of simplicity and efficiency, backups are made by renaming old
5032 files prior to creation or extraction, and not by copying. The original
5033 name is restored if the file creation fails. If a failure occurs after a
5034 partial extraction of a file, both the backup and the partially extracted
5038 @item --backup[=@var{method}]
5040 @vindex VERSION_CONTROL
5042 Back up files that are about to be overwritten or removed.
5043 Without this option, the original versions are destroyed.
5045 Use @var{method} to determine the type of backups made.
5046 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5047 environment variable. And if @env{VERSION_CONTROL} is not set,
5048 use the @samp{existing} method.
5050 @vindex version-control @r{Emacs variable}
5051 This option corresponds to the Emacs variable @samp{version-control};
5052 the same values for @var{method} are accepted as in Emacs. This option
5053 also allows more descriptive names. The valid @var{method}s are:
5058 @cindex numbered @r{backup method}
5059 Always make numbered backups.
5063 @cindex existing @r{backup method}
5064 Make numbered backups of files that already have them, simple backups
5069 @cindex simple @r{backup method}
5070 Always make simple backups.
5074 @item --suffix=@var{suffix}
5076 @cindex backup suffix
5077 @vindex SIMPLE_BACKUP_SUFFIX
5078 Append @var{suffix} to each backup file made with @option{--backup}. If this
5079 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5080 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5081 set, the default is @samp{~}, just as in Emacs.
5086 @section Notable @command{tar} Usages
5089 @FIXME{Using Unix file linking capability to recreate directory
5090 structures---linking files into one subdirectory and then
5091 @command{tar}ring that directory.}
5093 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5096 You can easily use archive files to transport a group of files from
5097 one system to another: put all relevant files into an archive on one
5098 computer system, transfer the archive to another system, and extract
5099 the contents there. The basic transfer medium might be magnetic tape,
5100 Internet FTP, or even electronic mail (though you must encode the
5101 archive with @command{uuencode} in order to transport it properly by
5102 mail). Both machines do not have to use the same operating system, as
5103 long as they both support the @command{tar} program.
5105 For example, here is how you might copy a directory's contents from
5106 one disk to another, while preserving the dates, modes, owners and
5107 link-structure of all the files therein. In this case, the transfer
5108 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5111 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5115 You can avoid subshells by using @option{-C} option:
5118 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5122 The command also works using short option forms:
5125 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5126 | (cd targetdir; tar --extract --file=-)}
5128 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5129 | tar --directory targetdir --extract --file=-}
5133 This is one of the easiest methods to transfer a @command{tar} archive.
5136 @section Looking Ahead: The Rest of this Manual
5138 You have now seen how to use all eight of the operations available to
5139 @command{tar}, and a number of the possible options. The next chapter
5140 explains how to choose and change file and archive names, how to use
5141 files to store names of other files which you can then call as
5142 arguments to @command{tar} (this can help you save time if you expect to
5143 archive the same list of files a number of times), and so forth.
5144 @FIXME{in case it's not obvious, i'm making this up in some sense
5145 based on my limited memory of what the next chapter *really* does. i
5146 just wanted to flesh out this final section a little bit so i'd
5147 remember to stick it in here. :-)}
5149 If there are too many files to conveniently list on the command line,
5150 you can list the names in a file, and @command{tar} will read that file.
5153 There are various ways of causing @command{tar} to skip over some files,
5154 and not archive them. @xref{Choosing}.
5157 @chapter Performing Backups and Restoring Files
5160 @GNUTAR{} is distributed along with the scripts
5161 which the Free Software Foundation uses for performing backups. There
5162 is no corresponding scripts available yet for doing restoration of
5163 files. Even if there is a good chance those scripts may be satisfying
5164 to you, they are not the only scripts or methods available for doing
5165 backups and restore. You may well create your own, or use more
5166 sophisticated packages dedicated to that purpose.
5168 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5169 Automatic Network Disk Archiver), a backup system developed by James
5170 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5171 This is free software, and it is available at these places:
5174 http://www.cs.umd.edu/projects/amanda/amanda.html
5175 ftp://ftp.cs.umd.edu/pub/amanda
5180 Here is a possible plan for a future documentation about the backuping
5181 scripts which are provided within the @GNUTAR{}
5187 @item what are dumps
5188 @item different levels of dumps
5190 @item full dump = dump everything
5191 @item level 1, level 2 dumps etc
5192 A level @var{n} dump dumps everything changed since the last level
5195 @item how to use scripts for dumps (ie, the concept)
5197 @item scripts to run after editing backup specs (details)
5199 @item Backup Specs, what is it.
5201 @item how to customize
5202 @item actual text of script [/sp/dump/backup-specs]
5206 @item rsh doesn't work
5207 @item rtape isn't installed
5210 @item the @option{--incremental} option of tar
5213 @item write protection
5214 @item types of media, different sizes and types, useful for different things
5215 @item files and tape marks
5216 one tape mark between files, two at end.
5217 @item positioning the tape
5218 MT writes two at end of write,
5219 backspaces over one when writing again.
5225 This chapter documents both the provided shell scripts and @command{tar}
5226 options which are more specific to usage as a backup tool.
5228 To @dfn{back up} a file system means to create archives that contain
5229 all the files in that file system. Those archives can then be used to
5230 restore any or all of those files (for instance if a disk crashes or a
5231 file is accidentally deleted). File system @dfn{backups} are also
5235 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5236 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5237 * Backup Levels:: Levels of Backups
5238 * Backup Parameters:: Setting Parameters for Backups and Restoration
5239 * Scripted Backups:: Using the Backup Scripts
5240 * Scripted Restoration:: Using the Restore Script
5244 @section Using @command{tar} to Perform Full Dumps
5250 @cindex corrupted archives
5251 Full dumps should only be made when no other people or programs
5252 are modifying files in the file system. If files are modified while
5253 @command{tar} is making the backup, they may not be stored properly in
5254 the archive, in which case you won't be able to restore them if you
5255 have to. (Files not being modified are written with no trouble, and do
5256 not corrupt the entire archive.)
5258 You will want to use the @option{--label=@var{archive-label}}
5259 (@option{-V @var{archive-label}}) option to give the archive a
5260 volume label, so you can tell what this archive is even if the label
5261 falls off the tape, or anything like that.
5263 Unless the file system you are dumping is guaranteed to fit on
5264 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5265 Make sure you have enough tapes on hand to complete the backup.
5267 If you want to dump each file system separately you will need to use
5268 the @option{--one-file-system} option to prevent
5269 @command{tar} from crossing file system boundaries when storing
5272 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5273 option is not needed, since this is a complete copy of everything in
5274 the file system, and a full restore from this backup would only be
5275 done onto a completely
5278 Unless you are in a hurry, and trust the @command{tar} program (and your
5279 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5280 option, to make sure your files really made it onto the dump properly.
5281 This will also detect cases where the file was modified while (or just
5282 after) it was being archived. Not all media (notably cartridge tapes)
5283 are capable of being verified, unfortunately.
5285 @node Incremental Dumps
5286 @section Using @command{tar} to Perform Incremental Dumps
5288 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5289 stores additional metadata so that exact state of the file system
5290 can be restored when extracting the archive.
5292 @GNUTAR{} currently offers two options for handling incremental
5293 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5294 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5296 @opindex listed-incremental
5297 The option @option{--listed-incremental} instructs tar to operate on
5298 an incremental archive with additional metadata stored in a standalone
5299 file, called a @dfn{snapshot file}. The purpose of this file is to help
5300 determine which files have been changed, added or deleted since the
5301 last backup, so that the next incremental backup will contain only
5302 modified files. The name of the snapshot file is given as an argument
5306 @item --listed-incremental=@var{file}
5307 @itemx -g @var{file}
5308 Handle incremental backups with snapshot data in @var{file}.
5311 To create an incremental backup, you would use
5312 @option{--listed-incremental} together with @option{--create}
5313 (@pxref{create}). For example:
5316 $ @kbd{tar --create \
5317 --file=archive.1.tar \
5318 --listed-incremental=/var/log/usr.snar \
5322 This will create in @file{archive.1.tar} an incremental backup of
5323 the @file{/usr} file system, storing additional metadata in the file
5324 @file{/var/log/usr.snar}. If this file does not exist, it will be
5325 created. The created archive will then be a @dfn{level 0 backup};
5326 please see the next section for more on backup levels.
5328 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5329 determines which files are modified. In this case only these files will be
5330 stored in the archive. Suppose, for example, that after running the
5331 above command, you delete file @file{/usr/doc/old} and create
5332 directory @file{/usr/local/db} with the following contents:
5335 $ @kbd{ls /usr/local/db}
5340 Some time later you create another incremental backup. You will
5344 $ @kbd{tar --create \
5345 --file=archive.2.tar \
5346 --listed-incremental=/var/log/usr.snar \
5348 tar: usr/local/db: Directory is new
5355 The created archive @file{archive.2.tar} will contain only these
5356 three members. This archive is called a @dfn{level 1 backup}. Notice
5357 that @file{/var/log/usr.snar} will be updated with the new data, so if
5358 you plan to create more @samp{level 1} backups, it is necessary to
5359 create a working copy of the snapshot file before running
5360 @command{tar}. The above example will then be modified as follows:
5363 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5364 $ @kbd{tar --create \
5365 --file=archive.2.tar \
5366 --listed-incremental=/var/log/usr.snar-1 \
5370 Incremental dumps depend crucially on time stamps, so the results are
5371 unreliable if you modify a file's time stamps during dumping (e.g.,
5372 with the @option{--atime-preserve=replace} option), or if you set the clock
5375 Metadata stored in snapshot files include device numbers, which,
5376 obviously is supposed to be a non-volatile value. However, it turns
5377 out that NFS devices have undependable values when an automounter
5378 gets in the picture. This can lead to a great deal of spurious
5379 redumping in incremental dumps, so it is somewhat useless to compare
5380 two NFS devices numbers over time. The solution implemented currently
5381 is to considers all NFS devices as being equal when it comes to
5382 comparing directories; this is fairly gross, but there does not seem
5383 to be a better way to go.
5385 Note that incremental archives use @command{tar} extensions and may
5386 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5388 @xopindex{listed-incremental, using with @option{--extract}}
5389 @xopindex{extract, using with @option{--listed-incremental}}
5390 To extract from the incremental dumps, use
5391 @option{--listed-incremental} together with @option{--extract}
5392 option (@pxref{extracting files}). In this case, @command{tar} does
5393 not need to access snapshot file, since all the data necessary for
5394 extraction are stored in the archive itself. So, when extracting, you
5395 can give whatever argument to @option{--listed-incremental}, the usual
5396 practice is to use @option{--listed-incremental=/dev/null}.
5397 Alternatively, you can use @option{--incremental}, which needs no
5398 arguments. In general, @option{--incremental} (@option{-G}) can be
5399 used as a shortcut for @option{--listed-incremental} when listing or
5400 extracting incremental backups (for more information, regarding this
5401 option, @pxref{incremental-op}).
5403 When extracting from the incremental backup @GNUTAR{} attempts to
5404 restore the exact state the file system had when the archive was
5405 created. In particular, it will @emph{delete} those files in the file
5406 system that did not exist in their directories when the archive was
5407 created. If you have created several levels of incremental files,
5408 then in order to restore the exact contents the file system had when
5409 the last level was created, you will need to restore from all backups
5410 in turn. Continuing our example, to restore the state of @file{/usr}
5411 file system, one would do@footnote{Notice, that since both archives
5412 were created without @option{-P} option (@pxref{absolute}), these
5413 commands should be run from the root file system.}:
5416 $ @kbd{tar --extract \
5417 --listed-incremental=/dev/null \
5418 --file archive.1.tar}
5419 $ @kbd{tar --extract \
5420 --listed-incremental=/dev/null \
5421 --file archive.2.tar}
5424 To list the contents of an incremental archive, use @option{--list}
5425 (@pxref{list}), as usual. To obtain more information about the
5426 archive, use @option{--listed-incremental} or @option{--incremental}
5427 combined with two @option{--verbose} options@footnote{Two
5428 @option{--verbose} options were selected to avoid breaking usual
5429 verbose listing output (@option{--list --verbose}) when using in
5432 @xopindex{incremental, using with @option{--list}}
5433 @xopindex{listed-incremental, using with @option{--list}}
5434 @xopindex{list, using with @option{--incremental}}
5435 @xopindex{list, using with @option{--listed-incremental}}
5436 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5437 contents of the DUMPDIR header (with terminating nulls) when
5438 @option{--incremental} or @option{--listed-incremental} option was
5439 given, no matter what the verbosity level. This behavior, and,
5440 especially, the binary output it produced were considered inconvenient
5441 and were changed in version 1.16}:
5444 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5447 This command will print, for each directory in the archive, the list
5448 of files in that directory at the time the archive was created. This
5449 information is put out in a format which is both human-readable and
5450 unambiguous for a program: each file name is printed as
5457 where @var{x} is a letter describing the status of the file: @samp{Y}
5458 if the file is present in the archive, @samp{N} if the file is not
5459 included in the archive, or a @samp{D} if the file is a directory (and
5460 is included in the archive). @xref{Dumpdir}, for the detailed
5461 description of dumpdirs and status codes. Each such
5462 line is terminated by a newline character. The last line is followed
5463 by an additional newline to indicate the end of the data.
5465 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5466 gives the same behavior as @option{--listed-incremental} when used
5467 with @option{--list} and @option{--extract} options. When used with
5468 @option{--create} option, it creates an incremental archive without
5469 creating snapshot file. Thus, it is impossible to create several
5470 levels of incremental backups with @option{--incremental} option.
5473 @section Levels of Backups
5475 An archive containing all the files in the file system is called a
5476 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5477 creating a full dump every day. This strategy, however, would waste a
5478 substantial amount of archive media and user time, as unchanged files
5479 are daily re-archived.
5481 It is more efficient to do a full dump only occasionally. To back up
5482 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5483 one} dump archives all the files that have changed since the last full
5486 A typical dump strategy would be to perform a full dump once a week,
5487 and a level one dump once a day. This means some versions of files
5488 will in fact be archived more than once, but this dump strategy makes
5489 it possible to restore a file system to within one day of accuracy by
5490 only extracting two archives---the last weekly (full) dump and the
5491 last daily (level one) dump. The only information lost would be in
5492 files changed or created since the last daily backup. (Doing dumps
5493 more than once a day is usually not worth the trouble).
5495 @GNUTAR{} comes with scripts you can use to do full
5496 and level-one (actually, even level-two and so on) dumps. Using
5497 scripts (shell programs) to perform backups and restoration is a
5498 convenient and reliable alternative to typing out file name lists
5499 and @command{tar} commands by hand.
5501 Before you use these scripts, you need to edit the file
5502 @file{backup-specs}, which specifies parameters used by the backup
5503 scripts and by the restore script. This file is usually located
5504 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5505 detailed description. Once the backup parameters are set, you can
5506 perform backups or restoration by running the appropriate script.
5508 The name of the backup script is @code{backup}. The name of the
5509 restore script is @code{restore}. The following sections describe
5510 their use in detail.
5512 @emph{Please Note:} The backup and restoration scripts are
5513 designed to be used together. While it is possible to restore files by
5514 hand from an archive which was created using a backup script, and to create
5515 an archive by hand which could then be extracted using the restore script,
5516 it is easier to use the scripts. @xref{Incremental Dumps}, before
5517 making such an attempt.
5519 @node Backup Parameters
5520 @section Setting Parameters for Backups and Restoration
5522 The file @file{backup-specs} specifies backup parameters for the
5523 backup and restoration scripts provided with @command{tar}. You must
5524 edit @file{backup-specs} to fit your system configuration and schedule
5525 before using these scripts.
5527 Syntactically, @file{backup-specs} is a shell script, containing
5528 mainly variable assignments. However, any valid shell construct
5529 is allowed in this file. Particularly, you may wish to define
5530 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5531 For more information about shell script syntax, please refer to
5532 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5533 g_02, the definition of the Shell Command Language}. See also
5534 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5536 The shell variables controlling behavior of @code{backup} and
5537 @code{restore} are described in the following subsections.
5540 * General-Purpose Variables::
5541 * Magnetic Tape Control::
5543 * backup-specs example:: An Example Text of @file{Backup-specs}
5546 @node General-Purpose Variables
5547 @subsection General-Purpose Variables
5549 @defvr {Backup variable} ADMINISTRATOR
5550 The user name of the backup administrator. @code{Backup} scripts
5551 sends a backup report to this address.
5554 @defvr {Backup variable} BACKUP_HOUR
5555 The hour at which the backups are done. This can be a number from 0
5556 to 23, or the time specification in form @var{hours}:@var{minutes},
5557 or the string @samp{now}.
5559 This variable is used by @code{backup}. Its value may be overridden
5560 using @option{--time} option (@pxref{Scripted Backups}).
5563 @defvr {Backup variable} TAPE_FILE
5565 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5566 is a remote archive (@pxref{remote-dev}), backup script will suppose
5567 that your @command{mt} is able to access remote devices. If @var{RSH}
5568 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5569 invocations of @command{mt}.
5572 @defvr {Backup variable} BLOCKING
5574 The blocking factor @command{tar} will use when writing the dump archive.
5575 @xref{Blocking Factor}.
5578 @defvr {Backup variable} BACKUP_DIRS
5580 A list of file systems to be dumped (for @code{backup}), or restored
5581 (for @code{restore}). You can include any directory
5582 name in the list --- subdirectories on that file system will be
5583 included, regardless of how they may look to other networked machines.
5584 Subdirectories on other file systems will be ignored.
5586 The host name specifies which host to run @command{tar} on, and should
5587 normally be the host that actually contains the file system. However,
5588 the host machine must have @GNUTAR{} installed, and
5589 must be able to access the directory containing the backup scripts and
5590 their support files using the same file name that is used on the
5591 machine where the scripts are run (i.e., what @command{pwd} will print
5592 when in that directory on that machine). If the host that contains
5593 the file system does not have this capability, you can specify another
5594 host as long as it can access the file system through NFS.
5596 If the list of file systems is very long you may wish to put it
5597 in a separate file. This file is usually named
5598 @file{/etc/backup/dirs}, but this name may be overridden in
5599 @file{backup-specs} using @code{DIRLIST} variable.
5602 @defvr {Backup variable} DIRLIST
5604 A path to the file containing the list of the file systems to backup
5605 or restore. By default it is @file{/etc/backup/dirs}.
5608 @defvr {Backup variable} BACKUP_FILES
5610 A list of individual files to be dumped (for @code{backup}), or restored
5611 (for @code{restore}). These should be accessible from the machine on
5612 which the backup script is run.
5614 If the list of file systems is very long you may wish to store it
5615 in a separate file. This file is usually named
5616 @file{/etc/backup/files}, but this name may be overridden in
5617 @file{backup-specs} using @code{FILELIST} variable.
5620 @defvr {Backup variable} FILELIST
5622 A path to the file containing the list of the individual files to backup
5623 or restore. By default it is @file{/etc/backup/files}.
5626 @defvr {Backup variable} MT
5628 Full file name of @command{mt} binary.
5631 @defvr {Backup variable} RSH
5633 Full file name of @command{rsh} binary or its equivalent. You may wish to
5634 set it to @code{ssh}, to improve security. In this case you will have
5635 to use public key authentication.
5638 @defvr {Backup variable} RSH_COMMAND
5640 Full file name of @command{rsh} binary on remote machines. This will
5641 be passed via @option{--rsh-command} option to the remote invocation
5645 @defvr {Backup variable} VOLNO_FILE
5647 Name of temporary file to hold volume numbers. This needs to be accessible
5648 by all the machines which have file systems to be dumped.
5651 @defvr {Backup variable} XLIST
5653 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5654 located on the remote machine and containing the list of files to
5655 be excluded from the backup. Exclude file lists are searched in
5656 /etc/tar-backup directory. A common use for exclude file lists
5657 is to exclude files containing security-sensitive information
5658 (e.g., @file{/etc/shadow} from backups).
5660 This variable affects only @code{backup}.
5663 @defvr {Backup variable} SLEEP_TIME
5665 Time to sleep between dumps of any two successive file systems
5667 This variable affects only @code{backup}.
5670 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5672 Script to be run when it's time to insert a new tape in for the next
5673 volume. Administrators may want to tailor this script for their site.
5674 If this variable isn't set, @GNUTAR{} will display its built-in
5675 prompt, and will expect confirmation from the console. For the
5676 description of the default prompt, see @ref{change volume prompt}.
5680 @defvr {Backup variable} SLEEP_MESSAGE
5682 Message to display on the terminal while waiting for dump time. Usually
5683 this will just be some literal text.
5686 @defvr {Backup variable} TAR
5688 Full file name of the @GNUTAR{} executable. If this is not set, backup
5689 scripts will search @command{tar} in the current shell path.
5692 @node Magnetic Tape Control
5693 @subsection Magnetic Tape Control
5695 Backup scripts access tape device using special @dfn{hook functions}.
5696 These functions take a single argument -- the name of the tape
5697 device. Their names are kept in the following variables:
5699 @defvr {Backup variable} MT_BEGIN
5700 The name of @dfn{begin} function. This function is called before
5701 accessing the drive. By default it retensions the tape:
5707 mt -f "$1" retension
5712 @defvr {Backup variable} MT_REWIND
5713 The name of @dfn{rewind} function. The default definition is as
5726 @defvr {Backup variable} MT_OFFLINE
5727 The name of the function switching the tape off line. By default
5728 it is defined as follows:
5731 MT_OFFLINE=mt_offline
5739 @defvr {Backup variable} MT_STATUS
5740 The name of the function used to obtain the status of the archive device,
5741 including error count. Default definition:
5753 @subsection User Hooks
5755 @dfn{User hooks} are shell functions executed before and after
5756 each @command{tar} invocation. Thus, there are @dfn{backup
5757 hooks}, which are executed before and after dumping each file
5758 system, and @dfn{restore hooks}, executed before and
5759 after restoring a file system. Each user hook is a shell function
5760 taking four arguments:
5762 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5767 Current backup or restore level.
5770 Name or IP address of the host machine being dumped or restored.
5773 Full path name to the file system being dumped or restored.
5776 File system name with directory separators replaced with colons. This
5777 is useful, e.g., for creating unique files.
5781 Following variables keep the names of user hook functions
5783 @defvr {Backup variable} DUMP_BEGIN
5784 Dump begin function. It is executed before dumping the file system.
5787 @defvr {Backup variable} DUMP_END
5788 Executed after dumping the file system.
5791 @defvr {Backup variable} RESTORE_BEGIN
5792 Executed before restoring the file system.
5795 @defvr {Backup variable} RESTORE_END
5796 Executed after restoring the file system.
5799 @node backup-specs example
5800 @subsection An Example Text of @file{Backup-specs}
5802 The following is an example of @file{backup-specs}:
5805 # site-specific parameters for file system backup.
5807 ADMINISTRATOR=friedman
5809 TAPE_FILE=/dev/nrsmt0
5811 # Use @code{ssh} instead of the less secure @code{rsh}
5813 RSH_COMMAND=/usr/bin/ssh
5815 # Override MT_STATUS function:
5821 # Disable MT_OFFLINE function
5838 apple-gunkies:/com/mailer/gnu
5839 apple-gunkies:/com/archive/gnu"
5841 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5845 @node Scripted Backups
5846 @section Using the Backup Scripts
5848 The syntax for running a backup script is:
5851 backup --level=@var{level} --time=@var{time}
5854 The @option{level} option requests the dump level. Thus, to produce
5855 a full dump, specify @code{--level=0} (this is the default, so
5856 @option{--level} may be omitted if its value is @code{0}).
5857 @footnote{For backward compatibility, the @code{backup} will also
5858 try to deduce the requested dump level from the name of the
5859 script itself. If the name consists of a string @samp{level-}
5860 followed by a single decimal digit, that digit is taken as
5861 the dump level number. Thus, you may create a link from @code{backup}
5862 to @code{level-1} and then run @code{level-1} whenever you need to
5863 create a level one dump.}
5865 The @option{--time} option determines when should the backup be
5866 run. @var{Time} may take three forms:
5869 @item @var{hh}:@var{mm}
5871 The dump must be run at @var{hh} hours @var{mm} minutes.
5875 The dump must be run at @var{hh} hours
5879 The dump must be run immediately.
5882 You should start a script with a tape or disk mounted. Once you
5883 start a script, it prompts you for new tapes or disks as it
5884 needs them. Media volumes don't have to correspond to archive
5885 files --- a multi-volume archive can be started in the middle of a
5886 tape that already contains the end of another multi-volume archive.
5887 The @code{restore} script prompts for media by its archive volume,
5888 so to avoid an error message you should keep track of which tape
5889 (or disk) contains which volume of the archive (@pxref{Scripted
5892 The backup scripts write two files on the file system. The first is a
5893 record file in @file{/etc/tar-backup/}, which is used by the scripts
5894 to store and retrieve information about which files were dumped. This
5895 file is not meant to be read by humans, and should not be deleted by
5896 them. @xref{Snapshot Files}, for a more detailed explanation of this
5899 The second file is a log file containing the names of the file systems
5900 and files dumped, what time the backup was made, and any error
5901 messages that were generated, as well as how much space was left in
5902 the media volume after the last volume of the archive was written.
5903 You should check this log file after every backup. The file name is
5904 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5905 represents current date, and @var{n} represents current dump level number.
5907 The script also prints the name of each system being dumped to the
5910 Following is the full list of options accepted by @code{backup}
5914 @item -l @var{level}
5915 @itemx --level=@var{level}
5916 Do backup level @var{level} (default 0).
5920 Force backup even if today's log file already exists.
5922 @item -v[@var{level}]
5923 @itemx --verbose[=@var{level}]
5924 Set verbosity level. The higher the level is, the more debugging
5925 information will be output during execution. Default @var{level}
5926 is 100, which means the highest debugging level.
5928 @item -t @var{start-time}
5929 @itemx --time=@var{start-time}
5930 Wait till @var{time}, then do backup.
5934 Display short help message and exit.
5938 Display information about the program's name, version, origin and legal
5939 status, all on standard output, and then exit successfully.
5943 @node Scripted Restoration
5944 @section Using the Restore Script
5946 To restore files that were archived using a scripted backup, use the
5947 @code{restore} script. Its usage is quite straightforward. In the
5948 simplest form, invoke @code{restore --all}, it will
5949 then restore all the file systems and files specified in
5950 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5952 You may select the file systems (and/or files) to restore by
5953 giving @code{restore} list of @dfn{patterns} in its command
5954 line. For example, running
5961 will restore all file systems on the machine @samp{albert}. A more
5962 complicated example:
5965 restore 'albert:*' '*:/var'
5969 This command will restore all file systems on the machine @samp{albert}
5970 as well as @file{/var} file system on all machines.
5972 By default @code{restore} will start restoring files from the lowest
5973 available dump level (usually zero) and will continue through
5974 all available dump levels. There may be situations where such a
5975 thorough restore is not necessary. For example, you may wish to
5976 restore only files from the recent level one backup. To do so,
5977 use @option{--level} option, as shown in the example below:
5983 The full list of options accepted by @code{restore} follows:
5988 Restore all file systems and files specified in @file{backup-specs}
5990 @item -l @var{level}
5991 @itemx --level=@var{level}
5992 Start restoring from the given backup level, instead of the default 0.
5994 @item -v[@var{level}]
5995 @itemx --verbose[=@var{level}]
5996 Set verbosity level. The higher the level is, the more debugging
5997 information will be output during execution. Default @var{level}
5998 is 100, which means the highest debugging level.
6002 Display short help message and exit.
6006 Display information about the program's name, version, origin and legal
6007 status, all on standard output, and then exit successfully.
6010 You should start the restore script with the media containing the
6011 first volume of the archive mounted. The script will prompt for other
6012 volumes as they are needed. If the archive is on tape, you don't need
6013 to rewind the tape to to its beginning---if the tape head is
6014 positioned past the beginning of the archive, the script will rewind
6015 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6019 @strong{Warning:} The script will delete files from the active file
6020 system if they were not in the file system when the archive was made.
6023 @xref{Incremental Dumps}, for an explanation of how the script makes
6027 @chapter Choosing Files and Names for @command{tar}
6030 Certain options to @command{tar} enable you to specify a name for your
6031 archive. Other options let you decide which files to include or exclude
6032 from the archive, based on when or whether files were modified, whether
6033 the file names do or don't match specified patterns, or whether files
6034 are in specified directories.
6036 This chapter discusses these options in detail.
6039 * file:: Choosing the Archive's Name
6040 * Selecting Archive Members::
6041 * files:: Reading Names from a File
6042 * exclude:: Excluding Some Files
6043 * wildcards:: Wildcards Patterns and Matching
6044 * quoting styles:: Ways of Quoting Special Characters in Names
6045 * transform:: Modifying File and Member Names
6046 * after:: Operating Only on New Files
6047 * recurse:: Descending into Directories
6048 * one:: Crossing File System Boundaries
6052 @section Choosing and Naming Archive Files
6055 @cindex Naming an archive
6056 @cindex Archive Name
6057 @cindex Choosing an archive file
6058 @cindex Where is the archive?
6059 By default, @command{tar} uses an archive file name that was compiled when
6060 it was built on the system; usually this name refers to some physical
6061 tape drive on the machine. However, the person who installed @command{tar}
6062 on the system may not have set the default to a meaningful value as far as
6063 most users are concerned. As a result, you will usually want to tell
6064 @command{tar} where to find (or create) the archive. The
6065 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6066 option allows you to either specify or name a file to use as the archive
6067 instead of the default archive file location.
6070 @xopindex{file, short description}
6071 @item --file=@var{archive-name}
6072 @itemx -f @var{archive-name}
6073 Name the archive to create or operate on. Use in conjunction with
6077 For example, in this @command{tar} command,
6080 $ @kbd{tar -cvf collection.tar blues folk jazz}
6084 @file{collection.tar} is the name of the archive. It must directly
6085 follow the @option{-f} option, since whatever directly follows @option{-f}
6086 @emph{will} end up naming the archive. If you neglect to specify an
6087 archive name, you may end up overwriting a file in the working directory
6088 with the archive you create since @command{tar} will use this file's name
6089 for the archive name.
6091 An archive can be saved as a file in the file system, sent through a
6092 pipe or over a network, or written to an I/O device such as a tape,
6093 floppy disk, or CD write drive.
6095 @cindex Writing new archives
6096 @cindex Archive creation
6097 If you do not name the archive, @command{tar} uses the value of the
6098 environment variable @env{TAPE} as the file name for the archive. If
6099 that is not available, @command{tar} uses a default, compiled-in archive
6100 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6102 @cindex Standard input and output
6103 @cindex tar to standard input and output
6104 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6105 archive from standard input (when listing or extracting files), or
6106 writes it to standard output (when creating an archive). If you use
6107 @file{-} as an @var{archive-name} when modifying an archive,
6108 @command{tar} reads the original archive from its standard input and
6109 writes the entire new archive to its standard output.
6111 The following example is a convenient way of copying directory
6112 hierarchy from @file{sourcedir} to @file{targetdir}.
6115 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6118 The @option{-C} option allows to avoid using subshells:
6121 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6124 In both examples above, the leftmost @command{tar} invocation archives
6125 the contents of @file{sourcedir} to the standard output, while the
6126 rightmost one reads this archive from its standard input and
6127 extracts it. The @option{-p} option tells it to restore permissions
6128 of the extracted files.
6130 @cindex Remote devices
6131 @cindex tar to a remote device
6133 To specify an archive file on a device attached to a remote machine,
6137 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6141 @command{tar} will complete the remote connection, if possible, and
6142 prompt you for a username and password. If you use
6143 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6144 will complete the remote connection, if possible, using your username
6145 as the username on the remote machine.
6147 @cindex Local and remote archives
6148 @anchor{local and remote archives}
6149 If the archive file name includes a colon (@samp{:}), then it is assumed
6150 to be a file on another machine. If the archive file is
6151 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6152 host @var{host}. The remote host is accessed using the @command{rsh}
6153 program, with a username of @var{user}. If the username is omitted
6154 (along with the @samp{@@} sign), then your user name will be used.
6155 (This is the normal @command{rsh} behavior.) It is necessary for the
6156 remote machine, in addition to permitting your @command{rsh} access, to
6157 have the @file{rmt} program installed (This command is included in
6158 the @GNUTAR{} distribution and by default is installed under
6159 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6160 installation prefix). If you need to use a file whose name includes a
6161 colon, then the remote tape drive behavior
6162 can be inhibited by using the @option{--force-local} option.
6164 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6165 tries to minimize input and output operations. The Amanda backup
6166 system, when used with @GNUTAR{}, has an initial sizing pass which
6169 @node Selecting Archive Members
6170 @section Selecting Archive Members
6171 @cindex Specifying files to act on
6172 @cindex Specifying archive members
6174 @dfn{File Name arguments} specify which files in the file system
6175 @command{tar} operates on, when creating or adding to an archive, or which
6176 archive members @command{tar} operates on, when reading or deleting from
6177 an archive. @xref{Operations}.
6179 To specify file names, you can include them as the last arguments on
6180 the command line, as follows:
6182 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6185 If a file name begins with dash (@samp{-}), precede it with
6186 @option{--add-file} option to prevent it from being treated as an
6189 @anchor{input name quoting}
6190 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6191 name, replacing @dfn{escape sequences} according to the following
6194 @multitable @columnfractions 0.20 0.60
6195 @headitem Escape @tab Replaced with
6196 @item \a @tab Audible bell (ASCII 7)
6197 @item \b @tab Backspace (ASCII 8)
6198 @item \f @tab Form feed (ASCII 12)
6199 @item \n @tab New line (ASCII 10)
6200 @item \r @tab Carriage return (ASCII 13)
6201 @item \t @tab Horizontal tabulation (ASCII 9)
6202 @item \v @tab Vertical tabulation (ASCII 11)
6203 @item \? @tab ASCII 127
6204 @item \@var{n} @tab ASCII @var{n} (@var{n} should be an octal number
6208 A backslash followed by any other symbol is retained.
6210 This default behavior is controlled by the following command line
6216 Enable unquoting input file or member names (default).
6220 Disable unquoting input file or member names.
6223 If you specify a directory name as a file name argument, all the files
6224 in that directory are operated on by @command{tar}.
6226 If you do not specify files, @command{tar} behavior differs depending
6227 on the operation mode as described below:
6229 When @command{tar} is invoked with @option{--create} (@option{-c}),
6230 @command{tar} will stop immediately, reporting the following:
6234 $ @kbd{tar cf a.tar}
6235 tar: Cowardly refusing to create an empty archive
6236 Try `tar --help' or `tar --usage' for more information.
6240 If you specify either @option{--list} (@option{-t}) or
6241 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6242 operates on all the archive members in the archive.
6244 If run with @option{--diff} option, tar will compare the archive with
6245 the contents of the current working directory.
6247 If you specify any other operation, @command{tar} does nothing.
6249 By default, @command{tar} takes file names from the command line. However,
6250 there are other ways to specify file or member names, or to modify the
6251 manner in which @command{tar} selects the files or members upon which to
6252 operate. In general, these methods work both for specifying the names
6253 of files and archive members.
6256 @section Reading Names from a File
6258 @cindex Reading file names from a file
6259 @cindex Lists of file names
6260 @cindex File Name arguments, alternatives
6261 Instead of giving the names of files or archive members on the command
6262 line, you can put the names into a file, and then use the
6263 @option{--files-from=@var{file-of-names}} (@option{-T
6264 @var{file-of-names}}) option to @command{tar}. Give the name of the
6265 file which contains the list of files to include as the argument to
6266 @option{--files-from}. In the list, the file names should be separated by
6267 newlines. You will frequently use this option when you have generated
6268 the list of files to archive with the @command{find} utility.
6272 @item --files-from=@var{file-name}
6273 @itemx -T @var{file-name}
6274 Get names to extract or create from file @var{file-name}.
6277 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6278 you specify either @code{--files-from=-} or @code{-T -}), then the file
6279 names are read from standard input.
6281 Unless you are running @command{tar} with @option{--create}, you can not use
6282 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6285 Any number of @option{-T} options can be given in the command line.
6287 The following example shows how to use @command{find} to generate a list of
6288 files smaller than 400K in length and put that list into a file
6289 called @file{small-files}. You can then use the @option{-T} option to
6290 @command{tar} to specify the files from that file, @file{small-files}, to
6291 create the archive @file{little.tgz}. (The @option{-z} option to
6292 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6296 $ @kbd{find . -size -400 -print > small-files}
6297 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6301 In the file list given by @option{-T} option, any file name beginning
6302 with @samp{-} character is considered a @command{tar} option and is
6303 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6304 recognized only @option{-C} option in file lists, and only if the
6305 option and its argument occupied two consecutive lines.} For example,
6306 the common use of this feature is to change to another directory by
6307 specifying @option{-C} option:
6317 $ @kbd{tar -c -f foo.tar --files-from list}
6322 In this example, @command{tar} will first switch to @file{/etc}
6323 directory and add files @file{passwd} and @file{hosts} to the
6324 archive. Then it will change to @file{/lib} directory and will archive
6325 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6330 $ @kbd{tar tf foo.tar}
6338 @xopindex{directory, using in @option{--files-from} argument}
6339 Notice that the option parsing algorithm used with @option{-T} is
6340 stricter than the one used by shell. Namely, when specifying option
6341 arguments, you should observe the following rules:
6345 When using short (single-letter) option form, its argument must
6346 immediately follow the option letter, without any intervening
6347 whitespace. For example: @code{-Cdir}.
6350 When using long option form, the option argument must be separated
6351 from the option by a single equal sign. No whitespace is allowed on
6352 any side of the equal sign. For example: @code{--directory=dir}.
6355 For both short and long option forms, the option argument can be given
6356 on the next line after the option name, e.g.:
6377 If you happen to have a file whose name starts with @samp{-},
6378 precede it with @option{--add-file} option to prevent it from
6379 being recognized as an option. For example: @code{--add-file=--my-file}.
6386 @subsection @code{NUL} Terminated File Names
6388 @cindex File names, terminated by @code{NUL}
6389 @cindex @code{NUL} terminated file names
6390 The @option{--null} option causes
6391 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6392 to read file names terminated by a @code{NUL} instead of a newline, so
6393 files whose names contain newlines can be archived using
6394 @option{--files-from}.
6399 Only consider @code{NUL} terminated file names, instead of files that
6400 terminate in a newline.
6403 The @option{--null} option is just like the one in @acronym{GNU}
6404 @command{xargs} and @command{cpio}, and is useful with the
6405 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6406 @command{tar}, @option{--null} also disables special handling for
6407 file names that begin with dash.
6409 This example shows how to use @command{find} to generate a list of files
6410 larger than 800K in length and put that list into a file called
6411 @file{long-files}. The @option{-print0} option to @command{find} is just
6412 like @option{-print}, except that it separates files with a @code{NUL}
6413 rather than with a newline. You can then run @command{tar} with both the
6414 @option{--null} and @option{-T} options to specify that @command{tar} get the
6415 files from that file, @file{long-files}, to create the archive
6416 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6417 @command{tar} to recognize the @code{NUL} separator between files.
6420 $ @kbd{find . -size +800 -print0 > long-files}
6421 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6424 @FIXME{say anything else here to conclude the section?}
6427 @section Excluding Some Files
6430 @cindex File names, excluding files by
6431 @cindex Excluding files by name and pattern
6432 @cindex Excluding files by file system
6433 To avoid operating on files whose names match a particular pattern,
6434 use the @option{--exclude} or @option{--exclude-from} options.
6438 @item --exclude=@var{pattern}
6439 Causes @command{tar} to ignore files that match the @var{pattern}.
6443 The @option{--exclude=@var{pattern}} option prevents any file or
6444 member whose name matches the shell wildcard (@var{pattern}) from
6446 For example, to create an archive with all the contents of the directory
6447 @file{src} except for files whose names end in @file{.o}, use the
6448 command @samp{tar -cf src.tar --exclude='*.o' src}.
6450 You may give multiple @option{--exclude} options.
6453 @opindex exclude-from
6454 @item --exclude-from=@var{file}
6455 @itemx -X @var{file}
6456 Causes @command{tar} to ignore files that match the patterns listed in
6460 @findex exclude-from
6461 Use the @option{--exclude-from} option to read a
6462 list of patterns, one per line, from @var{file}; @command{tar} will
6463 ignore files matching those patterns. Thus if @command{tar} is
6464 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6465 single line @file{*.o}, no files whose names end in @file{.o} will be
6466 added to the archive.
6469 @opindex exclude-caches
6470 @item --exclude-caches
6471 Causes @command{tar} to ignore directories containing a cache directory tag.
6474 @findex exclude-caches
6475 When creating an archive, the @option{--exclude-caches} option causes
6476 @command{tar} to exclude all directories that contain a @dfn{cache
6477 directory tag}. A cache directory tag is a short file with the
6478 well-known name @file{CACHEDIR.TAG} and having a standard header
6479 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6480 Various applications write cache directory tags into directories they
6481 use to hold regenerable, non-precious data, so that such data can be
6482 more easily excluded from backups.
6485 * problems with exclude::
6488 @node problems with exclude
6489 @unnumberedsubsec Problems with Using the @code{exclude} Options
6491 @xopindex{exclude, potential problems with}
6492 Some users find @samp{exclude} options confusing. Here are some common
6497 The main operating mode of @command{tar} does not act on a path name
6498 explicitly listed on the command line if one of its file name
6499 components is excluded. In the example above, if
6500 you create an archive and exclude files that end with @samp{*.o}, but
6501 explicitly name the file @samp{dir.o/foo} after all the options have been
6502 listed, @samp{dir.o/foo} will be excluded from the archive.
6505 You can sometimes confuse the meanings of @option{--exclude} and
6506 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6507 to be excluded are given as a pattern on the command line. Use
6508 @option{--exclude-from} to introduce the name of a file which contains
6509 a list of patterns, one per line; each of these patterns can exclude
6510 zero, one, or many files.
6513 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6514 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6515 like @samp{*}. If you do not do this, the shell might expand the
6516 @samp{*} itself using files at hand, so @command{tar} might receive a
6517 list of files instead of one pattern, or none at all, making the
6518 command somewhat illegal. This might not correspond to what you want.
6523 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6531 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6535 You must use use shell syntax, or globbing, rather than @code{regexp}
6536 syntax, when using exclude options in @command{tar}. If you try to use
6537 @code{regexp} syntax to describe files to be excluded, your command
6541 @FIXME{The change in semantics must have occurred before 1.11,
6542 so I doubt if it is worth mentioning at all. Anyway, should at
6543 least specify in which version the semantics changed.}
6544 In earlier versions of @command{tar}, what is now the
6545 @option{--exclude-from} option was called @option{--exclude} instead.
6546 Now, @option{--exclude} applies to patterns listed on the command
6547 line and @option{--exclude-from} applies to patterns listed in a
6553 @section Wildcards Patterns and Matching
6555 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6556 @samp{*} or @samp{?} for example, are replaced and expanded into all
6557 existing files matching the given pattern. @GNUTAR{} can use wildcard
6558 patterns for matching (or globbing) archive members when extracting
6559 from or listing an archive. Wildcard patterns are also used for
6560 verifying volume labels of @command{tar} archives. This section has the
6561 purpose of explaining wildcard syntax for @command{tar}.
6563 @FIXME{the next few paragraphs need work.}
6565 A @var{pattern} should be written according to shell syntax, using wildcard
6566 characters to effect globbing. Most characters in the pattern stand
6567 for themselves in the matched string, and case is significant: @samp{a}
6568 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6569 pattern matches any single character in the matched string. The character
6570 @samp{*} in the pattern matches zero, one, or more single characters in
6571 the matched string. The character @samp{\} says to take the following
6572 character of the pattern @emph{literally}; it is useful when one needs to
6573 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6575 The character @samp{[}, up to the matching @samp{]}, introduces a character
6576 class. A @dfn{character class} is a list of acceptable characters
6577 for the next single character of the matched string. For example,
6578 @samp{[abcde]} would match any of the first five letters of the alphabet.
6579 Note that within a character class, all of the ``special characters''
6580 listed above other than @samp{\} lose their special meaning; for example,
6581 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6582 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6583 the characters @samp{-} and @samp{]} must either come @emph{first} or
6584 @emph{last} in a character class.)
6586 @cindex Excluding characters from a character class
6587 @cindex Character class, excluding characters from
6588 If the first character of the class after the opening @samp{[}
6589 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6590 Rather than listing character to match, it lists those characters which
6591 are @emph{forbidden} as the next single character of the matched string.
6593 Other characters of the class stand for themselves. The special
6594 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6595 letters, is meant to represent all characters between @var{a} and
6598 @FIXME{need to add a sentence or so here to make this clear for those
6599 who don't have dan around.}
6601 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6602 special for wildcard matches. However, if a pattern completely matches
6603 a directory prefix of a matched string, then it matches the full matched
6604 string: thus, excluding a directory also excludes all the files beneath it.
6607 * controlling pattern-matching::
6610 @node controlling pattern-matching
6611 @unnumberedsubsec Controlling Pattern-Matching
6613 For the purposes of this section, we call @dfn{exclusion members} all
6614 member names obtained while processing @option{--exclude} and
6615 @option{--exclude-from} options, and @dfn{inclusion members} those
6616 member names that were given in the command line or read from the file
6617 specified with @option{--files-from} option.
6619 These two pairs of member lists are used in the following operations:
6620 @option{--diff}, @option{--extract}, @option{--list},
6623 There are no inclusion members in create mode (@option{--create} and
6624 @option{--append}), since in this mode the names obtained from the
6625 command line refer to @emph{files}, not archive members.
6627 By default, inclusion members are compared with archive members
6628 literally @footnote{Notice that earlier @GNUTAR{} versions used
6629 globbing for inclusion members, which contradicted to UNIX98
6630 specification and was not documented. @xref{Changes}, for more
6631 information on this and other changes.} and exclusion members are
6632 treated as globbing patterns. For example:
6636 $ @kbd{tar tf foo.tar}
6641 # @i{Member names are used verbatim:}
6642 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6644 # @i{Exclude member names are globbed:}
6645 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6651 This behavior can be altered by using the following options:
6656 Treat all member names as wildcards.
6658 @opindex no-wildcards
6659 @item --no-wildcards
6660 Treat all member names as literal strings.
6663 Thus, to extract files whose names end in @samp{.c}, you can use:
6666 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6672 Notice quoting of the pattern to prevent the shell from interpreting
6675 The effect of @option{--wildcards} option is canceled by
6676 @option{--no-wildcards}. This can be used to pass part of
6677 the command line arguments verbatim and other part as globbing
6678 patterns. For example, the following invocation:
6681 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6685 instructs @command{tar} to extract from @file{foo.tar} all files whose
6686 names end in @samp{.txt} and the file named @file{[remarks]}.
6688 Normally, a pattern matches a name if an initial subsequence of the
6689 name's components matches the pattern, where @samp{*}, @samp{?}, and
6690 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6691 and wildcards can match @samp{/}.
6693 Other than optionally stripping leading @samp{/} from names
6694 (@pxref{absolute}), patterns and names are used as-is. For
6695 example, trailing @samp{/} is not trimmed from a user-specified name
6696 before deciding whether to exclude it.
6698 However, this matching procedure can be altered by the options listed
6699 below. These options accumulate. For example:
6702 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6706 ignores case when excluding @samp{makefile}, but not when excluding
6711 @opindex no-anchored
6713 @itemx --no-anchored
6714 If anchored, a pattern must match an initial subsequence
6715 of the name's components. Otherwise, the pattern can match any
6716 subsequence. Default is @option{--no-anchored} for exclusion members
6717 and @option{--anchored} inclusion members.
6719 @opindex ignore-case
6720 @opindex no-ignore-case
6722 @itemx --no-ignore-case
6723 When ignoring case, upper-case patterns match lower-case names and vice versa.
6724 When not ignoring case (the default), matching is case-sensitive.
6726 @opindex wildcards-match-slash
6727 @opindex no-wildcards-match-slash
6728 @item --wildcards-match-slash
6729 @itemx --no-wildcards-match-slash
6730 When wildcards match slash (the default for exclusion members), a
6731 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6732 name. Otherwise, @samp{/} is matched only by @samp{/}.
6736 The @option{--recursion} and @option{--no-recursion} options
6737 (@pxref{recurse}) also affect how member patterns are interpreted. If
6738 recursion is in effect, a pattern matches a name if it matches any of
6739 the name's parent directories.
6741 The following table summarizes pattern-matching default values:
6743 @multitable @columnfractions .3 .7
6744 @headitem Members @tab Default settings
6745 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6746 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6749 @node quoting styles
6750 @section Quoting Member Names
6752 When displaying member names, @command{tar} takes care to avoid
6753 ambiguities caused by certain characters. This is called @dfn{name
6754 quoting}. The characters in question are:
6757 @item Non-printable control characters:
6759 @multitable @columnfractions 0.20 0.10 0.60
6760 @headitem Character @tab ASCII @tab Character name
6761 @item \a @tab 7 @tab Audible bell
6762 @item \b @tab 8 @tab Backspace
6763 @item \f @tab 12 @tab Form feed
6764 @item \n @tab 10 @tab New line
6765 @item \r @tab 13 @tab Carriage return
6766 @item \t @tab 9 @tab Horizontal tabulation
6767 @item \v @tab 11 @tab Vertical tabulation
6770 @item Space (ASCII 32)
6772 @item Single and double quotes (@samp{'} and @samp{"})
6774 @item Backslash (@samp{\})
6777 The exact way @command{tar} uses to quote these characters depends on
6778 the @dfn{quoting style}. The default quoting style, called
6779 @dfn{escape} (see below), uses backslash notation to represent control
6780 characters, space and backslash. Using this quoting style, control
6781 characters are represented as listed in column @samp{Character} in the
6782 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6784 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6785 using @option{--quoting-style} option:
6788 @item --quoting-style=@var{style}
6789 @opindex quoting-style
6791 Sets quoting style. Valid values for @var{style} argument are:
6792 literal, shell, shell-always, c, escape, locale, clocale.
6795 These styles are described in detail below. To illustrate their
6796 effect, we will use an imaginary tar archive @file{arch.tar}
6797 containing the following members:
6801 # 1. Contains horizontal tabulation character.
6803 # 2. Contains newline character
6806 # 3. Contains a space
6808 # 4. Contains double quotes
6810 # 5. Contains single quotes
6812 # 6. Contains a backslash character:
6817 Here is how usual @command{ls} command would have listed them, if they
6818 had existed in the current working directory:
6836 No quoting, display each character as is:
6840 $ @kbd{tar tf arch.tar --quoting-style=literal}
6853 Display characters the same way Bourne shell does:
6854 control characters, except @samp{\t} and @samp{\n}, are printed using
6855 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
6856 single quote is printed as @samp{\'}. If a name contains any quoted
6857 characters, it is enclosed in single quotes. In particular, if a name
6858 contains single quotes, it is printed as several single-quoted strings:
6862 $ @kbd{tar tf arch.tar --quoting-style=shell}
6865 './a'\''single'\''quote'
6875 Same as @samp{shell}, but the names are always enclosed in single
6880 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
6883 './a'\''single'\''quote'
6893 Use the notation of the C programming language. All names are
6894 enclosed in double quotes. Control characters are quoted using
6895 backslash notations, double quotes are represented as @samp{\"},
6896 backslash characters are represented as @samp{\\}. Single quotes and
6897 spaces are not quoted:
6901 $ @kbd{tar tf arch.tar --quoting-style=c}
6905 "./a\"double\"quote"
6913 Control characters are printed using backslash notation, a space is
6914 printed as @samp{\ } and a backslash as @samp{\\}. This is the
6915 default quoting style, unless it was changed when configured the
6920 $ @kbd{tar tf arch.tar --quoting-style=escape}
6932 Control characters, single quote and backslash are printed using
6933 backslash notation. All names are quoted using left and right
6934 quotation marks, appropriate to the current locale. If it does not
6935 define quotation marks, use @samp{`} as left and @samp{'} as right
6936 quotation marks. Any occurrences of the right quotation mark in a
6937 name are escaped with @samp{\}, for example:
6943 $ @kbd{tar tf arch.tar --quoting-style=locale}
6946 `./a\'single\'quote'
6955 Same as @samp{locale}, but @samp{"} is used for both left and right
6956 quotation marks, if not provided by the currently selected locale:
6960 $ @kbd{tar tf arch.tar --quoting-style=clocale}
6964 "./a\"double\"quote"
6972 You can specify which characters should be quoted in addition to those
6973 implied by the current quoting style:
6976 @item --quote-chars=@var{string}
6977 Always quote characters from @var{string}, even if the selected
6978 quoting style would not quote them.
6981 For example, using @samp{escape} quoting (compare with the usual
6982 escape listing above):
6986 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
6997 To disable quoting of such additional characters, use the following
7001 @item --no-quote-chars=@var{string}
7002 Remove characters listed in @var{string} from the list of quoted
7003 characters set by the previous @option{--quote-chars} option.
7006 This option is particularly useful if you have added
7007 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7008 and wish to disable it for the current invocation.
7010 Note, that @option{--no-quote-chars} does @emph{not} disable those
7011 characters that are quoted by default in the selected quoting style.
7014 @section Modifying File and Member Names
7016 @command{Tar} archives contain detailed information about files stored
7017 in them and full file names are part of that information. When
7018 storing file to an archive, its file name is recorded in the archive
7019 along with the actual file contents. When restoring from an archive,
7020 a file is created on disk with exactly the same name as that stored
7021 in the archive. In the majority of cases this is the desired behavior
7022 of a file archiver. However, there are some cases when it is not.
7024 First of all, it is often unsafe to extract archive members with
7025 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7026 takes special precautions when extracting such names and provides a
7027 special option for handling them, which is described in
7030 Secondly, you may wish to extract file names without some leading
7031 directory components, or with otherwise modified names. In other
7032 cases it is desirable to store files under differing names in the
7035 @GNUTAR{} provides two options for these needs.
7038 @opindex strip-components
7039 @item --strip-components=@var{number}
7040 Strip given @var{number} of leading components from file names before
7044 For example, suppose you have archived whole @file{/usr} hierarchy to
7045 a tar archive named @file{usr.tar}. Among other files, this archive
7046 contains @file{usr/include/stdlib.h}, which you wish to extract to
7047 the current working directory. To do so, you type:
7050 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7053 The option @option{--strip=2} instructs @command{tar} to strip the
7054 two leading components (@file{usr/} and @file{include/}) off the file
7057 If you add to the above invocation @option{--verbose} (@option{-v})
7058 option, you will note that the verbose listing still contains the
7059 full file name, with the two removed components still in place. This
7060 can be inconvenient, so @command{tar} provides a special option for
7061 altering this behavior:
7063 @anchor{show-transformed-names}
7065 @opindex show-transformed-names
7066 @item --show-transformed-names
7067 Display file or member names with all requested transformations
7076 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7077 usr/include/stdlib.h
7078 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7083 Notice that in both cases the file is @file{stdlib.h} extracted to the
7084 current working directory, @option{--show-transformed-names} affects
7085 only the way its name is displayed.
7087 This option is especially useful for verifying whether the invocation
7088 will have the desired effect. Thus, before running
7091 $ @kbd{tar -x --strip=@var{n}}
7095 it is often advisable to run
7098 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7102 to make sure the command will produce the intended results.
7104 In case you need to apply more complex modifications to the file name,
7105 @GNUTAR{} provides a general-purpose transformation option:
7109 @item --transform=@var{expression}
7110 Modify file names using supplied @var{expression}.
7114 The @var{expression} is a @command{sed}-like replace expression of the
7118 s/@var{regexp}/@var{replace}/[@var{flags}]
7122 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7123 replacement for each file name part that matches @var{regexp}. Both
7124 @var{regexp} and @var{replace} are described in detail in
7125 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7127 Supported @var{flags} are:
7131 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7135 Use case-insensitive matching
7138 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7139 regexps, Extended regular expressions, Extended regular expressions,
7143 Only replace the @var{number}th match of the @var{regexp}.
7145 Note: the @var{posix} standard does not specify what should happen
7146 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7147 follows the GNU @command{sed} implementation in this regard, so
7148 the interaction is defined to be: ignore matches before the
7149 @var{number}th, and then match and replace all matches from the
7154 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7155 that it be used consistently throughout the expression. For example,
7156 the following two expressions are equivalent:
7165 Changing delimiters is often useful when the @var{regex} contains
7166 slashes. For example, it is more convenient to write @code{s,/,-,} than
7169 Here are several examples of @option{--transform} usage:
7172 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7175 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7178 @item Strip two leading directory components (equivalent to
7179 @option{--strip-components=2}):
7182 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7185 @item Prepend @file{/prefix/} to each file name:
7188 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7191 @item Convert each file name to lower case:
7194 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7199 Unlike @option{--strip-components}, @option{--transform} can be used
7200 in any @GNUTAR{} operation mode. For example, the following command
7201 adds files to the archive while replacing the leading @file{usr/}
7202 component with @file{var/}:
7205 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7208 To test @option{--transform} effect we suggest using
7209 @option{--show-transformed-names} option:
7212 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7213 --verbose --show-transformed-names /}
7216 If both @option{--strip-components} and @option{--transform} are used
7217 together, then @option{--transform} is applied first, and the required
7218 number of components is then stripped from its result.
7221 @section Operating Only on New Files
7224 @cindex Excluding file by age
7225 @cindex Data Modification time, excluding files by
7226 @cindex Modification time, excluding files by
7227 @cindex Age, excluding files by
7228 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7229 @option{-N @var{date}}) option causes @command{tar} to only work on
7230 files whose data modification or status change times are newer than
7231 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7232 it is taken to be a file name; the data modification time of that file
7233 is used as the date. If you use this option when creating or appending
7234 to an archive, the archive will only include new files. If you use
7235 @option{--after-date} when extracting an archive, @command{tar} will
7236 only extract files newer than the @var{date} you specify.
7238 If you only want @command{tar} to make the date comparison based on
7239 modification of the file's data (rather than status
7240 changes), then use the @option{--newer-mtime=@var{date}} option.
7242 You may use these options with any operation. Note that these options
7243 differ from the @option{--update} (@option{-u}) operation in that they
7244 allow you to specify a particular date against which @command{tar} can
7245 compare when deciding whether or not to archive the files.
7250 @item --after-date=@var{date}
7251 @itemx --newer=@var{date}
7252 @itemx -N @var{date}
7253 Only store files newer than @var{date}.
7255 Acts on files only if their data modification or status change times are
7256 later than @var{date}. Use in conjunction with any operation.
7258 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7259 name; the data modification time of that file is used as the date.
7261 @opindex newer-mtime
7262 @item --newer-mtime=@var{date}
7263 Acts like @option{--after-date}, but only looks at data modification times.
7266 These options limit @command{tar} to operate only on files which have
7267 been modified after the date specified. A file's status is considered to have
7268 changed if its contents have been modified, or if its owner,
7269 permissions, and so forth, have been changed. (For more information on
7270 how to specify a date, see @ref{Date input formats}; remember that the
7271 entire date argument must be quoted if it contains any spaces.)
7273 Gurus would say that @option{--after-date} tests both the data
7274 modification time (@code{mtime}, the time the contents of the file
7275 were last modified) and the status change time (@code{ctime}, the time
7276 the file's status was last changed: owner, permissions, etc.@:)
7277 fields, while @option{--newer-mtime} tests only the @code{mtime}
7280 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7281 @code{ctime} and processes the file if either one is more recent than
7282 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7283 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7284 contents of the file were looked at).
7286 Date specifiers can have embedded spaces. Because of this, you may need
7287 to quote date arguments to keep the shell from parsing them as separate
7288 arguments. For example, the following command will add to the archive
7289 all the files modified less than two days ago:
7292 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7295 When any of these options is used with the option @option{--verbose}
7296 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7297 date back to its textual representation and compare that with the
7298 one given with the option. If the two dates differ, @command{tar} will
7299 print a warning saying what date it will use. This is to help user
7300 ensure he is using the right date. For example:
7304 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7305 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7311 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7312 should not be used for incremental backups. @xref{Incremental Dumps},
7313 for proper way of creating incremental backups.
7317 @section Descending into Directories
7319 @cindex Avoiding recursion in directories
7320 @cindex Descending directories, avoiding
7321 @cindex Directories, avoiding recursion
7322 @cindex Recursion in directories, avoiding
7324 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7326 Usually, @command{tar} will recursively explore all directories (either
7327 those given on the command line or through the @option{--files-from}
7328 option) for the various files they contain. However, you may not always
7329 want @command{tar} to act this way.
7331 @opindex no-recursion
7332 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7333 into specified directories. If you specify @option{--no-recursion}, you can
7334 use the @command{find} utility for hunting through levels of directories to
7335 construct a list of file names which you could then pass to @command{tar}.
7336 @command{find} allows you to be more selective when choosing which files to
7337 archive; see @ref{files}, for more information on using @command{find} with
7338 @command{tar}, or look.
7341 @item --no-recursion
7342 Prevents @command{tar} from recursively descending directories.
7346 Requires @command{tar} to recursively descend directories.
7347 This is the default.
7350 When you use @option{--no-recursion}, @GNUTAR{} grabs
7351 directory entries themselves, but does not descend on them
7352 recursively. Many people use @command{find} for locating files they
7353 want to back up, and since @command{tar} @emph{usually} recursively
7354 descends on directories, they have to use the @samp{@w{-not -type d}}
7355 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7356 find, Finding Files}), as they usually do not want all the files in a
7357 directory. They then use the @option{--files-from} option to archive
7358 the files located via @command{find}.
7360 The problem when restoring files archived in this manner is that the
7361 directories themselves are not in the archive; so the
7362 @option{--same-permissions} (@option{--preserve-permissions},
7363 @option{-p}) option does not affect them---while users might really
7364 like it to. Specifying @option{--no-recursion} is a way to tell
7365 @command{tar} to grab only the directory entries given to it, adding
7366 no new files on its own. To summarize, if you use @command{find} to
7367 create a list of files to be stored in an archive, use it as follows:
7371 $ @kbd{find @var{dir} @var{tests} | \
7372 tar -cf @var{archive} -T - --no-recursion}
7376 The @option{--no-recursion} option also applies when extracting: it
7377 causes @command{tar} to extract only the matched directory entries, not
7378 the files under those directories.
7380 The @option{--no-recursion} option also affects how globbing patterns
7381 are interpreted (@pxref{controlling pattern-matching}).
7383 The @option{--no-recursion} and @option{--recursion} options apply to
7384 later options and operands, and can be overridden by later occurrences
7385 of @option{--no-recursion} and @option{--recursion}. For example:
7388 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7392 creates an archive with one entry for @file{grape}, and the recursive
7393 contents of @file{grape/concord}, but no entries under @file{grape}
7394 other than @file{grape/concord}.
7397 @section Crossing File System Boundaries
7398 @cindex File system boundaries, not crossing
7401 @command{tar} will normally automatically cross file system boundaries in
7402 order to archive files which are part of a directory tree. You can
7403 change this behavior by running @command{tar} and specifying
7404 @option{--one-file-system}. This option only affects files that are
7405 archived because they are in a directory that is being archived;
7406 @command{tar} will still archive files explicitly named on the command line
7407 or through @option{--files-from}, regardless of where they reside.
7410 @opindex one-file-system
7411 @item --one-file-system
7412 Prevents @command{tar} from crossing file system boundaries when
7413 archiving. Use in conjunction with any write operation.
7416 The @option{--one-file-system} option causes @command{tar} to modify its
7417 normal behavior in archiving the contents of directories. If a file in
7418 a directory is not on the same file system as the directory itself, then
7419 @command{tar} will not archive that file. If the file is a directory
7420 itself, @command{tar} will not archive anything beneath it; in other words,
7421 @command{tar} will not cross mount points.
7423 This option is useful for making full or incremental archival backups of
7424 a file system. If this option is used in conjunction with
7425 @option{--verbose} (@option{-v}), files that are excluded are
7426 mentioned by name on the standard error.
7429 * directory:: Changing Directory
7430 * absolute:: Absolute File Names
7434 @subsection Changing the Working Directory
7436 @FIXME{need to read over this node now for continuity; i've switched
7437 things around some.}
7439 @cindex Changing directory mid-stream
7440 @cindex Directory, changing mid-stream
7441 @cindex Working directory, specifying
7442 To change the working directory in the middle of a list of file names,
7443 either on the command line or in a file specified using
7444 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7445 This will change the working directory to the specified directory
7446 after that point in the list.
7450 @item --directory=@var{directory}
7451 @itemx -C @var{directory}
7452 Changes the working directory in the middle of a command line.
7458 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7462 will place the files @file{grape} and @file{prune} from the current
7463 directory into the archive @file{jams.tar}, followed by the file
7464 @file{cherry} from the directory @file{food}. This option is especially
7465 useful when you have several widely separated files that you want to
7466 store in the same archive.
7468 Note that the file @file{cherry} is recorded in the archive under the
7469 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7470 archive will contain three files that all appear to have come from the
7471 same directory; if the archive is extracted with plain @samp{tar
7472 --extract}, all three files will be written in the current directory.
7474 Contrast this with the command,
7477 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7481 which records the third file in the archive under the name
7482 @file{red/cherry} so that, if the archive is extracted using
7483 @samp{tar --extract}, the third file will be written in a subdirectory
7484 named @file{orange-colored}.
7486 You can use the @option{--directory} option to make the archive
7487 independent of the original name of the directory holding the files.
7488 The following command places the files @file{/etc/passwd},
7489 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7493 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7497 However, the names of the archive members will be exactly what they were
7498 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7499 They will not appear to be related by file name to the original
7500 directories where those files were located.
7502 Note that @option{--directory} options are interpreted consecutively. If
7503 @option{--directory} specifies a relative file name, it is interpreted
7504 relative to the then current directory, which might not be the same as
7505 the original current working directory of @command{tar}, due to a previous
7506 @option{--directory} option.
7508 When using @option{--files-from} (@pxref{files}), you can put various
7509 @command{tar} options (including @option{-C}) in the file list. Notice,
7510 however, that in this case the option and its argument may not be
7511 separated by whitespace. If you use short option, its argument must
7512 either follow the option letter immediately, without any intervening
7513 whitespace, or occupy the next line. Otherwise, if you use long
7514 option, separate its argument by an equal sign.
7516 For instance, the file list for the above example will be:
7529 To use it, you would invoke @command{tar} as follows:
7532 $ @kbd{tar -c -f foo.tar --files-from list}
7535 The interpretation of @option{--directory} is disabled by
7536 @option{--null} option.
7539 @subsection Absolute File Names
7543 @opindex absolute-names
7544 @item --absolute-names
7546 Do not strip leading slashes from file names, and permit file names
7547 containing a @file{..} file name component.
7550 By default, @GNUTAR{} drops a leading @samp{/} on
7551 input or output, and complains about file names containing a @file{..}
7552 component. This option turns off this behavior.
7554 When @command{tar} extracts archive members from an archive, it strips any
7555 leading slashes (@samp{/}) from the member name. This causes absolute
7556 member names in the archive to be treated as relative file names. This
7557 allows you to have such members extracted wherever you want, instead of
7558 being restricted to extracting the member in the exact directory named
7559 in the archive. For example, if the archive member has the name
7560 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7561 really @file{etc/passwd}.
7563 File names containing @file{..} can cause problems when extracting, so
7564 @command{tar} normally warns you about such files when creating an
7565 archive, and rejects attempts to extracts such files.
7567 Other @command{tar} programs do not do this. As a result, if you
7568 create an archive whose member names start with a slash, they will be
7569 difficult for other people with a non-@GNUTAR{}
7570 program to use. Therefore, @GNUTAR{} also strips
7571 leading slashes from member names when putting members into the
7572 archive. For example, if you ask @command{tar} to add the file
7573 @file{/bin/ls} to an archive, it will do so, but the member name will
7574 be @file{bin/ls}.@footnote{A side effect of this is that when
7575 @option{--create} is used with @option{--verbose} the resulting output
7576 is not, generally speaking, the same as the one you'd get running
7577 @kbd{tar --list} command. This may be important if you use some
7578 scripts for comparing both outputs. @xref{listing member and file names},
7579 for the information on how to handle this case.}
7581 If you use the @option{--absolute-names} (@option{-P}) option,
7582 @command{tar} will do none of these transformations.
7584 To archive or extract files relative to the root directory, specify
7585 the @option{--absolute-names} (@option{-P}) option.
7587 Normally, @command{tar} acts on files relative to the working
7588 directory---ignoring superior directory names when archiving, and
7589 ignoring leading slashes when extracting.
7591 When you specify @option{--absolute-names} (@option{-P}),
7592 @command{tar} stores file names including all superior directory
7593 names, and preserves leading slashes. If you only invoked
7594 @command{tar} from the root directory you would never need the
7595 @option{--absolute-names} option, but using this option
7596 may be more convenient than switching to root.
7598 @FIXME{Should be an example in the tutorial/wizardry section using this
7599 to transfer files between systems.}
7601 @FIXME{Is write access an issue?}
7604 @item --absolute-names
7605 Preserves full file names (including superior directory names) when
7606 archiving files. Preserves leading slash when extracting files.
7610 @FIXME{this is still horrible; need to talk with dan on monday.}
7612 @command{tar} prints out a message about removing the @samp{/} from
7613 file names. This message appears once per @GNUTAR{}
7614 invocation. It represents something which ought to be told; ignoring
7615 what it means can cause very serious surprises, later.
7617 Some people, nevertheless, do not want to see this message. Wanting to
7618 play really dangerously, one may of course redirect @command{tar} standard
7619 error to the sink. For example, under @command{sh}:
7622 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7626 Another solution, both nicer and simpler, would be to change to
7627 the @file{/} directory first, and then avoid absolute notation.
7631 $ @kbd{(cd / && tar -c -f archive.tar home)}
7633 $ @kbd{tar -c -f archive.tar -C / home}
7636 @include getdate.texi
7639 @chapter Controlling the Archive Format
7641 @cindex Tar archive formats
7642 Due to historical reasons, there are several formats of tar archives.
7643 All of them are based on the same principles, but have some subtle
7644 differences that often make them incompatible with each other.
7646 GNU tar is able to create and handle archives in a variety of formats.
7647 The most frequently used formats are (in alphabetical order):
7651 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7652 from an early @acronym{POSIX} standard, adding some improvements such as
7653 sparse file handling and incremental archives. Unfortunately these
7654 features were implemented in a way incompatible with other archive
7657 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7661 Format used by @GNUTAR{} of versions prior to 1.12.
7664 Archive format, compatible with the V7 implementation of tar. This
7665 format imposes a number of limitations. The most important of them
7669 @item The maximum length of a file name is limited to 99 characters.
7670 @item The maximum length of a symbolic link is limited to 99 characters.
7671 @item It is impossible to store special files (block and character
7672 devices, fifos etc.)
7673 @item Maximum value of user or group ID is limited to 2097151 (7777777
7675 @item V7 archives do not contain symbolic ownership information (user
7676 and group name of the file owner).
7679 This format has traditionally been used by Automake when producing
7680 Makefiles. This practice will change in the future, in the meantime,
7681 however this means that projects containing filenames more than 99
7682 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7683 Automake prior to 1.9.
7686 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7687 symbolic ownership information. It is also able to store
7688 special files. However, it imposes several restrictions as well:
7691 @item The maximum length of a file name is limited to 256 characters,
7692 provided that the filename can be split at directory separator in
7693 two parts, first of them being at most 155 bytes long. So, in most
7694 cases the maximum file name length will be shorter than 256
7696 @item The maximum length of a symbolic link name is limited to
7698 @item Maximum size of a file the archive is able to accommodate
7700 @item Maximum value of UID/GID is 2097151.
7701 @item Maximum number of bits in device major and minor numbers is 21.
7705 Format used by J@"org Schilling @command{star}
7706 implementation. @GNUTAR{} is able to read @samp{star} archives but
7707 currently does not produce them.
7710 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7711 most flexible and feature-rich format. It does not impose any
7712 restrictions on file sizes or filename lengths. This format is quite
7713 recent, so not all tar implementations are able to handle it properly.
7714 However, this format is designed in such a way that any tar
7715 implementation able to read @samp{ustar} archives will be able to read
7716 most @samp{posix} archives as well, with the only exception that any
7717 additional information (such as long file names etc.) will in such
7718 case be extracted as plain text files along with the files it refers to.
7720 This archive format will be the default format for future versions
7725 The following table summarizes the limitations of each of these
7728 @multitable @columnfractions .10 .20 .20 .20 .20
7729 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7730 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7731 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7732 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7733 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7734 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7737 The default format for @GNUTAR{} is defined at compilation
7738 time. You may check it by running @command{tar --help}, and examining
7739 the last lines of its output. Usually, @GNUTAR{} is configured
7740 to create archives in @samp{gnu} format, however, future version will
7741 switch to @samp{posix}.
7744 * Compression:: Using Less Space through Compression
7745 * Attributes:: Handling File Attributes
7746 * Portability:: Making @command{tar} Archives More Portable
7747 * cpio:: Comparison of @command{tar} and @command{cpio}
7751 @section Using Less Space through Compression
7754 * gzip:: Creating and Reading Compressed Archives
7755 * sparse:: Archiving Sparse Files
7759 @subsection Creating and Reading Compressed Archives
7760 @cindex Compressed archives
7761 @cindex Storing archives in compressed format
7763 @GNUTAR{} is able to create and read compressed archives. It supports
7764 @command{gzip} and @command{bzip2} compression programs. For backward
7765 compatibility, it also supports @command{compress} command, although
7766 we strongly recommend against using it, since there is a patent
7767 covering the algorithm it uses and you could be sued for patent
7768 infringement merely by running @command{compress}! Besides, it is less
7769 effective than @command{gzip} and @command{bzip2}.
7771 Creating a compressed archive is simple: you just specify a
7772 @dfn{compression option} along with the usual archive creation
7773 commands. The compression option is @option{-z} (@option{--gzip}) to
7774 create a @command{gzip} compressed archive, @option{-j}
7775 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
7776 @option{-Z} (@option{--compress}) to use @command{compress} program.
7780 $ @kbd{tar cfz archive.tar.gz .}
7783 Reading compressed archive is even simpler: you don't need to specify
7784 any additional options as @GNUTAR{} recognizes its format
7785 automatically. Thus, the following commands will list and extract the
7786 archive created in previous example:
7789 # List the compressed archive
7790 $ @kbd{tar tf archive.tar.gz}
7791 # Extract the compressed archive
7792 $ @kbd{tar xf archive.tar.gz}
7795 The only case when you have to specify a decompression option while
7796 reading the archive is when reading from a pipe or from a tape drive
7797 that does not support random access. However, in this case @GNUTAR{}
7798 will indicate which option you should use. For example:
7801 $ @kbd{cat archive.tar.gz | tar tf -}
7802 tar: Archive is compressed. Use -z option
7803 tar: Error is not recoverable: exiting now
7806 If you see such diagnostics, just add the suggested option to the
7807 invocation of @GNUTAR{}:
7810 $ @kbd{cat archive.tar.gz | tar tfz -}
7813 Notice also, that there are several restrictions on operations on
7814 compressed archives. First of all, compressed archives cannot be
7815 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
7816 (@option{--delete}) members from them. Likewise, you cannot append
7817 another @command{tar} archive to a compressed archive using
7818 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
7821 The following table summarizes compression options used by @GNUTAR{}.
7829 Filter the archive through @command{gzip}.
7831 You can use @option{--gzip} and @option{--gunzip} on physical devices
7832 (tape drives, etc.) and remote files as well as on normal files; data
7833 to or from such devices or remote files is reblocked by another copy
7834 of the @command{tar} program to enforce the specified (or default) record
7835 size. The default compression parameters are used; if you need to
7836 override them, set @env{GZIP} environment variable, e.g.:
7839 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
7843 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
7844 @command{gzip} explicitly:
7847 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
7850 @cindex corrupted archives
7851 About corrupted compressed archives: @command{gzip}'ed files have no
7852 redundancy, for maximum compression. The adaptive nature of the
7853 compression scheme means that the compression tables are implicitly
7854 spread all over the archive. If you lose a few blocks, the dynamic
7855 construction of the compression tables becomes unsynchronized, and there
7856 is little chance that you could recover later in the archive.
7858 There are pending suggestions for having a per-volume or per-file
7859 compression in @GNUTAR{}. This would allow for viewing the
7860 contents without decompression, and for resynchronizing decompression at
7861 every volume or file, in case of corrupted archives. Doing so, we might
7862 lose some compressibility. But this would have make recovering easier.
7863 So, there are pros and cons. We'll see!
7868 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
7875 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
7877 The @acronym{GNU} Project recommends you not use
7878 @command{compress}, because there is a patent covering the algorithm it
7879 uses. You could be sued for patent infringement merely by running
7882 @opindex use-compress-program
7883 @item --use-compress-program=@var{prog}
7884 Use external compression program @var{prog}. Use this option if you
7885 have a compression program that @GNUTAR{} does not support. There
7886 are two requirements to which @var{prog} should comply:
7888 First, when called without options, it should read data from standard
7889 input, compress it and output it on standard output.
7891 Secondly, if called with @option{-d} argument, it should do exactly
7892 the opposite, i.e., read the compressed data from the standard input
7893 and produce uncompressed data on the standard output.
7896 @cindex gpg, using with tar
7897 @cindex gnupg, using with tar
7898 @cindex Using encrypted archives
7899 The @option{--use-compress-program} option, in particular, lets you
7900 implement your own filters, not necessarily dealing with
7901 compression/decompression. For example, suppose you wish to implement
7902 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
7903 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
7904 Manual}). The following script does that:
7910 -d) gpg --decrypt - | gzip -d -c;;
7911 '') gzip -c | gpg -s ;;
7912 *) echo "Unknown option $1">&2; exit 1;;
7917 Suppose you name it @file{gpgz} and save it somewhere in your
7918 @env{PATH}. Then the following command will create a compressed
7919 archive signed with your private key:
7922 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
7926 Likewise, the following command will list its contents:
7929 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
7933 The above is based on the following discussion:
7935 I have one question, or maybe it's a suggestion if there isn't a way
7936 to do it now. I would like to use @option{--gzip}, but I'd also like
7937 the output to be fed through a program like @acronym{GNU}
7938 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
7939 to use :-)), basically adding ECC protection on top of compression.
7940 It seems as if this should be quite easy to do, but I can't work out
7941 exactly how to go about it. Of course, I can pipe the standard output
7942 of @command{tar} through @command{ecc}, but then I lose (though I
7943 haven't started using it yet, I confess) the ability to have
7944 @command{tar} use @command{rmt} for it's I/O (I think).
7946 I think the most straightforward thing would be to let me specify a
7947 general set of filters outboard of compression (preferably ordered,
7948 so the order can be automatically reversed on input operations, and
7949 with the options they require specifiable), but beggars shouldn't be
7950 choosers and anything you decide on would be fine with me.
7952 By the way, I like @command{ecc} but if (as the comments say) it can't
7953 deal with loss of block sync, I'm tempted to throw some time at adding
7954 that capability. Supposing I were to actually do such a thing and
7955 get it (apparently) working, do you accept contributed changes to
7956 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
7958 Isn't that exactly the role of the
7959 @option{--use-compress-prog=@var{program}} option?
7960 I never tried it myself, but I suspect you may want to write a
7961 @var{prog} script or program able to filter stdin to stdout to
7962 way you want. It should recognize the @option{-d} option, for when
7963 extraction is needed rather than creation.
7965 It has been reported that if one writes compressed data (through the
7966 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
7967 the DLT compression mode, the data will actually get bigger and one will
7968 end up with less space on the tape.
7972 @subsection Archiving Sparse Files
7973 @cindex Sparse Files
7975 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
7976 in a file is a section of the file's contents which was never written.
7977 The contents of a hole reads as all zeros. On many operating systems,
7978 actual disk storage is not allocated for holes, but they are counted
7979 in the length of the file. If you archive such a file, @command{tar}
7980 could create an archive longer than the original. To have @command{tar}
7981 attempt to recognize the holes in a file, use @option{--sparse}
7982 (@option{-S}). When you use this option, then, for any file using
7983 less disk space than would be expected from its length, @command{tar}
7984 searches the file for consecutive stretches of zeros. It then records
7985 in the archive for the file where the consecutive stretches of zeros
7986 are, and only archives the ``real contents'' of the file. On
7987 extraction (using @option{--sparse} is not needed on extraction) any
7988 such files have holes created wherever the continuous stretches of zeros
7989 were found. Thus, if you use @option{--sparse}, @command{tar} archives
7990 won't take more space than the original.
7996 This option instructs @command{tar} to test each file for sparseness
7997 before attempting to archive it. If the file is found to be sparse it
7998 is treated specially, thus allowing to decrease the amount of space
7999 used by its image in the archive.
8001 This option is meaningful only when creating or updating archives. It
8002 has no effect on extraction.
8005 Consider using @option{--sparse} when performing file system backups,
8006 to avoid archiving the expanded forms of files stored sparsely in the
8009 Even if your system has no sparse files currently, some may be
8010 created in the future. If you use @option{--sparse} while making file
8011 system backups as a matter of course, you can be assured the archive
8012 will never take more space on the media than the files take on disk
8013 (otherwise, archiving a disk filled with sparse files might take
8014 hundreds of tapes). @xref{Incremental Dumps}.
8016 However, be aware that @option{--sparse} option presents a serious
8017 drawback. Namely, in order to determine if the file is sparse
8018 @command{tar} has to read it before trying to archive it, so in total
8019 the file is read @strong{twice}. So, always bear in mind that the
8020 time needed to process all files with this option is roughly twice
8021 the time needed to archive them without it.
8022 @FIXME{A technical note:
8024 Programs like @command{dump} do not have to read the entire file; by
8025 examining the file system directly, they can determine in advance
8026 exactly where the holes are and thus avoid reading through them. The
8027 only data it need read are the actual allocated data blocks.
8028 @GNUTAR{} uses a more portable and straightforward
8029 archiving approach, it would be fairly difficult that it does
8030 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8034 What I did say is that you cannot tell the difference between a hole and an
8035 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8036 best tells you how many holes there are; it doesn't tell you @emph{where}.
8037 Just as programs may, conceivably, care what @code{st_blocks} is (care
8038 to name one that does?), they may also care where the holes are (I have
8039 no examples of this one either, but it's equally imaginable).
8041 I conclude from this that good archivers are not portable. One can
8042 arguably conclude that if you want a portable program, you can in good
8043 conscience restore files with as many holes as possible, since you can't
8048 @cindex sparse formats, defined
8049 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
8050 sparse files using in three distinct ways, called @dfn{sparse
8051 formats}. A sparse format is identified by its @dfn{number},
8052 consisting, as usual of two decimal numbers, delimited by a dot. By
8053 default, format @samp{1.0} is used. If, for some reason, you wish to
8054 use an earlier format, you can select it using
8055 @option{--sparse-version} option.
8058 @opindex sparse-version
8059 @item --sparse-version=@var{version}
8061 Select the format to store sparse files in. Valid @var{version} values
8062 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
8063 for a detailed description of each format.
8066 Using @option{--sparse-format} option implies @option{--sparse}.
8069 @section Handling File Attributes
8072 When @command{tar} reads files, it updates their access times. To
8073 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8074 reset the access time retroactively or avoid changing it in the first
8077 Handling of file attributes
8080 @opindex atime-preserve
8081 @item --atime-preserve
8082 @itemx --atime-preserve=replace
8083 @itemx --atime-preserve=system
8084 Preserve the access times of files that are read. This works only for
8085 files that you own, unless you have superuser privileges.
8087 @option{--atime-preserve=replace} works on most systems, but it also
8088 restores the data modification time and updates the status change
8089 time. Hence it doesn't interact with incremental dumps nicely
8090 (@pxref{Incremental Dumps}), and it can set access or data modification times
8091 incorrectly if other programs access the file while @command{tar} is
8094 @option{--atime-preserve=system} avoids changing the access time in
8095 the first place, if the operating system supports this.
8096 Unfortunately, this may or may not work on any given operating system
8097 or file system. If @command{tar} knows for sure it won't work, it
8098 complains right away.
8100 Currently @option{--atime-preserve} with no operand defaults to
8101 @option{--atime-preserve=replace}, but this is intended to change to
8102 @option{--atime-preserve=system} when the latter is better-supported.
8107 Do not extract data modification time.
8109 When this option is used, @command{tar} leaves the data modification times
8110 of the files it extracts as the times when the files were extracted,
8111 instead of setting it to the times recorded in the archive.
8113 This option is meaningless with @option{--list} (@option{-t}).
8117 Create extracted files with the same ownership they have in the
8120 This is the default behavior for the superuser,
8121 so this option is meaningful only for non-root users, when @command{tar}
8122 is executed on those systems able to give files away. This is
8123 considered as a security flaw by many people, at least because it
8124 makes quite difficult to correctly account users for the disk space
8125 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8126 files are easily and silently lost when files are given away.
8128 When writing an archive, @command{tar} writes the user id and user name
8129 separately. If it can't find a user name (because the user id is not
8130 in @file{/etc/passwd}), then it does not write one. When restoring,
8131 it tries to look the name (if one was written) up in
8132 @file{/etc/passwd}. If it fails, then it uses the user id stored in
8133 the archive instead.
8135 @opindex no-same-owner
8136 @item --no-same-owner
8138 Do not attempt to restore ownership when extracting. This is the
8139 default behavior for ordinary users, so this option has an effect
8140 only for the superuser.
8142 @opindex numeric-owner
8143 @item --numeric-owner
8144 The @option{--numeric-owner} option allows (ANSI) archives to be written
8145 without user/group name information or such information to be ignored
8146 when extracting. It effectively disables the generation and/or use
8147 of user/group name information. This option forces extraction using
8148 the numeric ids from the archive, ignoring the names.
8150 This is useful in certain circumstances, when restoring a backup from
8151 an emergency floppy with different passwd/group files for example.
8152 It is otherwise impossible to extract files with the right ownerships
8153 if the password file in use during the extraction does not match the
8154 one belonging to the file system(s) being extracted. This occurs,
8155 for example, if you are restoring your files after a major crash and
8156 had booted from an emergency floppy with no password file or put your
8157 disk into another machine to do the restore.
8159 The numeric ids are @emph{always} saved into @command{tar} archives.
8160 The identifying names are added at create time when provided by the
8161 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8162 used when moving archives between a collection of machines using
8163 a centralized management for attribution of numeric ids to users
8164 and groups. This is often made through using the NIS capabilities.
8166 When making a @command{tar} file for distribution to other sites, it
8167 is sometimes cleaner to use a single owner for all files in the
8168 distribution, and nicer to specify the write permission bits of the
8169 files as stored in the archive independently of their actual value on
8170 the file system. The way to prepare a clean distribution is usually
8171 to have some Makefile rule creating a directory, copying all needed
8172 files in that directory, then setting ownership and permissions as
8173 wanted (there are a lot of possible schemes), and only then making a
8174 @command{tar} archive out of this directory, before cleaning
8175 everything out. Of course, we could add a lot of options to
8176 @GNUTAR{} for fine tuning permissions and ownership.
8177 This is not the good way, I think. @GNUTAR{} is
8178 already crowded with options and moreover, the approach just explained
8179 gives you a great deal of control already.
8181 @xopindex{same-permissions, short description}
8182 @xopindex{preserve-permissions, short description}
8184 @itemx --same-permissions
8185 @itemx --preserve-permissions
8186 Extract all protection information.
8188 This option causes @command{tar} to set the modes (access permissions) of
8189 extracted files exactly as recorded in the archive. If this option
8190 is not used, the current @code{umask} setting limits the permissions
8191 on extracted files. This option is by default enabled when
8192 @command{tar} is executed by a superuser.
8195 This option is meaningless with @option{--list} (@option{-t}).
8199 Same as both @option{--same-permissions} and @option{--same-order}.
8201 The @option{--preserve} option has no equivalent short option name.
8202 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8204 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8205 Neither do I. --Sergey}
8210 @section Making @command{tar} Archives More Portable
8212 Creating a @command{tar} archive on a particular system that is meant to be
8213 useful later on many other machines and with other versions of @command{tar}
8214 is more challenging than you might think. @command{tar} archive formats
8215 have been evolving since the first versions of Unix. Many such formats
8216 are around, and are not always compatible with each other. This section
8217 discusses a few problems, and gives some advice about making @command{tar}
8218 archives more portable.
8220 One golden rule is simplicity. For example, limit your @command{tar}
8221 archives to contain only regular files and directories, avoiding
8222 other kind of special files. Do not attempt to save sparse files or
8223 contiguous files as such. Let's discuss a few more problems, in turn.
8225 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
8226 archives and archive labels) in GNU and PAX formats.}
8229 * Portable Names:: Portable Names
8230 * dereference:: Symbolic Links
8231 * old:: Old V7 Archives
8232 * ustar:: Ustar Archives
8233 * gnu:: GNU and old GNU format archives.
8234 * posix:: @acronym{POSIX} archives
8235 * Checksumming:: Checksumming Problems
8236 * Large or Negative Values:: Large files, negative time stamps, etc.
8237 * Other Tars:: How to Extract GNU-Specific Data Using
8238 Other @command{tar} Implementations
8241 @node Portable Names
8242 @subsection Portable Names
8244 Use portable file and member names. A name is portable if it contains
8245 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
8246 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
8247 contain @samp{/-}. Avoid deep directory nesting. For portability to
8248 old Unix hosts, limit your file name components to 14 characters or
8251 If you intend to have your @command{tar} archives to be read under
8252 MSDOS, you should not rely on case distinction for file names, and you
8253 might use the @acronym{GNU} @command{doschk} program for helping you
8254 further diagnosing illegal MSDOS names, which are even more limited
8258 @subsection Symbolic Links
8259 @cindex File names, using symbolic links
8260 @cindex Symbolic link as file name
8262 @opindex dereference
8263 Normally, when @command{tar} archives a symbolic link, it writes a
8264 block to the archive naming the target of the link. In that way, the
8265 @command{tar} archive is a faithful record of the file system contents.
8266 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
8267 @command{tar} to archive the files symbolic links point to, instead of
8268 the links themselves. When this option is used, when @command{tar}
8269 encounters a symbolic link, it will archive the linked-to file,
8270 instead of simply recording the presence of a symbolic link.
8272 The name under which the file is stored in the file system is not
8273 recorded in the archive. To record both the symbolic link name and
8274 the file name in the system, archive the file under both names. If
8275 all links were recorded automatically by @command{tar}, an extracted file
8276 might be linked to a file name that no longer exists in the file
8279 If a linked-to file is encountered again by @command{tar} while creating
8280 the same archive, an entire second copy of it will be stored. (This
8281 @emph{might} be considered a bug.)
8283 So, for portable archives, do not archive symbolic links as such,
8284 and use @option{--dereference} (@option{-h}): many systems do not support
8285 symbolic links, and moreover, your distribution might be unusable if
8286 it contains unresolved symbolic links.
8289 @subsection Old V7 Archives
8290 @cindex Format, old style
8291 @cindex Old style format
8292 @cindex Old style archives
8293 @cindex v7 archive format
8295 Certain old versions of @command{tar} cannot handle additional
8296 information recorded by newer @command{tar} programs. To create an
8297 archive in V7 format (not ANSI), which can be read by these old
8298 versions, specify the @option{--format=v7} option in
8299 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
8300 accepts @option{--portability} or @option{--old-archive} for this
8301 option). When you specify it,
8302 @command{tar} leaves out information about directories, pipes, fifos,
8303 contiguous files, and device files, and specifies file ownership by
8304 group and user IDs instead of group and user names.
8306 When updating an archive, do not use @option{--format=v7}
8307 unless the archive was created using this option.
8309 In most cases, a @emph{new} format archive can be read by an @emph{old}
8310 @command{tar} program without serious trouble, so this option should
8311 seldom be needed. On the other hand, most modern @command{tar}s are
8312 able to read old format archives, so it might be safer for you to
8313 always use @option{--format=v7} for your distributions. Notice,
8314 however, that @samp{ustar} format is a better alternative, as it is
8315 free from many of @samp{v7}'s drawbacks.
8318 @subsection Ustar Archive Format
8320 @cindex ustar archive format
8321 Archive format defined by @acronym{POSIX}.1-1988 specification is called
8322 @code{ustar}. Although it is more flexible than the V7 format, it
8323 still has many restrictions (@xref{Formats,ustar}, for the detailed
8324 description of @code{ustar} format). Along with V7 format,
8325 @code{ustar} format is a good choice for archives intended to be read
8326 with other implementations of @command{tar}.
8328 To create archive in @code{ustar} format, use @option{--format=ustar}
8329 option in conjunction with the @option{--create} (@option{-c}).
8332 @subsection @acronym{GNU} and old @GNUTAR{} format
8334 @cindex GNU archive format
8335 @cindex Old GNU archive format
8336 @GNUTAR{} was based on an early draft of the
8337 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
8338 @command{tar}, such as the support for file names longer than 100
8339 characters, use portions of the @command{tar} header record which were
8340 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
8341 @acronym{POSIX} have allocated the same parts of the header record for
8342 other purposes. As a result, @GNUTAR{} format is
8343 incompatible with the current @acronym{POSIX} specification, and with
8344 @command{tar} programs that follow it.
8346 In the majority of cases, @command{tar} will be configured to create
8347 this format by default. This will change in the future releases, since
8348 we plan to make @samp{POSIX} format the default.
8350 To force creation a @GNUTAR{} archive, use option
8351 @option{--format=gnu}.
8354 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
8356 @cindex POSIX archive format
8357 @cindex PAX archive format
8358 Starting from version 1.14 @GNUTAR{} features full support for
8359 @acronym{POSIX.1-2001} archives.
8361 A @acronym{POSIX} conformant archive will be created if @command{tar}
8362 was given @option{--format=posix} (@option{--format=pax}) option. No
8363 special option is required to read and extract from a @acronym{POSIX}
8367 * PAX keywords:: Controlling Extended Header Keywords.
8371 @subsubsection Controlling Extended Header Keywords
8375 @item --pax-option=@var{keyword-list}
8376 Handle keywords in @acronym{PAX} extended headers. This option is
8377 equivalent to @option{-o} option of the @command{pax} utility.
8380 @var{Keyword-list} is a comma-separated
8381 list of keyword options, each keyword option taking one of
8382 the following forms:
8385 @item delete=@var{pattern}
8386 When used with one of archive-creation commands,
8387 this option instructs @command{tar} to omit from extended header records
8388 that it produces any keywords matching the string @var{pattern}.
8390 When used in extract or list mode, this option instructs tar
8391 to ignore any keywords matching the given @var{pattern} in the extended
8392 header records. In both cases, matching is performed using the pattern
8393 matching notation described in @acronym{POSIX 1003.2}, 3.13
8394 (@pxref{wildcards}). For example:
8397 --pax-option delete=security.*
8400 would suppress security-related information.
8402 @item exthdr.name=@var{string}
8404 This keyword allows user control over the name that is written into the
8405 ustar header blocks for the extended headers. The name is obtained
8406 from @var{string} after making the following substitutions:
8408 @multitable @columnfractions .25 .55
8409 @headitem Meta-character @tab Replaced By
8410 @item %d @tab The directory name of the file, equivalent to the
8411 result of the @command{dirname} utility on the translated pathname.
8412 @item %f @tab The filename of the file, equivalent to the result
8413 of the @command{basename} utility on the translated pathname.
8414 @item %p @tab The process ID of the @command{tar} process.
8415 @item %% @tab A @samp{%} character.
8418 Any other @samp{%} characters in @var{string} produce undefined
8421 If no option @samp{exthdr.name=string} is specified, @command{tar}
8422 will use the following default value:
8428 @item globexthdr.name=@var{string}
8429 This keyword allows user control over the name that is written into
8430 the ustar header blocks for global extended header records. The name
8431 is obtained from the contents of @var{string}, after making
8432 the following substitutions:
8434 @multitable @columnfractions .25 .55
8435 @headitem Meta-character @tab Replaced By
8436 @item %n @tab An integer that represents the
8437 sequence number of the global extended header record in the archive,
8439 @item %p @tab The process ID of the @command{tar} process.
8440 @item %% @tab A @samp{%} character.
8443 Any other @samp{%} characters in @var{string} produce undefined results.
8445 If no option @samp{globexthdr.name=string} is specified, @command{tar}
8446 will use the following default value:
8449 $TMPDIR/GlobalHead.%p.%n
8453 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
8454 environment variable. If @var{TMPDIR} is not set, @command{tar}
8457 @item @var{keyword}=@var{value}
8458 When used with one of archive-creation commands, these keyword/value pairs
8459 will be included at the beginning of the archive in a global extended
8460 header record. When used with one of archive-reading commands,
8461 @command{tar} will behave as if it has encountered these keyword/value
8462 pairs at the beginning of the archive in a global extended header
8465 @item @var{keyword}:=@var{value}
8466 When used with one of archive-creation commands, these keyword/value pairs
8467 will be included as records at the beginning of an extended header for
8468 each file. This is effectively equivalent to @var{keyword}=@var{value}
8469 form except that it creates no global extended header records.
8471 When used with one of archive-reading commands, @command{tar} will
8472 behave as if these keyword/value pairs were included as records at the
8473 end of each extended header; thus, they will override any global or
8474 file-specific extended header record keywords of the same names.
8475 For example, in the command:
8478 tar --format=posix --create \
8479 --file archive --pax-option gname:=user .
8482 the group name will be forced to a new value for all files
8483 stored in the archive.
8487 @subsection Checksumming Problems
8489 SunOS and HP-UX @command{tar} fail to accept archives created using
8490 @GNUTAR{} and containing non-ASCII file names, that
8491 is, file names having characters with the eight bit set, because they
8492 use signed checksums, while @GNUTAR{} uses unsigned
8493 checksums while creating archives, as per @acronym{POSIX} standards. On
8494 reading, @GNUTAR{} computes both checksums and
8495 accept any. It is somewhat worrying that a lot of people may go
8496 around doing backup of their files using faulty (or at least
8497 non-standard) software, not learning about it until it's time to
8498 restore their missing files with an incompatible file extractor, or
8501 @GNUTAR{} compute checksums both ways, and accept
8502 any on read, so @acronym{GNU} tar can read Sun tapes even with their
8503 wrong checksums. @GNUTAR{} produces the standard
8504 checksum, however, raising incompatibilities with Sun. That is to
8505 say, @GNUTAR{} has not been modified to
8506 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
8507 I've been told that more recent Sun @command{tar} now read standard
8508 archives, so maybe Sun did a similar patch, after all?
8510 The story seems to be that when Sun first imported @command{tar}
8511 sources on their system, they recompiled it without realizing that
8512 the checksums were computed differently, because of a change in
8513 the default signing of @code{char}'s in their compiler. So they
8514 started computing checksums wrongly. When they later realized their
8515 mistake, they merely decided to stay compatible with it, and with
8516 themselves afterwards. Presumably, but I do not really know, HP-UX
8517 has chosen that their @command{tar} archives to be compatible with Sun's.
8518 The current standards do not favor Sun @command{tar} format. In any
8519 case, it now falls on the shoulders of SunOS and HP-UX users to get
8520 a @command{tar} able to read the good archives they receive.
8522 @node Large or Negative Values
8523 @subsection Large or Negative Values
8524 @cindex large values
8525 @cindex future time stamps
8526 @cindex negative time stamps
8529 The above sections suggest to use @samp{oldest possible} archive
8530 format if in doubt. However, sometimes it is not possible. If you
8531 attempt to archive a file whose metadata cannot be represented using
8532 required format, @GNUTAR{} will print error message and ignore such a
8533 file. You will than have to switch to a format that is able to
8534 handle such values. The format summary table (@pxref{Formats}) will
8537 In particular, when trying to archive files larger than 8GB or with
8538 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
8539 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
8540 @acronym{POSIX} archive formats. When considering which format to
8541 choose, bear in mind that the @acronym{GNU} format uses
8542 two's-complement base-256 notation to store values that do not fit
8543 into standard @acronym{ustar} range. Such archives can generally be
8544 read only by a @GNUTAR{} implementation. Moreover, they sometimes
8545 cannot be correctly restored on another hosts even by @GNUTAR{}. For
8546 example, using two's complement representation for negative time
8547 stamps that assumes a signed 32-bit @code{time_t} generates archives
8548 that are not portable to hosts with differing @code{time_t}
8551 On the other hand, @acronym{POSIX} archives, generally speaking, can
8552 be extracted by any tar implementation that understands older
8553 @acronym{ustar} format. The only exception are files larger than 8GB.
8555 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
8559 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
8561 In previous sections you became acquainted with various quirks
8562 necessary to make your archives portable. Sometimes you may need to
8563 extract archives containing GNU-specific members using some
8564 third-party @command{tar} implementation or an older version of
8565 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
8566 but if it is for some reason impossible, this section will explain
8567 how to cope without it.
8569 When we speak about @dfn{GNU-specific} members we mean two classes of
8570 them: members split between the volumes of a multi-volume archive and
8571 sparse members. You will be able to always recover such members if
8572 the archive is in PAX format. In addition split members can be
8573 recovered from archives in old GNU format. The following subsections
8574 describe the required procedures in detail.
8577 * Split Recovery:: Members Split Between Volumes
8578 * Sparse Recovery:: Sparse Members
8581 @node Split Recovery
8582 @subsubsection Extracting Members Split Between Volumes
8584 @cindex Mutli-volume archives, extracting using non-GNU tars
8585 If a member is split between several volumes of an old GNU format archive
8586 most third party @command{tar} implementation will fail to extract
8587 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
8588 This program is available from
8589 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
8590 home page}. It concatenates several archive volumes into a single
8591 valid archive. For example, if you have three volumes named from
8592 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
8593 extract them using a third-party @command{tar}:
8596 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
8599 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
8600 You could use this approach for most (although not all) PAX
8601 format archives as well. However, extracting split members from a PAX
8602 archive is a much easier task, because PAX volumes are constructed in
8603 such a way that each part of a split member is extracted to a
8604 different file by @command{tar} implementations that are not aware of
8605 GNU extensions. More specifically, the very first part retains its
8606 original name, and all subsequent parts are named using the pattern:
8609 %d/GNUFileParts.%p/%f.%n
8613 where symbols preceeded by @samp{%} are @dfn{macro characters} that
8614 have the following meaning:
8616 @multitable @columnfractions .25 .55
8617 @headitem Meta-character @tab Replaced By
8618 @item %d @tab The directory name of the file, equivalent to the
8619 result of the @command{dirname} utility on its full name.
8620 @item %f @tab The file name of the file, equivalent to the result
8621 of the @command{basename} utility on its full name.
8622 @item %p @tab The process ID of the @command{tar} process that
8623 created the archive.
8624 @item %n @tab Ordinal number of this particular part.
8627 For example, if the file @file{var/longfile} was split during archive
8628 creation between three volumes, and the creator @command{tar} process
8629 had process ID @samp{27962}, then the member names will be:
8633 var/GNUFileParts.27962/longfile.1
8634 var/GNUFileParts.27962/longfile.2
8637 When you extract your archive using a third-party @command{tar}, these
8638 files will be created on your disk, and the only thing you will need
8639 to do to restore your file in its original form is concatenate them in
8640 the proper order, for example:
8645 $ @kbd{cat GNUFileParts.27962/longfile.1 \
8646 GNUFileParts.27962/longfile.2 >> longfile}
8647 $ rm -f GNUFileParts.27962
8651 Notice, that if the @command{tar} implementation you use supports PAX
8652 format archives, it will probably emit warnings about unknown keywords
8653 during extraction. They will look like this:
8658 Unknown extended header keyword 'GNU.volume.filename' ignored.
8659 Unknown extended header keyword 'GNU.volume.size' ignored.
8660 Unknown extended header keyword 'GNU.volume.offset' ignored.
8665 You can safely ignore these warnings.
8667 If your @command{tar} implementation is not PAX-aware, you will get
8668 more warnings and more files generated on your disk, e.g.:
8672 $ @kbd{tar xf vol-1.tar}
8673 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
8675 Unexpected EOF in archive
8676 $ @kbd{tar xf vol-2.tar}
8677 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
8678 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
8679 'x', extracted as normal file
8683 Ignore these warnings. The @file{PaxHeaders.*} directories created
8684 will contain files with @dfn{extended header keywords} describing the
8685 extracted files. You can delete them, unless they describe sparse
8686 members. Read further to learn more about them.
8688 @node Sparse Recovery
8689 @subsubsection Extracting Sparse Members
8691 @cindex sparse files, extracting with non-GNU tars
8692 Any @command{tar} implementation will be able to extract sparse members from a
8693 PAX archive. However, the extracted files will be @dfn{condensed},
8694 i.e., any zero blocks will be removed from them. When we restore such
8695 a condensed file to its original form, by adding zero bloks (or
8696 @dfn{holes}) back to their original locations, we call this process
8697 @dfn{expanding} a compressed sparse file.
8700 To expand a file, you will need a simple auxiliary program called
8701 @command{xsparse}. It is available in source form from
8702 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
8705 @cindex sparse files v.1.0, extracting with non-GNU tars
8706 Let's begin with archive members in @dfn{sparse format
8707 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
8708 The condensed file will contain both file map and file data, so no
8709 additional data will be needed to restore it. If the original file
8710 name was @file{@var{dir}/@var{name}}, then the condensed file will be
8711 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
8712 @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
8713 @dfn{process ID} of the @command{tar} process which created the
8714 archive (@pxref{PAX keywords}).}.
8716 To expand a version 1.0 file, run @command{xsparse} as follows:
8719 $ @kbd{xsparse @file{cond-file}}
8723 where @file{cond-file} is the name of the condensed file. The utility
8724 will deduce the name for the resulting expanded file using the
8725 following algorithm:
8728 @item If @file{cond-file} does not contain any directories,
8729 @file{../cond-file} will be used;
8731 @item If @file{cond-file} has the form
8732 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
8733 are simple names, with no @samp{/} characters in them, the output file
8734 name will be @file{@var{dir}/@var{name}}.
8736 @item Otherwise, if @file{cond-file} has the form
8737 @file{@var{dir}/@var{name}}, the output file name will be
8741 In the unlikely case when this algorithm does not suite your needs,
8742 you can explicitly specify output file name as a second argument to
8746 $ @kbd{xsparse @file{cond-file} @file{out-file}}
8749 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
8750 first. In this mode, the command does not actually expand the file,
8751 but verbosely lists all actions it would be taking to do so. The dry
8752 run mode is enabled by @option{-n} command line argument:
8756 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
8757 Reading v.1.0 sparse map
8758 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8759 `/home/gray/sparsefile'
8764 To actually expand the file, you would run:
8767 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
8771 The program behaves the same way all UNIX utilities do: it will keep
8772 quiet unless it has simething important to tell you (e.g. an error
8773 condition or something). If you wish it to produce verbose output,
8774 similar to that from the dry run mode, use @option{-v} option:
8778 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
8779 Reading v.1.0 sparse map
8780 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8781 `/home/gray/sparsefile'
8786 Additionally, if your @command{tar} implementation has extracted the
8787 @dfn{extended headers} for this file, you can instruct @command{xstar}
8788 to use them in order to verify the integrity of the expanded file.
8789 The option @option{-x} sets the name of the extended header file to
8790 use. Continuing our example:
8794 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
8795 /home/gray/GNUSparseFile.6058/sparsefile}
8796 Reading extended header file
8797 Found variable GNU.sparse.major = 1
8798 Found variable GNU.sparse.minor = 0
8799 Found variable GNU.sparse.name = sparsefile
8800 Found variable GNU.sparse.realsize = 217481216
8801 Reading v.1.0 sparse map
8802 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8803 `/home/gray/sparsefile'
8808 @anchor{extracting sparse v.0.x}
8809 @cindex sparse files v.0.1, extracting with non-GNU tars
8810 @cindex sparse files v.0.0, extracting with non-GNU tars
8811 An @dfn{extended header} is a special @command{tar} archive header
8812 that precedes an archive member and contains a set of
8813 @dfn{variables}, describing the member properties that cannot be
8814 stored in the standard @code{ustar} header. While optional for
8815 expanding sparse version 1.0 members, use of extended headers is
8816 mandatory when expanding sparse members in older sparse formats: v.0.0
8817 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
8818 Formats}.) So, for this format, the question is: how to obtain
8819 extended headers from the archive?
8821 If you use a @command{tar} implementation that does not support PAX
8822 format, extended headers for each member will be extracted as a
8823 separate file. If we represent the member name as
8824 @file{@var{dir}/@var{name}}, then the extended header file will be
8825 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
8826 @var{n} is an integer number.
8828 Things become more difficult if your @command{tar} implementation
8829 does support PAX headers, because in this case you will have to
8830 manually extract the headers. We recommend the following algorithm:
8834 Consult the documentation of your @command{tar} implementation for an
8835 option that prints @dfn{block numbers} along with the archive
8836 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
8837 @command{star} has @option{-block-number}.
8840 Obtain verbose listing using the @samp{block number} option, and
8841 find block numbers of the sparse member in question and the member
8842 immediately following it. For example, running @command{star} on our
8847 $ @kbd{star -t -v -block-number -f arc.tar}
8849 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
8850 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
8851 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
8852 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
8853 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
8854 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
8860 (as usual, ignore the warnings about unknown keywords.)
8863 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
8864 and @var{Bn} be the block number of the next member.
8868 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
8872 This number gives the size of the extended header part in tar @dfn{blocks}.
8873 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
8877 Use @command{dd} to extract the headers:
8880 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
8884 where @var{archive} is the archive name, @var{hname} is a name of the
8885 file to store the extended header in, @var{Bs} and @var{N} are
8886 computed in previous steps.
8888 In our example, this command will be
8891 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
8895 Finally, you can expand the condensed file, using the obtained header:
8899 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
8900 Reading extended header file
8901 Found variable GNU.sparse.size = 217481216
8902 Found variable GNU.sparse.numblocks = 208
8903 Found variable GNU.sparse.name = sparsefile
8904 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
8905 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
8911 @section Comparison of @command{tar} and @command{cpio}
8914 @FIXME{Reorganize the following material}
8916 The @command{cpio} archive formats, like @command{tar}, do have maximum
8917 pathname lengths. The binary and old ASCII formats have a max path
8918 length of 256, and the new ASCII and CRC ASCII formats have a max
8919 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8920 with arbitrary pathname lengths, but other @command{cpio} implementations
8921 may crash unexplainedly trying to read them.
8923 @command{tar} handles symbolic links in the form in which it comes in BSD;
8924 @command{cpio} doesn't handle symbolic links in the form in which it comes
8925 in System V prior to SVR4, and some vendors may have added symlinks
8926 to their system without enhancing @command{cpio} to know about them.
8927 Others may have enhanced it in a way other than the way I did it
8928 at Sun, and which was adopted by AT&T (and which is, I think, also
8929 present in the @command{cpio} that Berkeley picked up from AT&T and put
8930 into a later BSD release---I think I gave them my changes).
8932 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8933 can handle @command{tar} format input, and write it on output, and it
8934 probably handles symbolic links. They may not have bothered doing
8935 anything to enhance @command{tar} as a result.)
8937 @command{cpio} handles special files; traditional @command{tar} doesn't.
8939 @command{tar} comes with V7, System III, System V, and BSD source;
8940 @command{cpio} comes only with System III, System V, and later BSD
8941 (4.3-tahoe and later).
8943 @command{tar}'s way of handling multiple hard links to a file can handle
8944 file systems that support 32-bit inumbers (e.g., the BSD file system);
8945 @command{cpio}s way requires you to play some games (in its "binary"
8946 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8947 they're 18 bits---it would have to play games with the "file system ID"
8948 field of the header to make sure that the file system ID/i-number pairs
8949 of different files were always different), and I don't know which
8950 @command{cpio}s, if any, play those games. Those that don't might get
8951 confused and think two files are the same file when they're not, and
8952 make hard links between them.
8954 @command{tar}s way of handling multiple hard links to a file places only
8955 one copy of the link on the tape, but the name attached to that copy
8956 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8957 way puts one copy for every link, but you can retrieve it using any
8961 What type of check sum (if any) is used, and how is this calculated.
8964 See the attached manual pages for @command{tar} and @command{cpio} format.
8965 @command{tar} uses a checksum which is the sum of all the bytes in the
8966 @command{tar} header for a file; @command{cpio} uses no checksum.
8969 If anyone knows why @command{cpio} was made when @command{tar} was present
8973 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8974 generally-available version of UNIX had @command{tar} at the time. I don't
8975 know whether any version that was generally available @emph{within AT&T}
8976 had @command{tar}, or, if so, whether the people within AT&T who did
8977 @command{cpio} knew about it.
8979 On restore, if there is a corruption on a tape @command{tar} will stop at
8980 that point, while @command{cpio} will skip over it and try to restore the
8983 The main difference is just in the command syntax and header format.
8985 @command{tar} is a little more tape-oriented in that everything is blocked
8986 to start on a record boundary.
8989 Is there any differences between the ability to recover crashed
8990 archives between the two of them. (Is there any chance of recovering
8991 crashed archives at all.)
8994 Theoretically it should be easier under @command{tar} since the blocking
8995 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
8996 However, modern @command{cpio}'s and variations have an option to just
8997 search for the next file header after an error with a reasonable chance
8998 of resyncing. However, lots of tape driver software won't allow you to
8999 continue past a media error which should be the only reason for getting
9000 out of sync unless a file changed sizes while you were writing the
9004 If anyone knows why @command{cpio} was made when @command{tar} was present
9005 at the unix scene, please tell me about this too.
9008 Probably because it is more media efficient (by not blocking everything
9009 and using only the space needed for the headers where @command{tar}
9010 always uses 512 bytes per file header) and it knows how to archive
9013 You might want to look at the freely available alternatives. The
9014 major ones are @command{afio}, @GNUTAR{}, and
9015 @command{pax}, each of which have their own extensions with some
9016 backwards compatibility.
9018 Sparse files were @command{tar}red as sparse files (which you can
9019 easily test, because the resulting archive gets smaller, and
9020 @acronym{GNU} @command{cpio} can no longer read it).
9023 @chapter Tapes and Other Archive Media
9026 A few special cases about tape handling warrant more detailed
9027 description. These special cases are discussed below.
9029 Many complexities surround the use of @command{tar} on tape drives. Since
9030 the creation and manipulation of archives located on magnetic tape was
9031 the original purpose of @command{tar}, it contains many features making
9032 such manipulation easier.
9034 Archives are usually written on dismountable media---tape cartridges,
9035 mag tapes, or floppy disks.
9037 The amount of data a tape or disk holds depends not only on its size,
9038 but also on how it is formatted. A 2400 foot long reel of mag tape
9039 holds 40 megabytes of data when formatted at 1600 bits per inch. The
9040 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
9042 Magnetic media are re-usable---once the archive on a tape is no longer
9043 needed, the archive can be erased and the tape or disk used over.
9044 Media quality does deteriorate with use, however. Most tapes or disks
9045 should be discarded when they begin to produce data errors. EXABYTE
9046 tape cartridges should be discarded when they generate an @dfn{error
9047 count} (number of non-usable bits) of more than 10k.
9049 Magnetic media are written and erased using magnetic fields, and
9050 should be protected from such fields to avoid damage to stored data.
9051 Sticking a floppy disk to a filing cabinet using a magnet is probably
9055 * Device:: Device selection and switching
9056 * Remote Tape Server::
9057 * Common Problems and Solutions::
9058 * Blocking:: Blocking
9059 * Many:: Many archives on one tape
9060 * Using Multiple Tapes:: Using Multiple Tapes
9061 * label:: Including a Label in the Archive
9063 * Write Protection::
9067 @section Device Selection and Switching
9071 @item -f [@var{hostname}:]@var{file}
9072 @itemx --file=[@var{hostname}:]@var{file}
9073 Use archive file or device @var{file} on @var{hostname}.
9076 This option is used to specify the file name of the archive @command{tar}
9079 If the file name is @samp{-}, @command{tar} reads the archive from standard
9080 input (when listing or extracting), or writes it to standard output
9081 (when creating). If the @samp{-} file name is given when updating an
9082 archive, @command{tar} will read the original archive from its standard
9083 input, and will write the entire new archive to its standard output.
9085 If the file name contains a @samp{:}, it is interpreted as
9086 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
9087 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
9088 either case, @command{tar} will invoke the command @command{rsh} (or
9089 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
9090 machine. If you give an alternate login name, it will be given to the
9092 Naturally, the remote machine must have an executable
9093 @command{/usr/libexec/rmt}. This program is free software from the
9094 University of California, and a copy of the source code can be found
9095 with the sources for @command{tar}; it's compiled and installed by default.
9096 The exact path to this utility is determined when configuring the package.
9097 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
9098 your installation prefix. This location may also be overridden at
9099 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
9100 ---rmt-command}, for detailed description of this option. @xref{Remote
9101 Tape Server}, for the description of @command{rmt} command).
9103 If this option is not given, but the environment variable @env{TAPE}
9104 is set, its value is used; otherwise, old versions of @command{tar}
9105 used a default archive name (which was picked when @command{tar} was
9106 compiled). The default is normally set up to be the @dfn{first} tape
9107 drive or other transportable I/O medium on the system.
9109 Starting with version 1.11.5, @GNUTAR{} uses
9110 standard input and standard output as the default device, and I will
9111 not try anymore supporting automatic device detection at installation
9112 time. This was failing really in too many cases, it was hopeless.
9113 This is now completely left to the installer to override standard
9114 input and standard output for default device, if this seems
9115 preferable. Further, I think @emph{most} actual usages of
9116 @command{tar} are done with pipes or disks, not really tapes,
9117 cartridges or diskettes.
9119 Some users think that using standard input and output is running
9120 after trouble. This could lead to a nasty surprise on your screen if
9121 you forget to specify an output file name---especially if you are going
9122 through a network or terminal server capable of buffering large amounts
9123 of output. We had so many bug reports in that area of configuring
9124 default tapes automatically, and so many contradicting requests, that
9125 we finally consider the problem to be portably intractable. We could
9126 of course use something like @samp{/dev/tape} as a default, but this
9127 is @emph{also} running after various kind of trouble, going from hung
9128 processes to accidental destruction of real tapes. After having seen
9129 all this mess, using standard input and output as a default really
9130 sounds like the only clean choice left, and a very useful one too.
9132 @GNUTAR{} reads and writes archive in records, I
9133 suspect this is the main reason why block devices are preferred over
9134 character devices. Most probably, block devices are more efficient
9135 too. The installer could also check for @samp{DEFTAPE} in
9136 @file{<sys/mtio.h>}.
9139 @xopindex{force-local, short description}
9141 Archive file is local even if it contains a colon.
9143 @opindex rsh-command
9144 @item --rsh-command=@var{command}
9145 Use remote @var{command} instead of @command{rsh}. This option exists
9146 so that people who use something other than the standard @command{rsh}
9147 (e.g., a Kerberized @command{rsh}) can access a remote device.
9149 When this command is not used, the shell command found when
9150 the @command{tar} program was installed is used instead. This is
9151 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
9152 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
9153 The installer may have overridden this by defining the environment
9154 variable @env{RSH} @emph{at installation time}.
9157 Specify drive and density.
9159 @xopindex{multi-volume, short description}
9161 @itemx --multi-volume
9162 Create/list/extract multi-volume archive.
9164 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
9165 that may be larger than will fit on the medium used to hold it.
9166 @xref{Multi-Volume Archives}.
9168 @xopindex{tape-length, short description}
9170 @itemx --tape-length=@var{num}
9171 Change tape after writing @var{num} x 1024 bytes.
9173 This option might be useful when your tape drivers do not properly
9174 detect end of physical tapes. By being slightly conservative on the
9175 maximum tape length, you might avoid the problem entirely.
9177 @xopindex{info-script, short description}
9178 @xopindex{new-volume-script, short description}
9180 @itemx --info-script=@var{file}
9181 @itemx --new-volume-script=@var{file}
9182 Execute @file{file} at end of each tape. This implies
9183 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
9184 description of this option.
9187 @node Remote Tape Server
9188 @section The Remote Tape Server
9190 @cindex remote tape drive
9192 In order to access the tape drive on a remote machine, @command{tar}
9193 uses the remote tape server written at the University of California at
9194 Berkeley. The remote tape server must be installed as
9195 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
9196 want to use. @command{tar} calls @command{rmt} by running an
9197 @command{rsh} or @command{remsh} to the remote machine, optionally
9198 using a different login name if one is supplied.
9200 A copy of the source for the remote tape server is provided. It is
9201 Copyright @copyright{} 1983 by the Regents of the University of
9202 California, but can be freely distributed. It is compiled and
9203 installed by default.
9205 @cindex absolute file names
9206 Unless you use the @option{--absolute-names} (@option{-P}) option,
9207 @GNUTAR{} will not allow you to create an archive that contains
9208 absolute file names (a file name beginning with @samp{/}.) If you try,
9209 @command{tar} will automatically remove the leading @samp{/} from the
9210 file names it stores in the archive. It will also type a warning
9211 message telling you what it is doing.
9213 When reading an archive that was created with a different
9214 @command{tar} program, @GNUTAR{} automatically
9215 extracts entries in the archive which have absolute file names as if
9216 the file names were not absolute. This is an important feature. A
9217 visitor here once gave a @command{tar} tape to an operator to restore;
9218 the operator used Sun @command{tar} instead of @GNUTAR{},
9219 and the result was that it replaced large portions of
9220 our @file{/bin} and friends with versions from the tape; needless to
9221 say, we were unhappy about having to recover the file system from
9224 For example, if the archive contained a file @file{/usr/bin/computoy},
9225 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
9226 relative to the current directory. If you want to extract the files in
9227 an archive to the same absolute names that they had when the archive
9228 was created, you should do a @samp{cd /} before extracting the files
9229 from the archive, or you should either use the @option{--absolute-names}
9230 option, or use the command @samp{tar -C / @dots{}}.
9232 @cindex Ultrix 3.1 and write failure
9233 Some versions of Unix (Ultrix 3.1 is known to have this problem),
9234 can claim that a short write near the end of a tape succeeded,
9235 when it actually failed. This will result in the -M option not
9236 working correctly. The best workaround at the moment is to use a
9237 significantly larger blocking factor than the default 20.
9239 In order to update an archive, @command{tar} must be able to backspace the
9240 archive in order to reread or rewrite a record that was just read (or
9241 written). This is currently possible only on two kinds of files: normal
9242 disk files (or any other file that can be backspaced with @samp{lseek}),
9243 and industry-standard 9-track magnetic tape (or any other kind of tape
9244 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
9246 This means that the @option{--append}, @option{--concatenate}, and
9247 @option{--delete} commands will not work on any other kind of file.
9248 Some media simply cannot be backspaced, which means these commands and
9249 options will never be able to work on them. These non-backspacing
9250 media include pipes and cartridge tape drives.
9252 Some other media can be backspaced, and @command{tar} will work on them
9253 once @command{tar} is modified to do so.
9255 Archives created with the @option{--multi-volume}, @option{--label}, and
9256 @option{--incremental} (@option{-G}) options may not be readable by other version
9257 of @command{tar}. In particular, restoring a file that was split over
9258 a volume boundary will require some careful work with @command{dd}, if
9259 it can be done at all. Other versions of @command{tar} may also create
9260 an empty file whose name is that of the volume header. Some versions
9261 of @command{tar} may create normal files instead of directories archived
9262 with the @option{--incremental} (@option{-G}) option.
9264 @node Common Problems and Solutions
9265 @section Some Common Problems and their Solutions
9272 no such file or directory
9275 errors from @command{tar}:
9276 directory checksum error
9279 errors from media/system:
9290 @dfn{Block} and @dfn{record} terminology is rather confused, and it
9291 is also confusing to the expert reader. On the other hand, readers
9292 who are new to the field have a fresh mind, and they may safely skip
9293 the next two paragraphs, as the remainder of this manual uses those
9294 two terms in a quite consistent way.
9296 John Gilmore, the writer of the public domain @command{tar} from which
9297 @GNUTAR{} was originally derived, wrote (June 1995):
9300 The nomenclature of tape drives comes from IBM, where I believe
9301 they were invented for the IBM 650 or so. On IBM mainframes, what
9302 is recorded on tape are tape blocks. The logical organization of
9303 data is into records. There are various ways of putting records into
9304 blocks, including @code{F} (fixed sized records), @code{V} (variable
9305 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
9306 to a block), @code{VB} (variable size records, @var{n} to a block),
9307 @code{VSB} (variable spanned blocked: variable sized records that can
9308 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
9309 parameter specified this to the operating system.
9311 The Unix man page on @command{tar} was totally confused about this.
9312 When I wrote @code{PD TAR}, I used the historically correct terminology
9313 (@command{tar} writes data records, which are grouped into blocks).
9314 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
9315 here), and now Fran@,{c}ois has migrated that terminology back
9316 into the source code too.
9319 The term @dfn{physical block} means the basic transfer chunk from or
9320 to a device, after which reading or writing may stop without anything
9321 being lost. In this manual, the term @dfn{block} usually refers to
9322 a disk physical block, @emph{assuming} that each disk block is 512
9323 bytes in length. It is true that some disk devices have different
9324 physical blocks, but @command{tar} ignore these differences in its own
9325 format, which is meant to be portable, so a @command{tar} block is always
9326 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
9327 The term @dfn{logical block} often represents the basic chunk of
9328 allocation of many disk blocks as a single entity, which the operating
9329 system treats somewhat atomically; this concept is only barely used
9332 The term @dfn{physical record} is another way to speak of a physical
9333 block, those two terms are somewhat interchangeable. In this manual,
9334 the term @dfn{record} usually refers to a tape physical block,
9335 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
9336 It is true that archives may be put on disk or used with pipes,
9337 but nevertheless, @command{tar} tries to read and write the archive one
9338 @dfn{record} at a time, whatever the medium in use. One record is made
9339 up of an integral number of blocks, and this operation of putting many
9340 disk blocks into a single tape block is called @dfn{reblocking}, or
9341 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
9342 the logical organization of many characters into something meaningful
9343 to the application. The term @dfn{unit record} describes a small set
9344 of characters which are transmitted whole to or by the application,
9345 and often refers to a line of text. Those two last terms are unrelated
9346 to what we call a @dfn{record} in @GNUTAR{}.
9348 When writing to tapes, @command{tar} writes the contents of the archive
9349 in chunks known as @dfn{records}. To change the default blocking
9350 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
9351 @var{512-size}}) option. Each record will then be composed of
9352 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
9353 @xref{Standard}.) Each file written to the archive uses at least one
9354 full record. As a result, using a larger record size can result in
9355 more wasted space for small files. On the other hand, a larger record
9356 size can often be read and written much more efficiently.
9358 Further complicating the problem is that some tape drives ignore the
9359 blocking entirely. For these, a larger record size can still improve
9360 performance (because the software layers above the tape drive still
9361 honor the blocking), but not as dramatically as on tape drives that
9364 When reading an archive, @command{tar} can usually figure out the
9365 record size on itself. When this is the case, and a non-standard
9366 record size was used when the archive was created, @command{tar} will
9367 print a message about a non-standard blocking factor, and then operate
9368 normally. On some tape devices, however, @command{tar} cannot figure
9369 out the record size itself. On most of those, you can specify a
9370 blocking factor (with @option{--blocking-factor}) larger than the
9371 actual blocking factor, and then use the @option{--read-full-records}
9372 (@option{-B}) option. (If you specify a blocking factor with
9373 @option{--blocking-factor} and don't use the
9374 @option{--read-full-records} option, then @command{tar} will not
9375 attempt to figure out the recording size itself.) On some devices,
9376 you must always specify the record size exactly with
9377 @option{--blocking-factor} when reading, because @command{tar} cannot
9378 figure it out. In any case, use @option{--list} (@option{-t}) before
9379 doing any extractions to see whether @command{tar} is reading the archive
9382 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9383 putting them into records is to put a whole number of them (one or
9384 more) into each record. @command{tar} records are all the same size;
9385 at the end of the file there's a block containing all zeros, which
9386 is how you tell that the remainder of the last record(s) are garbage.
9388 In a standard @command{tar} file (no options), the block size is 512
9389 and the record size is 10240, for a blocking factor of 20. What the
9390 @option{--blocking-factor} option does is sets the blocking factor,
9391 changing the record size while leaving the block size at 512 bytes.
9392 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9393 most tape drives these days prefer much bigger records in order to
9394 stream and not waste tape. When writing tapes for myself, some tend
9395 to use a factor of the order of 2048, say, giving a record size of
9396 around one megabyte.
9398 If you use a blocking factor larger than 20, older @command{tar}
9399 programs might not be able to read the archive, so we recommend this
9400 as a limit to use in practice. @GNUTAR{}, however,
9401 will support arbitrarily large record sizes, limited only by the
9402 amount of virtual memory or the physical characteristics of the tape
9406 * Format Variations:: Format Variations
9407 * Blocking Factor:: The Blocking Factor of an Archive
9410 @node Format Variations
9411 @subsection Format Variations
9412 @cindex Format Parameters
9413 @cindex Format Options
9414 @cindex Options, archive format specifying
9415 @cindex Options, format specifying
9418 Format parameters specify how an archive is written on the archive
9419 media. The best choice of format parameters will vary depending on
9420 the type and number of files being archived, and on the media used to
9423 To specify format parameters when accessing or creating an archive,
9424 you can use the options described in the following sections.
9425 If you do not specify any format parameters, @command{tar} uses
9426 default parameters. You cannot modify a compressed archive.
9427 If you create an archive with the @option{--blocking-factor} option
9428 specified (@pxref{Blocking Factor}), you must specify that
9429 blocking-factor when operating on the archive. @xref{Formats}, for other
9430 examples of format parameter considerations.
9432 @node Blocking Factor
9433 @subsection The Blocking Factor of an Archive
9434 @cindex Blocking Factor
9436 @cindex Number of blocks per record
9437 @cindex Number of bytes per record
9438 @cindex Bytes per record
9439 @cindex Blocks per record
9442 @opindex blocking-factor
9443 The data in an archive is grouped into blocks, which are 512 bytes.
9444 Blocks are read and written in whole number multiples called
9445 @dfn{records}. The number of blocks in a record (i.e., the size of a
9446 record in units of 512 bytes) is called the @dfn{blocking factor}.
9447 The @option{--blocking-factor=@var{512-size}} (@option{-b
9448 @var{512-size}}) option specifies the blocking factor of an archive.
9449 The default blocking factor is typically 20 (i.e., 10240 bytes), but
9450 can be specified at installation. To find out the blocking factor of
9451 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
9452 This may not work on some devices.
9454 Records are separated by gaps, which waste space on the archive media.
9455 If you are archiving on magnetic tape, using a larger blocking factor
9456 (and therefore larger records) provides faster throughput and allows you
9457 to fit more data on a tape (because there are fewer gaps). If you are
9458 archiving on cartridge, a very large blocking factor (say 126 or more)
9459 greatly increases performance. A smaller blocking factor, on the other
9460 hand, may be useful when archiving small files, to avoid archiving lots
9461 of nulls as @command{tar} fills out the archive to the end of the record.
9462 In general, the ideal record size depends on the size of the
9463 inter-record gaps on the tape you are using, and the average size of the
9464 files you are archiving. @xref{create}, for information on
9467 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
9469 Archives with blocking factors larger than 20 cannot be read
9470 by very old versions of @command{tar}, or by some newer versions
9471 of @command{tar} running on old machines with small address spaces.
9472 With @GNUTAR{}, the blocking factor of an archive is limited
9473 only by the maximum record size of the device containing the archive,
9474 or by the amount of available virtual memory.
9476 Also, on some systems, not using adequate blocking factors, as sometimes
9477 imposed by the device drivers, may yield unexpected diagnostics. For
9478 example, this has been reported:
9481 Cannot write to /dev/dlt: Invalid argument
9485 In such cases, it sometimes happen that the @command{tar} bundled by
9486 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9487 requires an explicit specification for the block size,
9488 which it cannot guess. This yields some people to consider
9489 @GNUTAR{} is misbehaving, because by comparison,
9490 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9491 for example, might resolve the problem.
9493 If you use a non-default blocking factor when you create an archive, you
9494 must specify the same blocking factor when you modify that archive. Some
9495 archive devices will also require you to specify the blocking factor when
9496 reading that archive, however this is not typically the case. Usually, you
9497 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9498 reports a non-default record size and then lists the archive members as
9499 it would normally. To extract files from an archive with a non-standard
9500 blocking factor (particularly if you're not sure what the blocking factor
9501 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9502 specifying a blocking factor larger then the blocking factor of the archive
9503 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}.
9504 @xref{list}, for more information on the @option{--list} (@option{-t})
9505 operation. @xref{Reading}, for a more detailed explanation of that option.
9508 @item --blocking-factor=@var{number}
9509 @itemx -b @var{number}
9510 Specifies the blocking factor of an archive. Can be used with any
9511 operation, but is usually not necessary with @option{--list} (@option{-t}).
9517 @item -b @var{blocks}
9518 @itemx --blocking-factor=@var{blocks}
9519 Set record size to @math{@var{blocks} * 512} bytes.
9521 This option is used to specify a @dfn{blocking factor} for the archive.
9522 When reading or writing the archive, @command{tar}, will do reads and writes
9523 of the archive in records of @math{@var{block}*512} bytes. This is true
9524 even when the archive is compressed. Some devices requires that all
9525 write operations be a multiple of a certain size, and so, @command{tar}
9526 pads the archive out to the next record boundary.
9528 The default blocking factor is set when @command{tar} is compiled, and is
9529 typically 20. Blocking factors larger than 20 cannot be read by very
9530 old versions of @command{tar}, or by some newer versions of @command{tar}
9531 running on old machines with small address spaces.
9533 With a magnetic tape, larger records give faster throughput and fit
9534 more data on a tape (because there are fewer inter-record gaps).
9535 If the archive is in a disk file or a pipe, you may want to specify
9536 a smaller blocking factor, since a large one will result in a large
9537 number of null bytes at the end of the archive.
9539 When writing cartridge or other streaming tapes, a much larger
9540 blocking factor (say 126 or more) will greatly increase performance.
9541 However, you must specify the same blocking factor when reading or
9542 updating the archive.
9544 Apparently, Exabyte drives have a physical block size of 8K bytes.
9545 If we choose our blocksize as a multiple of 8k bytes, then the problem
9546 seems to disappear. Id est, we are using block size of 112 right
9547 now, and we haven't had the problem since we switched@dots{}
9549 With @GNUTAR{} the blocking factor is limited only
9550 by the maximum record size of the device containing the archive, or by
9551 the amount of available virtual memory.
9553 However, deblocking or reblocking is virtually avoided in a special
9554 case which often occurs in practice, but which requires all the
9555 following conditions to be simultaneously true:
9558 the archive is subject to a compression option,
9560 the archive is not handled through standard input or output, nor
9561 redirected nor piped,
9563 the archive is directly handled to a local disk, instead of any special
9566 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9570 If the output goes directly to a local disk, and not through
9571 stdout, then the last write is not extended to a full record size.
9572 Otherwise, reblocking occurs. Here are a few other remarks on this
9578 @command{gzip} will complain about trailing garbage if asked to
9579 uncompress a compressed archive on tape, there is an option to turn
9580 the message off, but it breaks the regularity of simply having to use
9581 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9582 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9583 Gailly, by sending a copy of this message to him.
9586 @command{compress} does not show this problem, but as Jean-loup pointed
9587 out to Michael, @samp{compress -d} silently adds garbage after
9588 the result of decompression, which tar ignores because it already
9589 recognized its end-of-file indicator. So this bug may be safely
9593 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9594 but will still return an exit status of 2 which tar reports in turn.
9595 @command{tar} might ignore the exit status returned, but I hate doing
9596 that, as it weakens the protection @command{tar} offers users against
9597 other possible problems at decompression time. If @command{gzip} was
9598 silently skipping trailing zeros @emph{and} also avoiding setting the
9599 exit status in this innocuous case, that would solve this situation.
9602 @command{tar} should become more solid at not stopping to read a pipe at
9603 the first null block encountered. This inelegantly breaks the pipe.
9604 @command{tar} should rather drain the pipe out before exiting itself.
9607 @xopindex{ignore-zeros, short description}
9609 @itemx --ignore-zeros
9610 Ignore blocks of zeros in archive (means EOF).
9612 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9613 of zeros in the archive. Normally a block of zeros indicates the
9614 end of the archive, but when reading a damaged archive, or one which
9615 was created by concatenating several archives together, this option
9616 allows @command{tar} to read the entire archive. This option is not on
9617 by default because many versions of @command{tar} write garbage after
9620 Note that this option causes @command{tar} to read to the end of the
9621 archive file, which may sometimes avoid problems when multiple files
9622 are stored on a single physical tape.
9624 @xopindex{read-full-records, short description}
9626 @itemx --read-full-records
9627 Reblock as we read (for reading 4.2BSD pipes).
9629 If @option{--read-full-records} is used, @command{tar}
9630 will not panic if an attempt to read a record from the archive does
9631 not return a full record. Instead, @command{tar} will keep reading
9632 until it has obtained a full
9635 This option is turned on by default when @command{tar} is reading
9636 an archive from standard input, or from a remote machine. This is
9637 because on BSD Unix systems, a read of a pipe will return however
9638 much happens to be in the pipe, even if it is less than @command{tar}
9639 requested. If this option was not used, @command{tar} would fail as
9640 soon as it read an incomplete record from the pipe.
9642 This option is also useful with the commands for updating an archive.
9648 @FIXME{Appropriate options should be moved here from elsewhere.}
9650 @cindex blocking factor
9651 @cindex tape blocking
9653 When handling various tapes or cartridges, you have to take care of
9654 selecting a proper blocking, that is, the number of disk blocks you
9655 put together as a single tape block on the tape, without intervening
9656 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9657 with no information on it, used for decelerating the tape to a
9658 full stop, and for later regaining the reading or writing speed.
9659 When the tape driver starts reading a record, the record has to
9660 be read whole without stopping, as a tape gap is needed to stop the
9661 tape motion without loosing information.
9663 @cindex Exabyte blocking
9664 @cindex DAT blocking
9665 Using higher blocking (putting more disk blocks per tape block) will use
9666 the tape more efficiently as there will be less tape gaps. But reading
9667 such tapes may be more difficult for the system, as more memory will be
9668 required to receive at once the whole record. Further, if there is a
9669 reading error on a huge record, this is less likely that the system will
9670 succeed in recovering the information. So, blocking should not be too
9671 low, nor it should be too high. @command{tar} uses by default a blocking of
9672 20 for historical reasons, and it does not really matter when reading or
9673 writing to disk. Current tape technology would easily accommodate higher
9674 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9675 We were told that for some DLT drives, the blocking should be a multiple
9676 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9677 Other manufacturers may use different recommendations for the same tapes.
9678 This might also depends of the buffering techniques used inside modern
9679 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9680 Others request blocking to be some exponent of two.
9682 So, there is no fixed rule for blocking. But blocking at read time
9683 should ideally be the same as blocking used at write time. At one place
9684 I know, with a wide variety of equipment, they found it best to use a
9685 blocking of 32 to guarantee that their tapes are fully interchangeable.
9687 I was also told that, for recycled tapes, prior erasure (by the same
9688 drive unit that will be used to create the archives) sometimes lowers
9689 the error rates observed at rewriting time.
9691 I might also use @option{--number-blocks} instead of
9692 @option{--block-number}, so @option{--block} will then expand to
9693 @option{--blocking-factor} unambiguously.
9696 @section Many Archives on One Tape
9698 @FIXME{Appropriate options should be moved here from elsewhere.}
9700 @findex ntape @r{device}
9701 Most tape devices have two entries in the @file{/dev} directory, or
9702 entries that come in pairs, which differ only in the minor number for
9703 this device. Let's take for example @file{/dev/tape}, which often
9704 points to the only or usual tape device of a given system. There might
9705 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9706 name is the @emph{rewinding} version of the device, while the name
9707 having @samp{nr} in it is the @emph{no rewinding} version of the same
9710 A rewinding tape device will bring back the tape to its beginning point
9711 automatically when this device is opened or closed. Since @command{tar}
9712 opens the archive file before using it and closes it afterwards, this
9713 means that a simple:
9716 $ @kbd{tar cf /dev/tape @var{directory}}
9720 will reposition the tape to its beginning both prior and after saving
9721 @var{directory} contents to it, thus erasing prior tape contents and
9722 making it so that any subsequent write operation will destroy what has
9725 @cindex tape positioning
9726 So, a rewinding device is normally meant to hold one and only one file.
9727 If you want to put more than one @command{tar} archive on a given tape, you
9728 will need to avoid using the rewinding version of the tape device. You
9729 will also have to pay special attention to tape positioning. Errors in
9730 positioning may overwrite the valuable data already on your tape. Many
9731 people, burnt by past experiences, will only use rewinding devices and
9732 limit themselves to one file per tape, precisely to avoid the risk of
9733 such errors. Be fully aware that writing at the wrong position on a
9734 tape loses all information past this point and most probably until the
9735 end of the tape, and this destroyed information @emph{cannot} be
9738 To save @var{directory-1} as a first archive at the beginning of a
9739 tape, and leave that tape ready for a second archive, you should use:
9742 $ @kbd{mt -f /dev/nrtape rewind}
9743 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9747 @dfn{Tape marks} are special magnetic patterns written on the tape
9748 media, which are later recognizable by the reading hardware. These
9749 marks are used after each file, when there are many on a single tape.
9750 An empty file (that is to say, two tape marks in a row) signal the
9751 logical end of the tape, after which no file exist. Usually,
9752 non-rewinding tape device drivers will react to the close request issued
9753 by @command{tar} by first writing two tape marks after your archive, and by
9754 backspacing over one of these. So, if you remove the tape at that time
9755 from the tape drive, it is properly terminated. But if you write
9756 another file at the current position, the second tape mark will be
9757 erased by the new information, leaving only one tape mark between files.
9759 So, you may now save @var{directory-2} as a second archive after the
9760 first on the same tape by issuing the command:
9763 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9767 and so on for all the archives you want to put on the same tape.
9769 Another usual case is that you do not write all the archives the same
9770 day, and you need to remove and store the tape between two archive
9771 sessions. In general, you must remember how many files are already
9772 saved on your tape. Suppose your tape already has 16 files on it, and
9773 that you are ready to write the 17th. You have to take care of skipping
9774 the first 16 tape marks before saving @var{directory-17}, say, by using
9778 $ @kbd{mt -f /dev/nrtape rewind}
9779 $ @kbd{mt -f /dev/nrtape fsf 16}
9780 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9783 In all the previous examples, we put aside blocking considerations, but
9784 you should do the proper things for that as well. @xref{Blocking}.
9787 * Tape Positioning:: Tape Positions and Tape Marks
9788 * mt:: The @command{mt} Utility
9791 @node Tape Positioning
9792 @subsection Tape Positions and Tape Marks
9795 Just as archives can store more than one file from the file system,
9796 tapes can store more than one archive file. To keep track of where
9797 archive files (or any other type of file stored on tape) begin and
9798 end, tape archive devices write magnetic @dfn{tape marks} on the
9799 archive media. Tape drives write one tape mark between files,
9800 two at the end of all the file entries.
9802 If you think of data as a series of records "rrrr"'s, and tape marks as
9803 "*"'s, a tape might look like the following:
9806 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9809 Tape devices read and write tapes using a read/write @dfn{tape
9810 head}---a physical part of the device which can only access one
9811 point on the tape at a time. When you use @command{tar} to read or
9812 write archive data from a tape device, the device will begin reading
9813 or writing from wherever on the tape the tape head happens to be,
9814 regardless of which archive or what part of the archive the tape
9815 head is on. Before writing an archive, you should make sure that no
9816 data on the tape will be overwritten (unless it is no longer needed).
9817 Before reading an archive, you should make sure the tape head is at
9818 the beginning of the archive you want to read. You can do it manually
9819 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9820 that automatically (@pxref{Scripted Restoration}).
9822 If you want to add new archive file entries to a tape, you should
9823 advance the tape to the end of the existing file entries, backspace
9824 over the last tape mark, and write the new archive file. If you were
9825 to add two archives to the example above, the tape might look like the
9829 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9833 @subsection The @command{mt} Utility
9836 @FIXME{Is it true that this only works on non-block devices?
9837 should explain the difference, (fixed or variable).}
9838 @xref{Blocking Factor}.
9840 You can use the @command{mt} utility to advance or rewind a tape past a
9841 specified number of archive files on the tape. This will allow you
9842 to move to the beginning of an archive before extracting or reading
9843 it, or to the end of all the archives before writing a new one.
9844 @FIXME{Why isn't there an "advance 'til you find two tape marks
9847 The syntax of the @command{mt} command is:
9850 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9853 where @var{tapename} is the name of the tape device, @var{number} is
9854 the number of times an operation is performed (with a default of one),
9855 and @var{operation} is one of the following:
9857 @FIXME{is there any use for record operations?}
9862 Writes @var{number} tape marks at the current position on the tape.
9865 Moves tape position forward @var{number} files.
9868 Moves tape position back @var{number} files.
9871 Rewinds the tape. (Ignores @var{number}).
9875 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9878 Prints status information about the tape unit.
9882 @FIXME{Is there a better way to frob the spacing on the list?}
9884 If you don't specify a @var{tapename}, @command{mt} uses the environment
9885 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
9886 the default device specified in your @file{sys/mtio.h} file
9887 (@code{DEFTAPE} variable). If this is not defined, the program will
9888 display a descriptive error message and exit with code 1.
9890 @command{mt} returns a 0 exit status when the operation(s) were
9891 successful, 1 if the command was unrecognized, and 2 if an operation
9894 @node Using Multiple Tapes
9895 @section Using Multiple Tapes
9897 Often you might want to write a large archive, one larger than will fit
9898 on the actual tape you are using. In such a case, you can run multiple
9899 @command{tar} commands, but this can be inconvenient, particularly if you
9900 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9901 Therefore, @command{tar} provides a special mode for creating
9902 multi-volume archives.
9904 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
9905 on several media volumes of fixed size. Although in this section we will
9906 often call @samp{volume} a @dfn{tape}, there is absolutely no
9907 requirement for multi-volume archives to be stored on tapes. Instead,
9908 they can use whatever media type the user finds convenient, they can
9909 even be located on files.
9911 When creating a multi-volume archive, @GNUTAR{} continues to fill
9912 current volume until it runs out of space, then it switches to
9913 next volume (usually the operator is queried to replace the tape on
9914 this point), and continues working on the new volume. This operation
9915 continues until all requested files are dumped. If @GNUTAR{} detects
9916 end of media while dumping a file, such a file is archived in split
9917 form. Some very big files can even be split across several volumes.
9919 Each volume is itself a valid @GNUTAR{} archive, so it can be read
9920 without any special options. Consequently any file member residing
9921 entirely on one volume can be extracted or otherwise operated upon
9922 without needing the other volume. Sure enough, to extract a split
9923 member you would need all volumes its parts reside on.
9925 Multi-volume archives suffer from several limitations. In particular,
9926 they cannot be compressed.
9928 @GNUTAR{} is able to create multi-volume archives of two formats
9929 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
9932 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9933 * Tape Files:: Tape Files
9934 * Tarcat:: Concatenate Volumes into a Single Archive
9938 @node Multi-Volume Archives
9939 @subsection Archives Longer than One Tape or Disk
9940 @cindex Multi-volume archives
9942 @opindex multi-volume
9943 To create an archive that is larger than will fit on a single unit of
9944 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9945 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9946 archive can be manipulated like any other archive (provided the
9947 @option{--multi-volume} option is specified), but is stored on more
9948 than one tape or disk.
9950 When you specify @option{--multi-volume}, @command{tar} does not report an
9951 error when it comes to the end of an archive volume (when reading), or
9952 the end of the media (when writing). Instead, it prompts you to load
9953 a new storage volume. If the archive is on a magnetic tape, you
9954 should change tapes when you see the prompt; if the archive is on a
9955 floppy disk, you should change disks; etc.
9958 @item --multi-volume
9960 Creates a multi-volume archive, when used in conjunction with
9961 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9962 archive, specify @option{--multi-volume} in conjunction with that
9967 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
9971 The method @command{tar} uses to detect end of tape is not perfect, and
9972 fails on some operating systems or on some devices. If @command{tar}
9973 cannot detect the end of the tape itself, you can use
9974 @option{--tape-length} option to inform it about the capacity of the
9977 @anchor{tape-length}
9979 @opindex tape-length
9980 @item --tape-length=@var{size}
9981 @itemx -L @var{size}
9982 Set maximum length of a volume. The @var{size} argument should then
9983 be the usable size of the tape in units of 1024 bytes. This option
9984 selects @option{--multi-volume} automatically. For example:
9987 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
9991 @anchor{change volume prompt}
9992 When @GNUTAR{} comes to the end of a storage media, it asks you to
9993 change the volume. The built-in prompt for POSIX locale
9994 is@footnote{If you run @GNUTAR{} under a different locale, the
9995 translation to the locale's language will be used.}:
9998 Prepare volume #@var{n} for `@var{archive}' and hit return:
10002 where @var{n} is the ordinal number of the volume to be created and
10003 @var{archive} is archive file or device name.
10005 When prompting for a new tape, @command{tar} accepts any of the following
10010 Request @command{tar} to explain possible responses
10012 Request @command{tar} to exit immediately.
10013 @item n @var{file-name}
10014 Request @command{tar} to write the next volume on the file @var{file-name}.
10016 Request @command{tar} to run a subshell. This option can be disabled
10017 by giving @option{--restrict} command line option to
10018 @command{tar}@footnote{@xref{--restrict}, for more information about
10021 Request @command{tar} to begin writing the next volume.
10024 (You should only type @samp{y} after you have changed the tape;
10025 otherwise @command{tar} will write over the volume it just finished.)
10027 @cindex Volume number file
10029 @anchor{volno-file}
10030 @opindex volno-file
10031 The volume number used by @command{tar} in its tape-changing prompt
10032 can be changed; if you give the
10033 @option{--volno-file=@var{file-of-number}} option, then
10034 @var{file-of-number} should be an non-existing file to be created, or
10035 else, a file already containing a decimal number. That number will be
10036 used as the volume number of the first volume written. When
10037 @command{tar} is finished, it will rewrite the file with the
10038 now-current volume number. (This does not change the volume number
10039 written on a tape label, as per @ref{label}, it @emph{only} affects
10040 the number used in the prompt.)
10042 @cindex End-of-archive info script
10043 @cindex Info script
10044 @anchor{info-script}
10045 @opindex info-script
10046 @opindex new-volume-script
10047 If you want more elaborate behavior than this, you can write a special
10048 @dfn{new volume script}, that will be responsible for changing the
10049 volume, and instruct @command{tar} to use it instead of its normal
10050 prompting procedure:
10053 @item --info-script=@var{script-name}
10054 @itemx --new-volume-script=@var{script-name}
10055 @itemx -F @var{script-name}
10056 Specify the full name of the volume script to use. The script can be
10057 used to eject cassettes, or to broadcast messages such as
10058 @samp{Someone please come change my tape} when performing unattended
10062 The @var{script-name} is executed without any command line
10063 arguments. It inherits @command{tar}'s shell environment.
10064 Additional data is passed to it via the following
10065 environment variables:
10068 @vrindex TAR_VERSION, info script environment variable
10070 @GNUTAR{} version number.
10072 @vrindex TAR_ARCHIVE, info script environment variable
10074 The name of the archive @command{tar} is processing.
10076 @vrindex TAR_VOLUME, info script environment variable
10078 Ordinal number of the volume @command{tar} is about to start.
10080 @vrindex TAR_SUBCOMMAND, info script environment variable
10081 @item TAR_SUBCOMMAND
10082 Short option describing the operation @command{tar} is executing
10083 @xref{Operations}, for a complete list of subcommand options.
10085 @vrindex TAR_FORMAT, info script environment variable
10087 Format of the archive being processed. @xref{Formats}, for a complete
10088 list of archive format names.
10091 The volume script can instruct @command{tar} to use new archive name,
10092 by writing in to file descriptor 3 (see below for an example).
10094 If the info script fails, @command{tar} exits; otherwise, it begins
10095 writing the next volume.
10097 If you want @command{tar} to cycle through a series of files or tape
10098 drives, there are three approaches to choose from. First of all, you
10099 can give @command{tar} multiple @option{--file} options. In this case
10100 the specified files will be used, in sequence, as the successive
10101 volumes of the archive. Only when the first one in the sequence needs
10102 to be used again will @command{tar} prompt for a tape change (or run
10103 the info script). For example, suppose someone has two tape drives on
10104 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
10105 @GNUTAR{} to switch to the second drive when it needs to write the
10106 second tape, and then back to the first tape, etc., just do either of:
10109 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
10110 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
10113 The second method is to use the @samp{n} response to the tape-change
10116 Finally, the most flexible approach is to use a volume script, that
10117 writes new archive name to the file descriptor #3. For example, the
10118 following volume script will create a series of archive files, named
10119 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
10120 archive being created (as given by @option{--file} option) and
10121 @var{vol} is the ordinal number of the archive being created:
10126 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
10128 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
10129 case $TAR_SUBCOMMAND in
10131 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
10136 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
10140 The same script cant be used while listing, comparing or extracting
10141 from the created archive. For example:
10145 # @r{Create a multi-volume archive:}
10146 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
10147 # @r{Extract from the created archive:}
10148 $ @kbd{tar -x -f archive.tar -F new-volume .}
10153 Notice, that the first command had to use @option{-L} option, since
10154 otherwise @GNUTAR{} will end up writing everything to file
10155 @file{archive.tar}.
10157 You can read each individual volume of a multi-volume archive as if it
10158 were an archive by itself. For example, to list the contents of one
10159 volume, use @option{--list}, without @option{--multi-volume} specified.
10160 To extract an archive member from one volume (assuming it is described
10161 that volume), use @option{--extract}, again without
10162 @option{--multi-volume}.
10164 If an archive member is split across volumes (i.e., its entry begins on
10165 one volume of the media and ends on another), you need to specify
10166 @option{--multi-volume} to extract it successfully. In this case, you
10167 should load the volume where the archive member starts, and use
10168 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
10169 volumes as it needs them. @xref{extracting archives}, for more
10170 information about extracting archives.
10172 Multi-volume archives can be modified like any other archive. To add
10173 files to a multi-volume archive, you need to only mount the last
10174 volume of the archive media (and new volumes, if needed). For all
10175 other operations, you need to use the entire archive.
10177 If a multi-volume archive was labeled using
10178 @option{--label=@var{archive-label}} (@pxref{label}) when it was
10179 created, @command{tar} will not automatically label volumes which are
10180 added later. To label subsequent volumes, specify
10181 @option{--label=@var{archive-label}} again in conjunction with the
10182 @option{--append}, @option{--update} or @option{--concatenate} operation.
10184 Notice that multi-volume support is a GNU extension and the archives
10185 created in this mode should be read only using @GNUTAR{}. If you
10186 absolutely have to process such archives using a third-party @command{tar}
10187 implementation, read @ref{Split Recovery}.
10190 @subsection Tape Files
10193 To give the archive a name which will be recorded in it, use the
10194 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
10195 option. This will write a special block identifying
10196 @var{volume-label} as the name of the archive to the front of the
10197 archive which will be displayed when the archive is listed with
10198 @option{--list}. If you are creating a multi-volume archive with
10199 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
10200 volume label will have @samp{Volume @var{nnn}} appended to the name
10201 you give, where @var{nnn} is the number of the volume of the archive.
10202 (If you use the @option{--label=@var{volume-label}}) option when
10203 reading an archive, it checks to make sure the label on the tape
10204 matches the one you give. @xref{label}.
10206 When @command{tar} writes an archive to tape, it creates a single
10207 tape file. If multiple archives are written to the same tape, one
10208 after the other, they each get written as separate tape files. When
10209 extracting, it is necessary to position the tape at the right place
10210 before running @command{tar}. To do this, use the @command{mt} command.
10211 For more information on the @command{mt} command and on the organization
10212 of tapes into a sequence of tape files, see @ref{mt}.
10214 People seem to often do:
10217 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
10220 or such, for pushing a common date in all volumes or an archive set.
10223 @subsection Concatenate Volumes into a Single Archive
10226 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
10227 archive to a single @command{tar} archive. Simply concatenating all
10228 volumes into one will not work, since each volume carries an additional
10229 information at the beginning. @GNUTAR{} is shipped with the shell
10230 script @command{tarcat} designed for this purpose.
10232 The script takes a list of files comprising a multi-volume archive
10233 and creates the resulting archive at the standard output. For example:
10236 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
10239 The script implements a simple heuristics to determine the format of
10240 the first volume file and to decide how to process the rest of the
10241 files. However, it makes no attempt to verify whether the files are
10242 given in order or even if they are valid @command{tar} archives.
10243 It uses @command{dd} and does not filter its standard error, so you
10244 will usually see lots of spurious messages.
10246 @FIXME{The script is not installed. Should we install it?}
10249 @section Including a Label in the Archive
10250 @cindex Labeling an archive
10251 @cindex Labels on the archive media
10252 @cindex Labeling multi-volume archives
10256 To avoid problems caused by misplaced paper labels on the archive
10257 media, you can include a @dfn{label} entry---an archive member which
10258 contains the name of the archive---in the archive itself. Use the
10259 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10260 option in conjunction with the @option{--create} operation to include
10261 a label entry in the archive as it is being created.
10264 @item --label=@var{archive-label}
10265 @itemx -V @var{archive-label}
10266 Includes an @dfn{archive-label} at the beginning of the archive when
10267 the archive is being created, when used in conjunction with the
10268 @option{--create} operation. Checks to make sure the archive label
10269 matches the one specified (when used in conjunction with any other
10273 If you create an archive using both
10274 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10275 and @option{--multi-volume} (@option{-M}), each volume of the archive
10276 will have an archive label of the form @samp{@var{archive-label}
10277 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
10278 next, and so on. @xref{Using Multiple Tapes}, for information on
10279 creating multiple volume archives.
10281 @cindex Volume label, listing
10282 @cindex Listing volume label
10283 The volume label will be displayed by @option{--list} along with
10284 the file contents. If verbose display is requested, it will also be
10285 explicitly marked as in the example below:
10289 $ @kbd{tar --verbose --list --file=iamanarchive}
10290 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
10291 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
10295 @opindex test-label
10296 @anchor{--test-label option}
10297 However, @option{--list} option will cause listing entire
10298 contents of the archive, which may be undesirable (for example, if the
10299 archive is stored on a tape). You can request checking only the volume
10300 by specifying @option{--test-label} option. This option reads only the
10301 first block of an archive, so it can be used with slow storage
10302 devices. For example:
10306 $ @kbd{tar --test-label --file=iamanarchive}
10311 If @option{--test-label} is used with a single command line
10312 argument, @command{tar} compares the volume label with the
10313 argument. It exits with code 0 if the two strings match, and with code
10314 2 otherwise. In this case no output is displayed. For example:
10318 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
10320 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
10325 If you request any operation, other than @option{--create}, along
10326 with using @option{--label} option, @command{tar} will first check if
10327 the archive label matches the one specified and will refuse to proceed
10328 if it does not. Use this as a safety precaution to avoid accidentally
10329 overwriting existing archives. For example, if you wish to add files
10330 to @file{archive}, presumably labeled with string @samp{My volume},
10335 $ @kbd{tar -rf archive --label 'My volume' .}
10336 tar: Archive not labeled to match `My volume'
10341 in case its label does not match. This will work even if
10342 @file{archive} is not labeled at all.
10344 Similarly, @command{tar} will refuse to list or extract the
10345 archive if its label doesn't match the @var{archive-label}
10346 specified. In those cases, @var{archive-label} argument is interpreted
10347 as a globbing-style pattern which must match the actual magnetic
10348 volume label. @xref{exclude}, for a precise description of how match
10349 is attempted@footnote{Previous versions of @command{tar} used full
10350 regular expression matching, or before that, only exact string
10351 matching, instead of wildcard matchers. We decided for the sake of
10352 simplicity to use a uniform matching device through
10353 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10354 the volume label matcher will also suffix @var{archive-label} by
10355 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10356 up. Since the volume numbering is automatically added in labels at
10357 creation time, it sounded logical to equally help the user taking care
10358 of it when the archive is being read.
10360 The @option{--label} was once called @option{--volume}, but is not
10361 available under that name anymore.
10363 You can also use @option{--label} to get a common information on
10364 all tapes of a series. For having this information different in each
10365 series created through a single script used on a regular basis, just
10366 manage to get some date string as part of the label. For example:
10370 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10371 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10372 --volume="Daily backup for `date +%Y-%m-%d`"}
10376 Also note that each label has its own date and time, which corresponds
10377 to when @GNUTAR{} initially attempted to write it,
10378 often soon after the operator launches @command{tar} or types the
10379 carriage return telling that the next tape is ready. Comparing date
10380 labels does give an idea of tape throughput only if the delays for
10381 rewinding tapes and the operator switching them were negligible, which
10382 is usually not the case.
10385 @section Verifying Data as It is Stored
10386 @cindex Verifying a write operation
10387 @cindex Double-checking a write operation
10392 @opindex verify, short description
10393 Attempt to verify the archive after writing.
10396 This option causes @command{tar} to verify the archive after writing it.
10397 Each volume is checked after it is written, and any discrepancies
10398 are recorded on the standard error output.
10400 Verification requires that the archive be on a back-space-able medium.
10401 This means pipes, some cartridge tape drives, and some other devices
10402 cannot be verified.
10404 You can insure the accuracy of an archive by comparing files in the
10405 system with archive members. @command{tar} can compare an archive to the
10406 file system as the archive is being written, to verify a write
10407 operation, or can compare a previously written archive, to insure that
10410 @xopindex{verify, using with @option{--create}}
10411 @xopindex{create, using with @option{--verify}}
10412 To check for discrepancies in an archive immediately after it is
10413 written, use the @option{--verify} (@option{-W}) option in conjunction with
10414 the @option{--create} operation. When this option is
10415 specified, @command{tar} checks archive members against their counterparts
10416 in the file system, and reports discrepancies on the standard error.
10418 To verify an archive, you must be able to read it from before the end
10419 of the last written entry. This option is useful for detecting data
10420 errors on some tapes. Archives written to pipes, some cartridge tape
10421 drives, and some other devices cannot be verified.
10423 One can explicitly compare an already made archive with the file
10424 system by using the @option{--compare} (@option{--diff}, @option{-d})
10425 option, instead of using the more automatic @option{--verify} option.
10428 Note that these two options have a slightly different intent. The
10429 @option{--compare} option checks how identical are the logical contents of some
10430 archive with what is on your disks, while the @option{--verify} option is
10431 really for checking if the physical contents agree and if the recording
10432 media itself is of dependable quality. So, for the @option{--verify}
10433 operation, @command{tar} tries to defeat all in-memory cache pertaining to
10434 the archive, while it lets the speed optimization undisturbed for the
10435 @option{--compare} option. If you nevertheless use @option{--compare} for
10436 media verification, you may have to defeat the in-memory cache yourself,
10437 maybe by opening and reclosing the door latch of your recording unit,
10438 forcing some doubt in your operating system about the fact this is really
10439 the same volume as the one just written or read.
10441 The @option{--verify} option would not be necessary if drivers were indeed
10442 able to detect dependably all write failures. This sometimes require many
10443 magnetic heads, some able to read after the writes occurred. One would
10444 not say that drivers unable to detect all cases are necessarily flawed,
10445 as long as programming is concerned.
10447 The @option{--verify} (@option{-W}) option will not work in
10448 conjunction with the @option{--multi-volume} (@option{-M}) option or
10449 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
10450 and @option{--delete} operations. @xref{Operations}, for more
10451 information on these operations.
10453 Also, since @command{tar} normally strips leading @samp{/} from file
10454 names (@pxref{absolute}), a command like @samp{tar --verify -cf
10455 /tmp/foo.tar /etc} will work as desired only if the working directory is
10456 @file{/}, as @command{tar} uses the archive's relative member names
10457 (e.g., @file{etc/motd}) when verifying the archive.
10459 @node Write Protection
10460 @section Write Protection
10462 Almost all tapes and diskettes, and in a few rare cases, even disks can
10463 be @dfn{write protected}, to protect data on them from being changed.
10464 Once an archive is written, you should write protect the media to prevent
10465 the archive from being accidentally overwritten or deleted. (This will
10466 protect the archive from being changed with a tape or floppy drive---it
10467 will not protect it from magnet fields or other physical hazards).
10469 The write protection device itself is usually an integral part of the
10470 physical media, and can be a two position (write enabled/write
10471 disabled) switch, a notch which can be popped out or covered, a ring
10472 which can be removed from the center of a tape reel, or some other
10473 changeable feature.
10478 This appendix lists some important user-visible changes between
10479 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
10480 version of this document is available at
10481 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
10482 @GNUTAR{} documentation page}.
10485 @item Use of globbing patterns when listing and extracting.
10487 Previous versions of GNU tar assumed shell-style globbing when
10488 extracting from or listing an archive. For example:
10491 $ @kbd{tar xf foo.tar '*.c'}
10494 would extract all files whose names end in @samp{.c}. This behavior
10495 was not documented and was incompatible with traditional tar
10496 implementations. Therefore, starting from version 1.15.91, GNU tar
10497 no longer uses globbing by default. For example, the above invocation
10498 is now interpreted as a request to extract from the archive the file
10501 To facilitate transition to the new behavior for those users who got
10502 used to the previous incorrect one, @command{tar} will print a warning
10503 if it finds out that a requested member was not found in the archive
10504 and its name looks like a globbing pattern. For example:
10507 $ @kbd{tar xf foo.tar '*.c'}
10508 tar: Pattern matching characters used in file names. Please,
10509 tar: use --wildcards to enable pattern matching, or --no-wildcards to
10510 tar: suppress this warning.
10511 tar: *.c: Not found in archive
10512 tar: Error exit delayed from previous errors
10515 To treat member names as globbing patterns, use --wildcards option.
10516 If you want to tar to mimic the behavior of versions prior to 1.15.91,
10517 add this option to your @env{TAR_OPTIONS} variable.
10519 @xref{wildcards}, for the detailed discussion of the use of globbing
10520 patterns by @GNUTAR{}.
10522 @item Use of short option @option{-o}.
10524 Earlier versions of @GNUTAR{} understood @option{-o} command line
10525 option as a synonym for @option{--old-archive}.
10527 @GNUTAR{} starting from version 1.13.90 understands this option as
10528 a synonym for @option{--no-same-owner}. This is compatible with
10529 UNIX98 @command{tar} implementations.
10531 However, to facilitate transition, @option{-o} option retains its
10532 old semantics when it is used with one of archive-creation commands.
10533 Users are encouraged to use @option{--format=oldgnu} instead.
10535 It is especially important, since versions of @acronym{GNU} Automake
10536 up to and including 1.8.4 invoke tar with this option to produce
10537 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10538 of this issue and its implications.
10540 @FIXME{Change the first argument to tar-formats when the new Automake is
10541 out. The proposition to add @anchor{} to the appropriate place of its
10542 docs was accepted by Automake people --Sergey 2006-05-25}.
10543 @xref{Options, tar-v7, Changing Automake's Behavior,
10544 automake, GNU Automake}, for a description on how to use various
10545 archive formats with @command{automake}.
10547 Future versions of @GNUTAR{} will understand @option{-o} only as a
10548 synonym for @option{--no-same-owner}.
10550 @item Use of short option @option{-l}
10552 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10553 synonym for @option{--one-file-system}. Since such usage contradicted
10554 to UNIX98 specification and harmed compatibility with other
10555 implementation, it was declared deprecated in version 1.14. However,
10556 to facilitate transition to its new semantics, it was supported by
10557 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10558 variant of @option{--check-links} was introduced in version 1.15.91.
10560 @item Use of options @option{--portability} and @option{--old-archive}
10562 These options are deprecated. Please use @option{--format=v7} instead.
10564 @item Use of option @option{--posix}
10566 This option is deprecated. Please use @option{--format=posix} instead.
10569 @node Configuring Help Summary
10570 @appendix Configuring Help Summary
10572 Running @kbd{tar --help} displays the short @command{tar} option
10573 summary (@pxref{help}). This summary is organized by @dfn{groups} of
10574 semantically close options. The options within each group are printed
10575 in the following order: a short option, eventually followed by a list
10576 of corresponding long option names, followed by a short description of
10577 the option. For example, here is an excerpt from the actual @kbd{tar
10581 Main operation mode:
10583 -A, --catenate, --concatenate append tar files to an archive
10584 -c, --create create a new archive
10585 -d, --diff, --compare find differences between archive and
10587 --delete delete from the archive
10590 @vrindex ARGP_HELP_FMT, environment variable
10591 The exact visual representation of the help output is configurable via
10592 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10593 is a comma-separated list of @dfn{format variable} assignments. There
10594 are two kinds of format variables. An @dfn{offset variable} keeps the
10595 offset of some part of help output text from the leftmost column on
10596 the screen. A @dfn{boolean} variable is a flag that toggles some
10597 output feature on or off. Depending on the type of the corresponding
10598 variable, there are two kinds of assignments:
10601 @item Offset assignment
10603 The assignment to an offset variable has the following syntax:
10606 @var{variable}=@var{value}
10610 where @var{variable} is the variable name, and @var{value} is a
10611 numeric value to be assigned to the variable.
10613 @item Boolean assignment
10615 To assign @code{true} value to a variable, simply put this variable name. To
10616 assign @code{false} value, prefix the variable name with @samp{no-}. For
10621 # Assign @code{true} value:
10623 # Assign @code{false} value:
10629 Following variables are declared:
10631 @deftypevr {Help Output} boolean dup-args
10632 If true, arguments for an option are shown with both short and long
10633 options, even when a given option has both forms, for example:
10636 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10639 If false, then if an option has both short and long forms, the
10640 argument is only shown with the long one, for example:
10643 -f, --file=ARCHIVE use archive file or device ARCHIVE
10647 and a message indicating that the argument is applicable to both
10648 forms is printed below the options. This message can be disabled
10649 using @code{dup-args-note} (see below).
10651 The default is false.
10654 @deftypevr {Help Output} boolean dup-args-note
10655 If this variable is true, which is the default, the following notice
10656 is displayed at the end of the help output:
10659 Mandatory or optional arguments to long options are also mandatory or
10660 optional for any corresponding short options.
10663 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10664 variables @code{dup-args} or @code{dup-args-note} should be set.
10667 @deftypevr {Help Output} offset short-opt-col
10668 Column in which short options start. Default is 2.
10672 $ @kbd{tar --help|grep ARCHIVE}
10673 -f, --file=ARCHIVE use archive file or device ARCHIVE
10674 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10675 -f, --file=ARCHIVE use archive file or device ARCHIVE
10680 @deftypevr {Help Output} offset long-opt-col
10681 Column in which long options start. Default is 6. For example:
10685 $ @kbd{tar --help|grep ARCHIVE}
10686 -f, --file=ARCHIVE use archive file or device ARCHIVE
10687 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10688 -f, --file=ARCHIVE use archive file or device ARCHIVE
10693 @deftypevr {Help Output} offset doc-opt-col
10694 Column in which @dfn{doc options} start. A doc option isn't actually
10695 an option, but rather an arbitrary piece of documentation that is
10696 displayed in much the same manner as the options. For example, in
10697 the description of @option{--format} option:
10701 -H, --format=FORMAT create archive of the given format.
10703 FORMAT is one of the following:
10705 gnu GNU tar 1.13.x format
10706 oldgnu GNU format as per tar <= 1.12
10707 pax POSIX 1003.1-2001 (pax) format
10709 ustar POSIX 1003.1-1988 (ustar) format
10710 v7 old V7 tar format
10715 the format names are doc options. Thus, if you set
10716 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10717 will look as follows:
10721 -H, --format=FORMAT create archive of the given format.
10723 FORMAT is one of the following:
10725 gnu GNU tar 1.13.x format
10726 oldgnu GNU format as per tar <= 1.12
10727 pax POSIX 1003.1-2001 (pax) format
10729 ustar POSIX 1003.1-1988 (ustar) format
10730 v7 old V7 tar format
10735 @deftypevr {Help Output} offset opt-doc-col
10736 Column in which option description starts. Default is 29.
10740 $ @kbd{tar --help|grep ARCHIVE}
10741 -f, --file=ARCHIVE use archive file or device ARCHIVE
10742 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10743 -f, --file=ARCHIVE use archive file or device ARCHIVE
10744 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10746 use archive file or device ARCHIVE
10751 Notice, that the description starts on a separate line if
10752 @code{opt-doc-col} value is too small.
10755 @deftypevr {Help Output} offset header-col
10756 Column in which @dfn{group headers} are printed. A group header is a
10757 descriptive text preceding an option group. For example, in the
10761 Main operation mode:
10763 -A, --catenate, --concatenate append tar files to
10765 -c, --create create a new archive
10768 @samp{Main operation mode:} is the group header.
10770 The default value is 1.
10773 @deftypevr {Help Output} offset usage-indent
10774 Indentation of wrapped usage lines. Affects @option{--usage}
10775 output. Default is 12.
10778 @deftypevr {Help Output} offset rmargin
10779 Right margin of the text output. Used for wrapping.
10782 @node Tar Internals
10783 @appendix Tar Internals
10784 @include intern.texi
10788 @include genfile.texi
10790 @node Free Software Needs Free Documentation
10791 @appendix Free Software Needs Free Documentation
10792 @include freemanuals.texi
10794 @node Copying This Manual
10795 @appendix Copying This Manual
10798 * GNU Free Documentation License:: License for copying this manual
10803 @node Index of Command Line Options
10804 @appendix Index of Command Line Options
10806 This appendix contains an index of all @GNUTAR{} long command line
10807 options. The options are listed without the preceding double-dash.
10808 For a cross-reference of short command line options, @ref{Short Option Summary}.
10821 @c Local variables:
10822 @c texinfo-column-for-description: 32