1 This is tar.info, produced by makeinfo version 4.13 from tar.texi.
3 This manual is for GNU `tar' (version 1.26, 12 March 2011), which
4 creates and extracts files from archives.
6 Copyright (C) 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2003,
7 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
9 Permission is granted to copy, distribute and/or modify this
10 document under the terms of the GNU Free Documentation License,
11 Version 1.3 or any later version published by the Free Software
12 Foundation; with no Invariant Sections, with the Front-Cover Texts
13 being "A GNU Manual", and with the Back-Cover Texts as in (a)
14 below. A copy of the license is included in the section entitled
15 "GNU Free Documentation License".
17 (a) The FSF's Back-Cover Text is: "You have the freedom to copy
18 and modify this GNU manual. Buying copies from the FSF supports
19 it in developing GNU and promoting software freedom."
21 INFO-DIR-SECTION Archiving
23 * Tar: (tar). Making tape (or disk) archives.
26 INFO-DIR-SECTION Individual utilities
28 * tar: (tar)tar invocation. Invoking GNU `tar'.
32 File: tar.info, Node: Top, Next: Introduction, Up: (dir)
34 GNU tar: an archiver tool
35 *************************
37 This manual is for GNU `tar' (version 1.26, 12 March 2011), which
38 creates and extracts files from archives.
40 Copyright (C) 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2003,
41 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
43 Permission is granted to copy, distribute and/or modify this
44 document under the terms of the GNU Free Documentation License,
45 Version 1.3 or any later version published by the Free Software
46 Foundation; with no Invariant Sections, with the Front-Cover Texts
47 being "A GNU Manual", and with the Back-Cover Texts as in (a)
48 below. A copy of the license is included in the section entitled
49 "GNU Free Documentation License".
51 (a) The FSF's Back-Cover Text is: "You have the freedom to copy
52 and modify this GNU manual. Buying copies from the FSF supports
53 it in developing GNU and promoting software freedom."
55 The first part of this master menu lists the major nodes in this Info
56 document. The rest of the menu lists all the lower level nodes.
66 * Date input formats::
69 * Reliability and security::
74 * Configuring Help Summary::
75 * Fixing Snapshot Files::
78 * Free Software Needs Free Documentation::
79 * GNU Free Documentation License::
80 * Index of Command Line Options::
83 --- The Detailed Node Listing ---
87 * Book Contents:: What this Book Contains
88 * Definitions:: Some Definitions
89 * What tar Does:: What `tar' Does
90 * Naming tar Archives:: How `tar' Archives are Named
91 * Authors:: GNU `tar' Authors
92 * Reports:: Reporting bugs or suggestions
94 Tutorial Introduction to `tar'
97 * stylistic conventions::
98 * basic tar options:: Basic `tar' Operations and Options
99 * frequent operations::
100 * Two Frequent Options::
101 * create:: How to Create Archives
102 * list:: How to List Archives
103 * extract:: How to Extract Members from an Archive
106 Two Frequently Used Options
112 How to Create Archives
114 * prepare for examples::
115 * Creating the archive::
124 How to Extract Members from an Archive
126 * extracting archives::
129 * extracting untrusted archives::
135 * using tar options::
145 The Three Option Styles
147 * Long Options:: Long Option Style
148 * Short Options:: Short Option Style
149 * Old Options:: Old Option Style
150 * Mixing:: Mixing Option Styles
154 * Operation Summary::
156 * Short Option Summary::
168 Advanced GNU `tar' Operations
177 How to Add Files to Existing Archives: `--append'
179 * appending files:: Appending Files to an Archive
186 Options Used by `--create'
188 * override:: Overriding File Metadata.
189 * Ignore Failed Read::
191 Options Used by `--extract'
193 * Reading:: Options to Help Read Archives
194 * Writing:: Changing How `tar' Writes Files
195 * Scarce:: Coping with Scarce Resources
197 Options to Help Read Archives
199 * read full records::
202 Changing How `tar' Writes Files
204 * Dealing with Old Files::
205 * Overwrite Old Files::
210 * Data Modification Times::
211 * Setting Access Permissions::
212 * Directory Modification Times and Permissions::
213 * Writing to Standard Output::
214 * Writing to an External Program::
217 Coping with Scarce Resources
222 Performing Backups and Restoring Files
224 * Full Dumps:: Using `tar' to Perform Full Dumps
225 * Incremental Dumps:: Using `tar' to Perform Incremental Dumps
226 * Backup Levels:: Levels of Backups
227 * Backup Parameters:: Setting Parameters for Backups and Restoration
228 * Scripted Backups:: Using the Backup Scripts
229 * Scripted Restoration:: Using the Restore Script
231 Setting Parameters for Backups and Restoration
233 * General-Purpose Variables::
234 * Magnetic Tape Control::
236 * backup-specs example:: An Example Text of `Backup-specs'
238 Choosing Files and Names for `tar'
240 * file:: Choosing the Archive's Name
241 * Selecting Archive Members::
242 * files:: Reading Names from a File
243 * exclude:: Excluding Some Files
244 * wildcards:: Wildcards Patterns and Matching
245 * quoting styles:: Ways of Quoting Special Characters in Names
246 * transform:: Modifying File and Member Names
247 * after:: Operating Only on New Files
248 * recurse:: Descending into Directories
249 * one:: Crossing File System Boundaries
251 Reading Names from a File
257 * problems with exclude::
259 Wildcards Patterns and Matching
261 * controlling pattern-matching::
263 Crossing File System Boundaries
265 * directory:: Changing Directory
266 * absolute:: Absolute File Names
270 * General date syntax:: Common rules.
271 * Calendar date items:: 19 Dec 1994.
272 * Time of day items:: 9:20pm.
273 * Time zone items:: EST, PDT, GMT.
274 * Day of week items:: Monday and others.
275 * Relative items in date strings:: next tuesday, 2 years ago.
276 * Pure numbers in date strings:: 19931219, 1440.
277 * Seconds since the Epoch:: @1078100502.
278 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
279 * Authors of parse_datetime:: Bellovin, Eggert, Salz, Berets, et al.
281 Controlling the Archive Format
283 * Compression:: Using Less Space through Compression
284 * Attributes:: Handling File Attributes
285 * Portability:: Making `tar' Archives More Portable
286 * cpio:: Comparison of `tar' and `cpio'
288 Using Less Space through Compression
290 * gzip:: Creating and Reading Compressed Archives
291 * sparse:: Archiving Sparse Files
293 Creating and Reading Compressed Archives
295 * lbzip2:: Using lbzip2 with GNU `tar'.
297 Making `tar' Archives More Portable
299 * Portable Names:: Portable Names
300 * dereference:: Symbolic Links
301 * hard links:: Hard Links
302 * old:: Old V7 Archives
303 * ustar:: Ustar Archives
304 * gnu:: GNU and old GNU format archives.
305 * posix:: POSIX archives
306 * Checksumming:: Checksumming Problems
307 * Large or Negative Values:: Large files, negative time stamps, etc.
308 * Other Tars:: How to Extract GNU-Specific Data Using
309 Other `tar' Implementations
311 GNU `tar' and POSIX `tar'
313 * PAX keywords:: Controlling Extended Header Keywords.
315 How to Extract GNU-Specific Data Using Other `tar' Implementations
317 * Split Recovery:: Members Split Between Volumes
318 * Sparse Recovery:: Sparse Members
320 Tapes and Other Archive Media
322 * Device:: Device selection and switching
323 * Remote Tape Server::
324 * Common Problems and Solutions::
325 * Blocking:: Blocking
326 * Many:: Many archives on one tape
327 * Using Multiple Tapes:: Using Multiple Tapes
328 * label:: Including a Label in the Archive
334 * Format Variations:: Format Variations
335 * Blocking Factor:: The Blocking Factor of an Archive
337 Many Archives on One Tape
339 * Tape Positioning:: Tape Positions and Tape Marks
340 * mt:: The `mt' Utility
344 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
345 * Tape Files:: Tape Files
346 * Tarcat:: Concatenate Volumes into a Single Archive
351 * Standard:: Basic Tar Format
352 * Extensions:: GNU Extensions to the Archive Format
353 * Sparse Formats:: Storing Sparse Files
360 * PAX 0:: PAX Format, Versions 0.0 and 0.1
361 * PAX 1:: PAX Format, Version 1.0
365 * Generate Mode:: File Generation Mode.
366 * Status Mode:: File Status Mode.
367 * Exec Mode:: Synchronous Execution mode.
371 * GNU Free Documentation License:: License for copying this manual
374 File: tar.info, Node: Introduction, Next: Tutorial, Prev: Top, Up: Top
379 GNU `tar' creates and manipulates "archives" which are actually
380 collections of many other files; the program provides users with an
381 organized and systematic method for controlling a large amount of data.
382 The name "tar" originally came from the phrase "Tape ARchive", but
383 archives need not (and these days, typically do not) reside on tapes.
387 * Book Contents:: What this Book Contains
388 * Definitions:: Some Definitions
389 * What tar Does:: What `tar' Does
390 * Naming tar Archives:: How `tar' Archives are Named
391 * Authors:: GNU `tar' Authors
392 * Reports:: Reporting bugs or suggestions
395 File: tar.info, Node: Book Contents, Next: Definitions, Up: Introduction
397 1.1 What this Book Contains
398 ===========================
400 The first part of this chapter introduces you to various terms that will
401 recur throughout the book. It also tells you who has worked on GNU
402 `tar' and its documentation, and where you should send bug reports or
405 The second chapter is a tutorial (*note Tutorial::) which provides a
406 gentle introduction for people who are new to using `tar'. It is meant
407 to be self-contained, not requiring any reading from subsequent
408 chapters to make sense. It moves from topic to topic in a logical,
409 progressive order, building on information already explained.
411 Although the tutorial is paced and structured to allow beginners to
412 learn how to use `tar', it is not intended solely for beginners. The
413 tutorial explains how to use the three most frequently used operations
414 (`create', `list', and `extract') as well as two frequently used
415 options (`file' and `verbose'). The other chapters do not refer to the
416 tutorial frequently; however, if a section discusses something which is
417 a complex variant of a basic concept, there may be a cross-reference to
418 that basic concept. (The entire book, including the tutorial, assumes
419 that the reader understands some basic concepts of using a Unix-type
420 operating system; *note Tutorial::.)
422 The third chapter presents the remaining five operations, and
423 information about using `tar' options and option syntax.
425 The other chapters are meant to be used as a reference. Each chapter
426 presents everything that needs to be said about a specific topic.
428 One of the chapters (*note Date input formats::) exists in its
429 entirety in other GNU manuals, and is mostly self-contained. In
430 addition, one section of this manual (*note Standard::) contains a big
431 quote which is taken directly from `tar' sources.
433 In general, we give both long and short (abbreviated) option names
434 at least once in each section where the relevant option is covered, so
435 that novice readers will become familiar with both styles. (A few
436 options have no short versions, and the relevant sections will indicate
440 File: tar.info, Node: Definitions, Next: What tar Does, Prev: Book Contents, Up: Introduction
445 The `tar' program is used to create and manipulate `tar' archives. An
446 "archive" is a single file which contains the contents of many files,
447 while still identifying the names of the files, their owner(s), and so
448 forth. (In addition, archives record access permissions, user and
449 group, size in bytes, and data modification time. Some archives also
450 record the file names in each archived directory, as well as other file
451 and directory information.) You can use `tar' to "create" a new
452 archive in a specified directory.
454 The files inside an archive are called "members". Within this
455 manual, we use the term "file" to refer only to files accessible in the
456 normal ways (by `ls', `cat', and so forth), and the term "member" to
457 refer only to the members of an archive. Similarly, a "file name" is
458 the name of a file, as it resides in the file system, and a "member
459 name" is the name of an archive member within the archive.
461 The term "extraction" refers to the process of copying an archive
462 member (or multiple members) into a file in the file system. Extracting
463 all the members of an archive is often called "extracting the archive".
464 The term "unpack" can also be used to refer to the extraction of many
465 or all the members of an archive. Extracting an archive does not
466 destroy the archive's structure, just as creating an archive does not
467 destroy the copies of the files that exist outside of the archive. You
468 may also "list" the members in a given archive (this is often thought
469 of as "printing" them to the standard output, or the command line), or
470 "append" members to a pre-existing archive. All of these operations
471 can be performed using `tar'.
474 File: tar.info, Node: What tar Does, Next: Naming tar Archives, Prev: Definitions, Up: Introduction
479 The `tar' program provides the ability to create `tar' archives, as
480 well as various other kinds of manipulation. For example, you can use
481 `tar' on previously created archives to extract files, to store
482 additional files, or to update or list files which were already stored.
484 Initially, `tar' archives were used to store files conveniently on
485 magnetic tape. The name `tar' comes from this use; it stands for
486 `t'ape `ar'chiver. Despite the utility's name, `tar' can direct its
487 output to available devices, files, or other programs (using pipes).
488 `tar' may even access remote devices or files (as archives).
490 You can use `tar' archives in many ways. We want to stress a few of
491 them: storage, backup, and transportation.
494 Often, `tar' archives are used to store related files for
495 convenient file transfer over a network. For example, the GNU
496 Project distributes its software bundled into `tar' archives, so
497 that all the files relating to a particular program (or set of
498 related programs) can be transferred as a single unit.
500 A magnetic tape can store several files in sequence. However, the
501 tape has no names for these files; it only knows their relative
502 position on the tape. One way to store several files on one tape
503 and retain their names is by creating a `tar' archive. Even when
504 the basic transfer mechanism can keep track of names, as FTP can,
505 the nuisance of handling multiple files, directories, and multiple
506 links makes `tar' archives useful.
508 Archive files are also used for long-term storage. You can think
509 of this as transportation from the present into the future. (It
510 is a science-fiction idiom that you can move through time as well
511 as in space; the idea here is that `tar' can be used to move
512 archives in all dimensions, even time!)
515 Because the archive created by `tar' is capable of preserving file
516 information and directory structure, `tar' is commonly used for
517 performing full and incremental backups of disks. A backup puts a
518 collection of files (possibly pertaining to many users and
519 projects) together on a disk or a tape. This guards against
520 accidental destruction of the information in those files. GNU
521 `tar' has special features that allow it to be used to make
522 incremental and full dumps of all the files in a file system.
525 You can create an archive on one system, transfer it to another
526 system, and extract the contents there. This allows you to
527 transport a group of files from one system to another.
530 File: tar.info, Node: Naming tar Archives, Next: Authors, Prev: What tar Does, Up: Introduction
532 1.4 How `tar' Archives are Named
533 ================================
535 Conventionally, `tar' archives are given names ending with `.tar'.
536 This is not necessary for `tar' to operate properly, but this manual
537 follows that convention in order to accustom readers to it and to make
540 Often, people refer to `tar' archives as "`tar' files," and archive
541 members as "files" or "entries". For people familiar with the
542 operation of `tar', this causes no difficulty. However, in this
543 manual, we consistently refer to "archives" and "archive members" to
544 make learning to use `tar' easier for novice users.
547 File: tar.info, Node: Authors, Next: Reports, Prev: Naming tar Archives, Up: Introduction
549 1.5 GNU `tar' Authors
550 =====================
552 GNU `tar' was originally written by John Gilmore, and modified by many
553 people. The GNU enhancements were written by Jay Fenlason, then Joy
554 Kendall, and the whole package has been further maintained by Thomas
555 Bushnell, n/BSG, Franc,ois Pinard, Paul Eggert, and finally Sergey
556 Poznyakoff with the help of numerous and kind users.
558 We wish to stress that `tar' is a collective work, and owes much to
559 all those people who reported problems, offered solutions and other
560 insights, or shared their thoughts and suggestions. An impressive, yet
561 partial list of those contributors can be found in the `THANKS' file
562 from the GNU `tar' distribution.
564 Jay Fenlason put together a draft of a GNU `tar' manual, borrowing
565 notes from the original man page from John Gilmore. This was withdrawn
566 in version 1.11. Thomas Bushnell, n/BSG and Amy Gorin worked on a
567 tutorial and manual for GNU `tar'. Franc,ois Pinard put version 1.11.8
568 of the manual together by taking information from all these sources and
569 merging them. Melissa Weisshaus finally edited and redesigned the book
570 to create version 1.12. The book for versions from 1.14 up to 1.26
571 were edited by the current maintainer, Sergey Poznyakoff.
573 For version 1.12, Daniel Hagerty contributed a great deal of
574 technical consulting. In particular, he is the primary author of *note
577 In July, 2003 GNU `tar' was put on CVS at savannah.gnu.org (see
578 `http://savannah.gnu.org/projects/tar'), and active development and
579 maintenance work has started again. Currently GNU `tar' is being
580 maintained by Paul Eggert, Sergey Poznyakoff and Jeff Bailey.
582 Support for POSIX archives was added by Sergey Poznyakoff.
585 File: tar.info, Node: Reports, Prev: Authors, Up: Introduction
587 1.6 Reporting bugs or suggestions
588 =================================
590 If you find problems or have suggestions about this program or manual,
591 please report them to `bug-tar@gnu.org'.
593 When reporting a bug, please be sure to include as much detail as
594 possible, in order to reproduce it.
597 File: tar.info, Node: Tutorial, Next: tar invocation, Prev: Introduction, Up: Top
599 2 Tutorial Introduction to `tar'
600 ********************************
602 This chapter guides you through some basic examples of three `tar'
603 operations: `--create', `--list', and `--extract'. If you already know
604 how to use some other version of `tar', then you may not need to read
605 this chapter. This chapter omits most complicated details about how
611 * stylistic conventions::
612 * basic tar options:: Basic `tar' Operations and Options
613 * frequent operations::
614 * Two Frequent Options::
615 * create:: How to Create Archives
616 * list:: How to List Archives
617 * extract:: How to Extract Members from an Archive
621 File: tar.info, Node: assumptions, Next: stylistic conventions, Up: Tutorial
623 2.1 Assumptions this Tutorial Makes
624 ===================================
626 This chapter is paced to allow beginners to learn about `tar' slowly.
627 At the same time, we will try to cover all the basic aspects of these
628 three operations. In order to accomplish both of these tasks, we have
629 made certain assumptions about your knowledge before reading this
630 manual, and the hardware you will be using:
632 * Before you start to work through this tutorial, you should
633 understand what the terms "archive" and "archive member" mean
634 (*note Definitions::). In addition, you should understand
635 something about how Unix-type operating systems work, and you
636 should know how to use some basic utilities. For example, you
637 should know how to create, list, copy, rename, edit, and delete
638 files and directories; how to change between directories; and how
639 to figure out where you are in the file system. You should have
640 some basic understanding of directory structure and how files are
641 named according to which directory they are in. You should
642 understand concepts such as standard output and standard input,
643 what various definitions of the term `argument' mean, and the
644 differences between relative and absolute file names.
646 * This manual assumes that you are working from your own home
647 directory (unless we state otherwise). In this tutorial, you will
648 create a directory to practice `tar' commands in. When we show
649 file names, we will assume that those names are relative to your
650 home directory. For example, my home directory is
651 `/home/fsf/melissa'. All of my examples are in a subdirectory of
652 the directory named by that file name; the subdirectory is called
655 * In general, we show examples of archives which exist on (or can be
656 written to, or worked with from) a directory on a hard disk. In
657 most cases, you could write those archives to, or work with them
658 on any other device, such as a tape drive. However, some of the
659 later examples in the tutorial and next chapter will not work on
660 tape drives. Additionally, working with tapes is much more
661 complicated than working with hard disks. For these reasons, the
662 tutorial does not cover working with tape drives. *Note Media::,
663 for complete information on using `tar' archives with tape drives.
667 File: tar.info, Node: stylistic conventions, Next: basic tar options, Prev: assumptions, Up: Tutorial
669 2.2 Stylistic Conventions
670 =========================
672 In the examples, `$' represents a typical shell prompt. It precedes
673 lines you should type; to make this more clear, those lines are shown
674 in `this font', as opposed to lines which represent the computer's
675 response; those lines are shown in `this font', or sometimes `like
679 File: tar.info, Node: basic tar options, Next: frequent operations, Prev: stylistic conventions, Up: Tutorial
681 2.3 Basic `tar' Operations and Options
682 ======================================
684 `tar' can take a wide variety of arguments which specify and define the
685 actions it will have on the particular set of files or the archive.
686 The main types of arguments to `tar' fall into one of two classes:
687 operations, and options.
689 Some arguments fall into a class called "operations"; exactly one of
690 these is both allowed and required for any instance of using `tar'; you
691 may _not_ specify more than one. People sometimes speak of "operating
692 modes". You are in a particular operating mode when you have specified
693 the operation which specifies it; there are eight operations in total,
694 and thus there are eight operating modes.
696 The other arguments fall into the class known as "options". You are
697 not required to specify any options, and you are allowed to specify more
698 than one at a time (depending on the way you are using `tar' at that
699 time). Some options are used so frequently, and are so useful for
700 helping you type commands more carefully that they are effectively
701 "required". We will discuss them in this chapter.
703 You can write most of the `tar' operations and options in any of
704 three forms: long (mnemonic) form, short form, and old style. Some of
705 the operations and options have no short or "old" forms; however, the
706 operations and options which we will cover in this tutorial have
707 corresponding abbreviations. We will indicate those abbreviations
708 appropriately to get you used to seeing them. Note, that the "old
709 style" option forms exist in GNU `tar' for compatibility with Unix
710 `tar'. In this book we present a full discussion of this way of
711 writing options and operations (*note Old Options::), and we discuss
712 the other two styles of writing options (*Note Long Options::, and
713 *note Short Options::).
715 In the examples and in the text of this tutorial, we usually use the
716 long forms of operations and options; but the "short" forms produce the
717 same result and can make typing long `tar' commands easier. For
718 example, instead of typing
720 tar --create --verbose --file=afiles.tar apple angst aspic
723 tar -c -v -f afiles.tar apple angst aspic
726 tar -cvf afiles.tar apple angst aspic
728 For more information on option syntax, see *note Advanced tar::. In
729 discussions in the text, when we name an option by its long form, we
730 also give the corresponding short option in parentheses.
732 The term, "option", can be confusing at times, since "operations"
733 are often lumped in with the actual, _optional_ "options" in certain
734 general class statements. For example, we just talked about "short and
735 long forms of options and operations". However, experienced `tar'
736 users often refer to these by shorthand terms such as, "short and long
737 options". This term assumes that the "operations" are included, also.
738 Context will help you determine which definition of "options" to use.
740 Similarly, the term "command" can be confusing, as it is often used
741 in two different ways. People sometimes refer to `tar' "commands". A
742 `tar' "command" is the entire command line of user input which tells
743 `tar' what to do -- including the operation, options, and any arguments
744 (file names, pipes, other commands, etc.). However, you will also
745 sometimes hear the term "the `tar' command". When the word "command"
746 is used specifically like this, a person is usually referring to the
747 `tar' _operation_, not the whole line. Again, use context to figure
748 out which of the meanings the speaker intends.
751 File: tar.info, Node: frequent operations, Next: Two Frequent Options, Prev: basic tar options, Up: Tutorial
753 2.4 The Three Most Frequently Used Operations
754 =============================================
756 Here are the three most frequently used operations (both short and long
757 forms), as well as a brief description of their meanings. The rest of
758 this chapter will cover how to use these operations in detail. We will
759 present the rest of the operations in the next chapter.
763 Create a new `tar' archive.
767 List the contents of an archive.
771 Extract one or more members from an archive.
774 File: tar.info, Node: Two Frequent Options, Next: create, Prev: frequent operations, Up: Tutorial
776 2.5 Two Frequently Used Options
777 ===============================
779 To understand how to run `tar' in the three operating modes listed
780 previously, you also need to understand how to use two of the options to
781 `tar': `--file' (which takes an archive file as an argument) and
782 `--verbose'. (You are usually not _required_ to specify either of
783 these options when you run `tar', but they can be very useful in making
784 things more clear and helping you avoid errors.)
793 File: tar.info, Node: file tutorial, Next: verbose tutorial, Up: Two Frequent Options
798 `--file=ARCHIVE-NAME'
800 Specify the name of an archive file.
802 You can specify an argument for the `--file=ARCHIVE-NAME' (`-f
803 ARCHIVE-NAME') option whenever you use `tar'; this option determines
804 the name of the archive file that `tar' will work on.
806 If you don't specify this argument, then `tar' will examine the
807 environment variable `TAPE'. If it is set, its value will be used as
808 the archive name. Otherwise, `tar' will use the default archive,
809 determined at compile time. Usually it is standard output or some
810 physical tape drive attached to your machine (you can verify what the
811 default is by running `tar --show-defaults', *note defaults::). If
812 there is no tape drive attached, or the default is not meaningful, then
813 `tar' will print an error message. The error message might look
814 roughly like one of the following:
816 tar: can't open /dev/rmt8 : No such device or address
817 tar: can't open /dev/rsmt0 : I/O error
819 To avoid confusion, we recommend that you always specify an archive file
820 name by using `--file=ARCHIVE-NAME' (`-f ARCHIVE-NAME') when writing
821 your `tar' commands. For more information on using the
822 `--file=ARCHIVE-NAME' (`-f ARCHIVE-NAME') option, see *note file::.
825 File: tar.info, Node: verbose tutorial, Next: help tutorial, Prev: file tutorial, Up: Two Frequent Options
827 The `--verbose' Option
828 ----------------------
832 Show the files being worked on as `tar' is running.
834 `--verbose' (`-v') shows details about the results of running `tar'.
835 This can be especially useful when the results might not be obvious.
836 For example, if you want to see the progress of `tar' as it writes
837 files into the archive, you can use the `--verbose' option. In the
838 beginning, you may find it useful to use `--verbose' at all times; when
839 you are more accustomed to `tar', you will likely want to use it at
840 certain times but not at others. We will use `--verbose' at times to
841 help make something clear, and we will give many examples both using
842 and not using `--verbose' to show the differences.
844 Each instance of `--verbose' on the command line increases the
845 verbosity level by one, so if you need more details on the output,
848 When reading archives (`--list', `--extract', `--diff'), `tar' by
849 default prints only the names of the members being extracted. Using
850 `--verbose' will show a full, `ls' style member listing.
852 In contrast, when writing archives (`--create', `--append',
853 `--update'), `tar' does not print file names by default. So, a single
854 `--verbose' option shows the file names being added to the archive,
855 while two `--verbose' options enable the full listing.
857 For example, to create an archive in verbose mode:
859 $ tar -cvf afiles.tar apple angst aspic
864 Creating the same archive with the verbosity level 2 could give:
866 $ tar -cvvf afiles.tar apple angst aspic
867 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
868 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
869 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
871 This works equally well using short or long forms of options. Using
872 long forms, you would simply write out the mnemonic form of the option
875 $ tar --create --verbose --verbose ...
877 Note that you must double the hyphens properly each time.
879 Later in the tutorial, we will give examples using
880 `--verbose --verbose'.
882 The full output consists of six fields:
884 * File type and permissions in symbolic form. These are displayed
885 in the same format as the first column of `ls -l' output (*note
886 format=verbose: (fileutils)What information is listed.).
888 * Owner name and group separated by a slash character. If these
889 data are not available (for example, when listing a `v7' format
890 archive), numeric ID values are printed instead.
892 * Size of the file, in bytes.
894 * File modification date in ISO 8601 format.
896 * File modification time.
898 * File name. If the name contains any special characters (white
899 space, newlines, etc.) these are displayed in an unambiguous form
900 using so called "quoting style". For the detailed discussion of
901 available styles and on how to use them, see *note quoting
904 Depending on the file type, the name can be followed by some
905 additional information, described in the following table:
908 The file or archive member is a "symbolic link" and LINK-NAME
909 is the name of file it links to.
912 The file or archive member is a "hard link" and LINK-NAME is
913 the name of file it links to.
916 The archive member is an old GNU format long link. You will
917 normally not encounter this.
920 The archive member is an old GNU format long name. You will
921 normally not encounter this.
924 The archive member is a GNU "volume header" (*note Tape
927 `--Continued at byte N--'
928 Encountered only at the beginning of a multi-volume archive
929 (*note Using Multiple Tapes::). This archive member is a
930 continuation from the previous volume. The number N gives the
931 offset where the original file was split.
933 `unknown file type C'
934 An archive member of unknown type. C is the type character
935 from the archive header. If you encounter such a message, it
936 means that either your archive contains proprietary member
937 types GNU `tar' is not able to handle, or the archive is
941 For example, here is an archive listing containing most of the
942 special suffixes explained above:
944 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
945 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at byte 32456--
946 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
947 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
948 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
949 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
953 File: tar.info, Node: help tutorial, Prev: verbose tutorial, Up: Two Frequent Options
955 Getting Help: Using the `--help' Option
956 ---------------------------------------
959 The `--help' option to `tar' prints out a very brief list of all
960 operations and option available for the current version of `tar'
961 available on your system.
964 File: tar.info, Node: create, Next: list, Prev: Two Frequent Options, Up: Tutorial
966 2.6 How to Create Archives
967 ==========================
969 _(This message will disappear, once this node revised.)_
971 One of the basic operations of `tar' is `--create' (`-c'), which you
972 use to create a `tar' archive. We will explain `--create' first
973 because, in order to learn about the other operations, you will find it
974 useful to have an archive available to practice on.
976 To make this easier, in this section you will first create a
977 directory containing three files. Then, we will show you how to create
978 an _archive_ (inside the new directory). Both the directory, and the
979 archive are specifically for you to practice on. The rest of this
980 chapter and the next chapter will show many examples using this
981 directory and the files you will create: some of those files may be
982 other directories and other archives.
984 The three files you will archive in this example are called `blues',
985 `folk', and `jazz'. The archive is called `collection.tar'.
987 This section will proceed slowly, detailing how to use `--create' in
988 `verbose' mode, and showing examples using both short and long forms.
989 In the rest of the tutorial, and in the examples in the next chapter,
990 we will proceed at a slightly quicker pace. This section moves more
991 slowly to allow beginning users to understand how `tar' works.
995 * prepare for examples::
996 * Creating the archive::
1002 File: tar.info, Node: prepare for examples, Next: Creating the archive, Up: create
1004 2.6.1 Preparing a Practice Directory for Examples
1005 -------------------------------------------------
1007 To follow along with this and future examples, create a new directory
1008 called `practice' containing files called `blues', `folk' and `jazz'.
1009 The files can contain any information you like: ideally, they should
1010 contain information which relates to their names, and be of different
1011 lengths. Our examples assume that `practice' is a subdirectory of your
1014 Now `cd' to the directory named `practice'; `practice' is now your
1015 "working directory". (_Please note_: Although the full file name of
1016 this directory is `/HOMEDIR/practice', in our examples we will refer to
1017 this directory as `practice'; the HOMEDIR is presumed.)
1019 In general, you should check that the files to be archived exist
1020 where you think they do (in the working directory) by running `ls'.
1021 Because you just created the directory and the files and have changed to
1022 that directory, you probably don't need to do that this time.
1024 It is very important to make sure there isn't already a file in the
1025 working directory with the archive name you intend to use (in this case,
1026 `collection.tar'), or that you don't care about its contents. Whenever
1027 you use `create', `tar' will erase the current contents of the file
1028 named by `--file=ARCHIVE-NAME' (`-f ARCHIVE-NAME') if it exists. `tar'
1029 will not tell you if you are about to overwrite an archive unless you
1030 specify an option which does this (*note backup::, for the information
1031 on how to do so). To add files to an existing archive, you need to use
1032 a different option, such as `--append' (`-r'); see *note append:: for
1033 information on how to do this.
1036 File: tar.info, Node: Creating the archive, Next: create verbose, Prev: prepare for examples, Up: create
1038 2.6.2 Creating the Archive
1039 --------------------------
1041 To place the files `blues', `folk', and `jazz' into an archive named
1042 `collection.tar', use the following command:
1044 $ tar --create --file=collection.tar blues folk jazz
1046 The order of the arguments is not very important, _when using long
1047 option forms_. You could also say:
1049 $ tar blues --create folk --file=collection.tar jazz
1051 However, you can see that this order is harder to understand; this is
1052 why we will list the arguments in the order that makes the commands
1053 easiest to understand (and we encourage you to do the same when you use
1054 `tar', to avoid errors).
1056 Note that the sequence `--file=collection.tar' is considered to be
1057 _one_ argument. If you substituted any other string of characters for
1058 `collection.tar', then that string would become the name of the
1059 archive file you create.
1061 The order of the options becomes more important when you begin to use
1062 short forms. With short forms, if you type commands in the wrong order
1063 (even if you type them correctly in all other ways), you may end up with
1064 results you don't expect. For this reason, it is a good idea to get
1065 into the habit of typing options in the order that makes inherent sense.
1066 *Note short create::, for more information on this.
1068 In this example, you type the command as shown above: `--create' is
1069 the operation which creates the new archive (`collection.tar'), and
1070 `--file' is the option which lets you give it the name you chose. The
1071 files, `blues', `folk', and `jazz', are now members of the archive,
1072 `collection.tar' (they are "file name arguments" to the `--create'
1073 operation. *Note Choosing::, for the detailed discussion on these.)
1074 Now that they are in the archive, they are called _archive members_,
1075 not files. (*note members: Definitions.).
1077 When you create an archive, you _must_ specify which files you want
1078 placed in the archive. If you do not specify any archive members, GNU
1079 `tar' will complain.
1081 If you now list the contents of the working directory (`ls'), you
1082 will find the archive file listed as well as the files you saw
1085 blues folk jazz collection.tar
1087 Creating the archive `collection.tar' did not destroy the copies of the
1088 files in the directory.
1090 Keep in mind that if you don't indicate an operation, `tar' will not
1091 run and will prompt you for one. If you don't name any files, `tar'
1092 will complain. You must have write access to the working directory, or
1093 else you will not be able to create an archive in that directory.
1095 _Caution_: Do not attempt to use `--create' (`-c') to add files to
1096 an existing archive; it will delete the archive and write a new one.
1097 Use `--append' (`-r') instead. *Note append::.
1100 File: tar.info, Node: create verbose, Next: short create, Prev: Creating the archive, Up: create
1102 2.6.3 Running `--create' with `--verbose'
1103 -----------------------------------------
1105 If you include the `--verbose' (`-v') option on the command line, `tar'
1106 will list the files it is acting on as it is working. In verbose mode,
1107 the `create' example above would appear as:
1109 $ tar --create --verbose --file=collection.tar blues folk jazz
1114 This example is just like the example we showed which did not use
1115 `--verbose', except that `tar' generated the remaining lines.
1117 In the rest of the examples in this chapter, we will frequently use
1118 `verbose' mode so we can show actions or `tar' responses that you would
1119 otherwise not see, and which are important for you to understand.
1122 File: tar.info, Node: short create, Next: create dir, Prev: create verbose, Up: create
1124 2.6.4 Short Forms with `create'
1125 -------------------------------
1127 As we said before, the `--create' (`-c') operation is one of the most
1128 basic uses of `tar', and you will use it countless times. Eventually,
1129 you will probably want to use abbreviated (or "short") forms of
1130 options. A full discussion of the three different forms that options
1131 can take appears in *note Styles::; for now, here is what the previous
1132 example (including the `--verbose' (`-v') option) looks like using
1135 $ tar -cvf collection.tar blues folk jazz
1140 As you can see, the system responds the same no matter whether you use
1141 long or short option forms.
1143 One difference between using short and long option forms is that,
1144 although the exact placement of arguments following options is no more
1145 specific when using short forms, it is easier to become confused and
1146 make a mistake when using short forms. For example, suppose you
1147 attempted the above example in the following way:
1149 $ tar -cfv collection.tar blues folk jazz
1151 In this case, `tar' will make an archive file called `v', containing
1152 the files `blues', `folk', and `jazz', because the `v' is the closest
1153 "file name" to the `-f' option, and is thus taken to be the chosen
1154 archive file name. `tar' will try to add a file called
1155 `collection.tar' to the `v' archive file; if the file `collection.tar'
1156 did not already exist, `tar' will report an error indicating that this
1157 file does not exist. If the file `collection.tar' does already exist
1158 (e.g., from a previous command you may have run), then `tar' will add
1159 this file to the archive. Because the `-v' option did not get
1160 registered, `tar' will not run under `verbose' mode, and will not
1161 report its progress.
1163 The end result is that you may be quite confused about what happened,
1164 and possibly overwrite a file. To illustrate this further, we will show
1165 you how an example we showed previously would look using short forms.
1169 $ tar blues --create folk --file=collection.tar jazz
1171 is confusing as it is. When shown using short forms, however, it
1172 becomes much more so:
1174 $ tar blues -c folk -f collection.tar jazz
1176 It would be very easy to put the wrong string of characters immediately
1177 following the `-f', but doing that could sacrifice valuable data.
1179 For this reason, we recommend that you pay very careful attention to
1180 the order of options and placement of file and archive names,
1181 especially when using short option forms. Not having the option name
1182 written out mnemonically can affect how well you remember which option
1183 does what, and therefore where different names have to be placed.
1186 File: tar.info, Node: create dir, Prev: short create, Up: create
1188 2.6.5 Archiving Directories
1189 ---------------------------
1191 You can archive a directory by specifying its directory name as a file
1192 name argument to `tar'. The files in the directory will be archived
1193 relative to the working directory, and the directory will be re-created
1194 along with its contents when the archive is extracted.
1196 To archive a directory, first move to its superior directory. If you
1197 have followed the previous instructions in this tutorial, you should
1203 This will put you into the directory which contains `practice', i.e.,
1204 your home directory. Once in the superior directory, you can specify
1205 the subdirectory, `practice', as a file name argument. To store
1206 `practice' in the new archive file `music.tar', type:
1208 $ tar --create --verbose --file=music.tar practice
1210 `tar' should output:
1216 practice/collection.tar
1218 Note that the archive thus created is not in the subdirectory
1219 `practice', but rather in the current working directory--the directory
1220 from which `tar' was invoked. Before trying to archive a directory
1221 from its superior directory, you should make sure you have write access
1222 to the superior directory itself, not only the directory you are trying
1223 archive with `tar'. For example, you will probably not be able to
1224 store your home directory in an archive by invoking `tar' from the root
1225 directory; *Note absolute::. (Note also that `collection.tar', the
1226 original archive file, has itself been archived. `tar' will accept any
1227 file as a file to be archived, regardless of its content. When
1228 `music.tar' is extracted, the archive file `collection.tar' will be
1229 re-written into the file system).
1231 If you give `tar' a command such as
1233 $ tar --create --file=foo.tar .
1235 `tar' will report `tar: ./foo.tar is the archive; not dumped'. This
1236 happens because `tar' creates the archive `foo.tar' in the current
1237 directory before putting any files into it. Then, when `tar' attempts
1238 to add all the files in the directory `.' to the archive, it notices
1239 that the file `./foo.tar' is the same as the archive `foo.tar', and
1240 skips it. (It makes no sense to put an archive into itself.) GNU `tar'
1241 will continue in this case, and create the archive normally, except for
1242 the exclusion of that one file. (_Please note:_ Other implementations
1243 of `tar' may not be so clever; they will enter an infinite loop when
1244 this happens, so you should not depend on this behavior unless you are
1245 certain you are running GNU `tar'. In general, it is wise to always
1246 place the archive outside of the directory being dumped.)
1249 File: tar.info, Node: list, Next: extract, Prev: create, Up: Tutorial
1251 2.7 How to List Archives
1252 ========================
1254 Frequently, you will find yourself wanting to determine exactly what a
1255 particular archive contains. You can use the `--list' (`-t') operation
1256 to get the member names as they currently appear in the archive, as
1257 well as various attributes of the files at the time they were archived.
1258 For example, you can examine the archive `collection.tar' that you
1259 created in the last section with the command,
1261 $ tar --list --file=collection.tar
1263 The output of `tar' would then be:
1269 The archive `bfiles.tar' would list as follows:
1275 Be sure to use a `--file=ARCHIVE-NAME' (`-f ARCHIVE-NAME') option just
1276 as with `--create' (`-c') to specify the name of the archive.
1278 If you use the `--verbose' (`-v') option with `--list', then `tar'
1279 will print out a listing reminiscent of `ls -l', showing owner, file
1280 size, and so forth. This output is described in detail in *note
1281 verbose member listing::.
1283 If you had used `--verbose' (`-v') mode, the example above would
1286 $ tar --list --verbose --file=collection.tar folk
1287 -rw-r--r-- myself/user 62 1990-05-23 10:55 folk
1289 It is important to notice that the output of `tar --list --verbose'
1290 does not necessarily match that produced by `tar --create --verbose'
1291 while creating the archive. It is because GNU `tar', unless told
1292 explicitly not to do so, removes some directory prefixes from file
1293 names before storing them in the archive (*Note absolute::, for more
1294 information). In other words, in verbose mode GNU `tar' shows "file
1295 names" when creating an archive and "member names" when listing it.
1296 Consider this example:
1298 $ tar --create --verbose --file archive /etc/mail
1299 tar: Removing leading `/' from member names
1301 /etc/mail/sendmail.cf
1303 $ tar --test --file archive
1305 etc/mail/sendmail.cf
1308 This default behavior can sometimes be inconvenient. You can force
1309 GNU `tar' show member names when creating archive by supplying
1310 `--show-stored-names' option.
1312 `--show-stored-names'
1313 Print member (as opposed to _file_) names when creating the
1316 You can specify one or more individual member names as arguments when
1317 using `list'. In this case, `tar' will only list the names of members
1318 you identify. For example, `tar --list --file=afiles.tar apple' would
1321 Because `tar' preserves file names, these must be specified as they
1322 appear in the archive (i.e., relative to the directory from which the
1323 archive was created). Therefore, it is essential when specifying
1324 member names to `tar' that you give the exact member names. For
1325 example, `tar --list --file=bfiles.tar birds' would produce an error
1326 message something like `tar: birds: Not found in archive', because
1327 there is no member named `birds', only one named `./birds'. While the
1328 names `birds' and `./birds' name the same file, _member_ names by
1329 default are compared verbatim.
1331 However, `tar --list --file=bfiles.tar baboon' would respond with
1332 `baboon', because this exact member name is in the archive file
1333 `bfiles.tar'. If you are not sure of the exact file name, use
1334 "globbing patterns", for example:
1336 $ tar --list --file=bfiles.tar --wildcards '*b*'
1338 will list all members whose name contains `b'. *Note wildcards::, for
1339 a detailed discussion of globbing patterns and related `tar' command
1347 File: tar.info, Node: list dir, Up: list
1349 Listing the Contents of a Stored Directory
1350 ------------------------------------------
1352 To get information about the contents of an archived directory, use the
1353 directory name as a file name argument in conjunction with `--list'
1354 (`-t'). To find out file attributes, include the `--verbose' (`-v')
1357 For example, to find out about files in the directory `practice', in
1358 the archive file `music.tar', type:
1360 $ tar --list --verbose --file=music.tar practice
1364 drwxrwxrwx myself/user 0 1990-05-31 21:49 practice/
1365 -rw-r--r-- myself/user 42 1990-05-21 13:29 practice/blues
1366 -rw-r--r-- myself/user 62 1990-05-23 10:55 practice/folk
1367 -rw-r--r-- myself/user 40 1990-05-21 13:30 practice/jazz
1368 -rw-r--r-- myself/user 10240 1990-05-31 21:49 practice/collection.tar
1370 When you use a directory name as a file name argument, `tar' acts on
1371 all the files (including sub-directories) in that directory.
1374 File: tar.info, Node: extract, Next: going further, Prev: list, Up: Tutorial
1376 2.8 How to Extract Members from an Archive
1377 ==========================================
1379 Creating an archive is only half the job--there is no point in storing
1380 files in an archive if you can't retrieve them. The act of retrieving
1381 members from an archive so they can be used and manipulated as
1382 unarchived files again is called "extraction". To extract files from
1383 an archive, use the `--extract' (`--get' or `-x') operation. As with
1384 `--create', specify the name of the archive with `--file' (`-f')
1385 option. Extracting an archive does not modify the archive in any way;
1386 you can extract it multiple times if you want or need to.
1388 Using `--extract', you can extract an entire archive, or specific
1389 files. The files can be directories containing other files, or not. As
1390 with `--create' (`-c') and `--list' (`-t'), you may use the short or the
1391 long form of the operation without affecting the performance.
1395 * extracting archives::
1396 * extracting files::
1398 * extracting untrusted archives::
1399 * failing commands::
1402 File: tar.info, Node: extracting archives, Next: extracting files, Up: extract
1404 2.8.1 Extracting an Entire Archive
1405 ----------------------------------
1407 To extract an entire archive, specify the archive file name only, with
1408 no individual file names as arguments. For example,
1410 $ tar -xvf collection.tar
1414 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
1415 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
1416 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
1419 File: tar.info, Node: extracting files, Next: extract dir, Prev: extracting archives, Up: extract
1421 2.8.2 Extracting Specific Files
1422 -------------------------------
1424 To extract specific archive members, give their exact member names as
1425 arguments, as printed by `--list' (`-t'). If you had mistakenly
1426 deleted one of the files you had placed in the archive `collection.tar'
1427 earlier (say, `blues'), you can extract it from the archive without
1428 changing the archive's structure. Its contents will be identical to
1429 the original file `blues' that you deleted.
1431 First, make sure you are in the `practice' directory, and list the
1432 files in the directory. Now, delete the file, `blues', and list the
1433 files in the directory again.
1435 You can now extract the member `blues' from the archive file
1436 `collection.tar' like this:
1438 $ tar --extract --file=collection.tar blues
1440 If you list the files in the directory again, you will see that the file
1441 `blues' has been restored, with its original permissions, data
1442 modification times, and owner.(1) (These parameters will be identical
1443 to those which the file had when you originally placed it in the
1444 archive; any changes you may have made before deleting the file from
1445 the file system, however, will _not_ have been made to the archive
1446 member.) The archive file, `collection.tar', is the same as it was
1447 before you extracted `blues'. You can confirm this by running `tar'
1448 with `--list' (`-t').
1450 Remember that as with other operations, specifying the exact member
1451 name is important. `tar --extract --file=bfiles.tar birds' will fail,
1452 because there is no member named `birds'. To extract the member named
1453 `./birds', you must specify `tar --extract --file=bfiles.tar ./birds'.
1454 If you don't remember the exact member names, use `--list' (`-t') option
1455 (*note list::). You can also extract those members that match a
1456 specific "globbing pattern". For example, to extract from `bfiles.tar'
1457 all files that begin with `b', no matter their directory prefix, you
1460 $ tar -x -f bfiles.tar --wildcards --no-anchored 'b*'
1462 Here, `--wildcards' instructs `tar' to treat command line arguments as
1463 globbing patterns and `--no-anchored' informs it that the patterns
1464 apply to member names after any `/' delimiter. The use of globbing
1465 patterns is discussed in detail in *Note wildcards::.
1467 You can extract a file to standard output by combining the above
1468 options with the `--to-stdout' (`-O') option (*note Writing to Standard
1471 If you give the `--verbose' option, then `--extract' will print the
1472 names of the archive members as it extracts them.
1474 ---------- Footnotes ----------
1476 (1) This is only accidentally true, but not in general. Whereas
1477 modification times are always restored, in most cases, one has to be
1478 root for restoring the owner, and use a special option for restoring
1479 permissions. Here, it just happens that the restoring user is also the
1480 owner of the archived members, and that the current `umask' is
1481 compatible with original permissions.
1484 File: tar.info, Node: extract dir, Next: extracting untrusted archives, Prev: extracting files, Up: extract
1486 2.8.3 Extracting Files that are Directories
1487 -------------------------------------------
1489 Extracting directories which are members of an archive is similar to
1490 extracting other files. The main difference to be aware of is that if
1491 the extracted directory has the same name as any directory already in
1492 the working directory, then files in the extracted directory will be
1493 placed into the directory of the same name. Likewise, if there are
1494 files in the pre-existing directory with the same names as the members
1495 which you extract, the files from the extracted archive will replace
1496 the files already in the working directory (and possible
1497 subdirectories). This will happen regardless of whether or not the
1498 files in the working directory were more recent than those extracted
1499 (there exist, however, special options that alter this behavior *note
1502 However, if a file was stored with a directory name as part of its
1503 file name, and that directory does not exist under the working
1504 directory when the file is extracted, `tar' will create the directory.
1506 We can demonstrate how to use `--extract' to extract a directory
1507 file with an example. Change to the `practice' directory if you
1508 weren't there, and remove the files `folk' and `jazz'. Then, go back
1509 to the parent directory and extract the archive `music.tar'. You may
1510 either extract the entire archive, or you may extract only the files
1511 you just deleted. To extract the entire archive, don't give any file
1512 names as arguments after the archive name `music.tar'. To extract only
1513 the files you deleted, use the following command:
1515 $ tar -xvf music.tar practice/folk practice/jazz
1519 If you were to specify two `--verbose' (`-v') options, `tar' would have
1520 displayed more detail about the extracted files, as shown in the
1523 $ tar -xvvf music.tar practice/folk practice/jazz
1524 -rw-r--r-- me/user 28 1996-10-18 16:31 practice/jazz
1525 -rw-r--r-- me/user 20 1996-09-23 16:44 practice/folk
1527 Because you created the directory with `practice' as part of the file
1528 names of each of the files by archiving the `practice' directory as
1529 `practice', you must give `practice' as part of the file names when you
1530 extract those files from the archive.
1533 File: tar.info, Node: extracting untrusted archives, Next: failing commands, Prev: extract dir, Up: extract
1535 2.8.4 Extracting Archives from Untrusted Sources
1536 ------------------------------------------------
1538 Extracting files from archives can overwrite files that already exist.
1539 If you receive an archive from an untrusted source, you should make a
1540 new directory and extract into that directory, so that you don't have
1541 to worry about the extraction overwriting one of your existing files.
1542 For example, if `untrusted.tar' came from somewhere else on the
1543 Internet, and you don't necessarily trust its contents, you can extract
1548 $ tar -xvf ../untrusted.tar
1550 It is also a good practice to examine contents of the archive before
1551 extracting it, using `--list' (`-t') option, possibly combined with
1555 File: tar.info, Node: failing commands, Prev: extracting untrusted archives, Up: extract
1557 2.8.5 Commands That Will Fail
1558 -----------------------------
1560 Here are some sample commands you might try which will not work, and why
1563 If you try to use this command,
1565 $ tar -xvf music.tar folk jazz
1567 you will get the following response:
1569 tar: folk: Not found in archive
1570 tar: jazz: Not found in archive
1572 This is because these files were not originally _in_ the parent
1573 directory `..', where the archive is located; they were in the
1574 `practice' directory, and their file names reflect this:
1576 $ tar -tvf music.tar
1581 Likewise, if you try to use this command,
1583 $ tar -tvf music.tar folk jazz
1585 you would get a similar response. Members with those names are not in
1586 the archive. You must use the correct member names, or wildcards, in
1587 order to extract the files from the archive.
1589 If you have forgotten the correct names of the files in the archive,
1590 use `tar --list --verbose' to list them correctly.
1593 File: tar.info, Node: going further, Prev: extract, Up: Tutorial
1595 2.9 Going Further Ahead in this Manual
1596 ======================================
1598 _(This message will disappear, once this node revised.)_
1601 File: tar.info, Node: tar invocation, Next: operations, Prev: Tutorial, Up: Top
1603 3 Invoking GNU `tar'
1604 ********************
1606 This chapter is about how one invokes the GNU `tar' command, from the
1607 command synopsis (*note Synopsis::). There are numerous options, and
1608 many styles for writing them. One mandatory option specifies the
1609 operation `tar' should perform (*note Operation Summary::), other
1610 options are meant to detail how this operation should be performed
1611 (*note Option Summary::). Non-option arguments are not always
1612 interpreted the same way, depending on what the operation is.
1614 You will find in this chapter everything about option styles and
1615 rules for writing them (*note Styles::). On the other hand, operations
1616 and options are fully described elsewhere, in other chapters. Here,
1617 you will find only synthetic descriptions for operations and options,
1618 together with pointers to other parts of the `tar' manual.
1620 Some options are so special they are fully described right in this
1621 chapter. They have the effect of inhibiting the normal operation of
1622 `tar' or else, they globally alter the amount of feedback the user
1623 receives about what is going on. These are the `--help' and
1624 `--version' (*note help::), `--verbose' (*note verbose::) and
1625 `--interactive' options (*note interactive::).
1630 * using tar options::
1641 File: tar.info, Node: Synopsis, Next: using tar options, Up: tar invocation
1643 3.1 General Synopsis of `tar'
1644 =============================
1646 The GNU `tar' program is invoked as either one of:
1648 tar OPTION... [NAME]...
1649 tar LETTER... [ARGUMENT]... [OPTION]... [NAME]...
1651 The second form is for when old options are being used.
1653 You can use `tar' to store files in an archive, to extract them from
1654 an archive, and to do other types of archive manipulation. The primary
1655 argument to `tar', which is called the "operation", specifies which
1656 action to take. The other arguments to `tar' are either "options",
1657 which change the way `tar' performs an operation, or file names or
1658 archive members, which specify the files or members `tar' is to act on.
1660 You can actually type in arguments in any order, even if in this
1661 manual the options always precede the other arguments, to make examples
1662 easier to understand. Further, the option stating the main operation
1663 mode (the `tar' main command) is usually given first.
1665 Each NAME in the synopsis above is interpreted as an archive member
1666 name when the main command is one of `--compare' (`--diff', `-d'),
1667 `--delete', `--extract' (`--get', `-x'), `--list' (`-t') or `--update'
1668 (`-u'). When naming archive members, you must give the exact name of
1669 the member in the archive, as it is printed by `--list'. For
1670 `--append' (`-r') and `--create' (`-c'), these NAME arguments specify
1671 the names of either files or directory hierarchies to place in the
1672 archive. These files or hierarchies should already exist in the file
1673 system, prior to the execution of the `tar' command.
1675 `tar' interprets relative file names as being relative to the
1676 working directory. `tar' will make all file names relative (by
1677 removing leading slashes when archiving or restoring files), unless you
1678 specify otherwise (using the `--absolute-names' option). *Note
1679 absolute::, for more information about `--absolute-names'.
1681 If you give the name of a directory as either a file name or a member
1682 name, then `tar' acts recursively on all the files and directories
1683 beneath that directory. For example, the name `/' identifies all the
1684 files in the file system to `tar'.
1686 The distinction between file names and archive member names is
1687 especially important when shell globbing is used, and sometimes a
1688 source of confusion for newcomers. *Note wildcards::, for more
1689 information about globbing. The problem is that shells may only glob
1690 using existing files in the file system. Only `tar' itself may glob on
1691 archive members, so when needed, you must ensure that wildcard
1692 characters reach `tar' without being interpreted by the shell first.
1693 Using a backslash before `*' or `?', or putting the whole argument
1694 between quotes, is usually sufficient for this.
1696 Even if NAMEs are often specified on the command line, they can also
1697 be read from a text file in the file system, using the
1698 `--files-from=FILE-OF-NAMES' (`-T FILE-OF-NAMES') option.
1700 If you don't use any file name arguments, `--append' (`-r'),
1701 `--delete' and `--concatenate' (`--catenate', `-A') will do nothing,
1702 while `--create' (`-c') will usually yield a diagnostic and inhibit
1703 `tar' execution. The other operations of `tar' (`--list', `--extract',
1704 `--compare', and `--update') will act on the entire contents of the
1707 Besides successful exits, GNU `tar' may fail for many reasons. Some
1708 reasons correspond to bad usage, that is, when the `tar' command line
1709 is improperly written. Errors may be encountered later, while
1710 processing the archive or the files. Some errors are recoverable, in
1711 which case the failure is delayed until `tar' has completed all its
1712 work. Some errors are such that it would be not meaningful, or at
1713 least risky, to continue processing: `tar' then aborts processing
1714 immediately. All abnormal exits, whether immediate or delayed, should
1715 always be clearly diagnosed on `stderr', after a line stating the
1716 nature of the error.
1718 Possible exit codes of GNU `tar' are summarized in the following
1722 `Successful termination'.
1725 `Some files differ'. If tar was invoked with `--compare'
1726 (`--diff', `-d') command line option, this means that some files
1727 in the archive differ from their disk counterparts (*note
1728 compare::). If tar was given `--create', `--append' or `--update'
1729 option, this exit code means that some files were changed while
1730 being archived and so the resulting archive does not contain the
1731 exact copy of the file set.
1734 `Fatal error'. This means that some fatal, unrecoverable error
1737 If `tar' has invoked a subprocess and that subprocess exited with a
1738 nonzero exit code, `tar' exits with that code as well. This can
1739 happen, for example, if `tar' was given some compression option (*note
1740 gzip::) and the external compressor program failed. Another example is
1741 `rmt' failure during backup to the remote device (*note Remote Tape
1745 File: tar.info, Node: using tar options, Next: Styles, Prev: Synopsis, Up: tar invocation
1747 3.2 Using `tar' Options
1748 =======================
1750 GNU `tar' has a total of eight operating modes which allow you to
1751 perform a variety of tasks. You are required to choose one operating
1752 mode each time you employ the `tar' program by specifying one, and only
1753 one operation as an argument to the `tar' command (the corresponding
1754 options may be found at *note frequent operations:: and *note
1755 Operations::). Depending on circumstances, you may also wish to
1756 customize how the chosen operating mode behaves. For example, you may
1757 wish to change the way the output looks, or the format of the files
1758 that you wish to archive may require you to do something special in
1759 order to make the archive look right.
1761 You can customize and control `tar''s performance by running `tar'
1762 with one or more options (such as `--verbose' (`-v'), which we used in
1763 the tutorial). As we said in the tutorial, "options" are arguments to
1764 `tar' which are (as their name suggests) optional. Depending on the
1765 operating mode, you may specify one or more options. Different options
1766 will have different effects, but in general they all change details of
1767 the operation, such as archive format, archive name, or level of user
1768 interaction. Some options make sense with all operating modes, while
1769 others are meaningful only with particular modes. You will likely use
1770 some options frequently, while you will only use others infrequently, or
1771 not at all. (A full list of options is available in *note All
1774 The `TAR_OPTIONS' environment variable specifies default options to
1775 be placed in front of any explicit options. For example, if
1776 `TAR_OPTIONS' is `-v --unlink-first', `tar' behaves as if the two
1777 options `-v' and `--unlink-first' had been specified before any
1778 explicit options. Option specifications are separated by whitespace.
1779 A backslash escapes the next character, so it can be used to specify an
1780 option containing whitespace or a backslash.
1782 Note that `tar' options are case sensitive. For example, the
1783 options `-T' and `-t' are different; the first requires an argument for
1784 stating the name of a file providing a list of NAMEs, while the second
1785 does not require an argument and is another way to write `--list'
1788 In addition to the eight operations, there are many options to
1789 `tar', and three different styles for writing both: long (mnemonic)
1790 form, short form, and old style. These styles are discussed below.
1791 Both the options and the operations can be written in any of these three
1795 File: tar.info, Node: Styles, Next: All Options, Prev: using tar options, Up: tar invocation
1797 3.3 The Three Option Styles
1798 ===========================
1800 There are three styles for writing operations and options to the command
1801 line invoking `tar'. The different styles were developed at different
1802 times during the history of `tar'. These styles will be presented
1803 below, from the most recent to the oldest.
1805 Some options must take an argument(1). Where you _place_ the
1806 arguments generally depends on which style of options you choose. We
1807 will detail specific information relevant to each option style in the
1808 sections on the different option styles, below. The differences are
1809 subtle, yet can often be very important; incorrect option placement can
1810 cause you to overwrite a number of important files. We urge you to
1811 note these differences, and only use the option style(s) which makes
1812 the most sense to you until you feel comfortable with the others.
1814 Some options _may_ take an argument. Such options may have at most
1815 long and short forms, they do not have old style equivalent. The rules
1816 for specifying an argument for such options are stricter than those for
1817 specifying mandatory arguments. Please, pay special attention to them.
1821 * Long Options:: Long Option Style
1822 * Short Options:: Short Option Style
1823 * Old Options:: Old Option Style
1824 * Mixing:: Mixing Option Styles
1826 ---------- Footnotes ----------
1828 (1) For example, `--file' (`-f') takes the name of an archive file
1829 as an argument. If you do not supply an archive file name, `tar' will
1830 use a default, but this can be confusing; thus, we recommend that you
1831 always supply a specific archive file name.
1834 File: tar.info, Node: Long Options, Next: Short Options, Up: Styles
1836 3.3.1 Long Option Style
1837 -----------------------
1839 Each option has at least one "long" (or "mnemonic") name starting with
1840 two dashes in a row, e.g., `--list'. The long names are more clear than
1841 their corresponding short or old names. It sometimes happens that a
1842 single long option has many different names which are synonymous, such
1843 as `--compare' and `--diff'. In addition, long option names can be
1844 given unique abbreviations. For example, `--cre' can be used in place
1845 of `--create' because there is no other long option which begins with
1846 `cre'. (One way to find this out is by trying it and seeing what
1847 happens; if a particular abbreviation could represent more than one
1848 option, `tar' will tell you that that abbreviation is ambiguous and
1849 you'll know that that abbreviation won't work. You may also choose to
1850 run `tar --help' to see a list of options. Be aware that if you run
1851 `tar' with a unique abbreviation for the long name of an option you
1852 didn't want to use, you are stuck; `tar' will perform the command as
1855 Long options are meant to be obvious and easy to remember, and their
1856 meanings are generally easier to discern than those of their
1857 corresponding short options (see below). For example:
1859 $ tar --create --verbose --blocking-factor=20 --file=/dev/rmt0
1861 gives a fairly good set of hints about what the command does, even for
1862 those not fully acquainted with `tar'.
1864 Long options which require arguments take those arguments
1865 immediately following the option name. There are two ways of
1866 specifying a mandatory argument. It can be separated from the option
1867 name either by an equal sign, or by any amount of white space
1868 characters. For example, the `--file' option (which tells the name of
1869 the `tar' archive) is given a file such as `archive.tar' as argument by
1870 using any of the following notations: `--file=archive.tar' or `--file
1873 In contrast, optional arguments must always be introduced using an
1874 equal sign. For example, the `--backup' option takes an optional
1875 argument specifying backup type. It must be used as
1876 `--backup=BACKUP-TYPE'.
1879 File: tar.info, Node: Short Options, Next: Old Options, Prev: Long Options, Up: Styles
1881 3.3.2 Short Option Style
1882 ------------------------
1884 Most options also have a "short option" name. Short options start with
1885 a single dash, and are followed by a single character, e.g., `-t'
1886 (which is equivalent to `--list'). The forms are absolutely identical
1887 in function; they are interchangeable.
1889 The short option names are faster to type than long option names.
1891 Short options which require arguments take their arguments
1892 immediately following the option, usually separated by white space. It
1893 is also possible to stick the argument right after the short option
1894 name, using no intervening space. For example, you might write
1895 `-f archive.tar' or `-farchive.tar' instead of using
1896 `--file=archive.tar'. Both `--file=ARCHIVE-NAME' and `-f ARCHIVE-NAME'
1897 denote the option which indicates a specific archive, here named
1900 Short options which take optional arguments take their arguments
1901 immediately following the option letter, _without any intervening white
1904 Short options' letters may be clumped together, but you are not
1905 required to do this (as compared to old options; see below). When
1906 short options are clumped as a set, use one (single) dash for them all,
1907 e.g., ``tar' -cvf'. Only the last option in such a set is allowed to
1908 have an argument(1).
1910 When the options are separated, the argument for each option which
1911 requires an argument directly follows that option, as is usual for Unix
1912 programs. For example:
1914 $ tar -c -v -b 20 -f /dev/rmt0
1916 If you reorder short options' locations, be sure to move any
1917 arguments that belong to them. If you do not move the arguments
1918 properly, you may end up overwriting files.
1920 ---------- Footnotes ----------
1922 (1) Clustering many options, the last of which has an argument, is a
1923 rather opaque way to write options. Some wonder if GNU `getopt' should
1924 not even be made helpful enough for considering such usages as invalid.
1927 File: tar.info, Node: Old Options, Next: Mixing, Prev: Short Options, Up: Styles
1929 3.3.3 Old Option Style
1930 ----------------------
1932 Like short options, "old options" are single letters. However, old
1933 options must be written together as a single clumped set, without
1934 spaces separating them or dashes preceding them(1). This set of
1935 letters must be the first to appear on the command line, after the
1936 `tar' program name and some white space; old options cannot appear
1937 anywhere else. The letter of an old option is exactly the same letter
1938 as the corresponding short option. For example, the old option `t' is
1939 the same as the short option `-t', and consequently, the same as the
1940 long option `--list'. So for example, the command `tar cv' specifies
1941 the option `-v' in addition to the operation `-c'.
1943 When options that need arguments are given together with the command,
1944 all the associated arguments follow, in the same order as the options.
1945 Thus, the example given previously could also be written in the old
1948 $ tar cvbf 20 /dev/rmt0
1950 Here, `20' is the argument of `-b' and `/dev/rmt0' is the argument of
1953 On the other hand, this old style syntax makes it difficult to match
1954 option letters with their corresponding arguments, and is often
1955 confusing. In the command `tar cvbf 20 /dev/rmt0', for example, `20'
1956 is the argument for `-b', `/dev/rmt0' is the argument for `-f', and
1957 `-v' does not have a corresponding argument. Even using short options
1958 like in `tar -c -v -b 20 -f /dev/rmt0' is clearer, putting all
1959 arguments next to the option they pertain to.
1961 If you want to reorder the letters in the old option argument, be
1962 sure to reorder any corresponding argument appropriately.
1964 This old way of writing `tar' options can surprise even experienced
1965 users. For example, the two commands:
1967 tar cfz archive.tar.gz file
1968 tar -cfz archive.tar.gz file
1970 are quite different. The first example uses `archive.tar.gz' as the
1971 value for option `f' and recognizes the option `z'. The second
1972 example, however, uses `z' as the value for option `f' -- probably not
1975 Old options are kept for compatibility with old versions of `tar'.
1977 This second example could be corrected in many ways, among which the
1978 following are equivalent:
1980 tar -czf archive.tar.gz file
1981 tar -cf archive.tar.gz -z file
1982 tar cf archive.tar.gz -z file
1984 As far as we know, all `tar' programs, GNU and non-GNU, support old
1985 options. GNU `tar' supports them not only for historical reasons, but
1986 also because many people are used to them. For compatibility with Unix
1987 `tar', the first argument is always treated as containing command and
1988 option letters even if it doesn't start with `-'. Thus, `tar c' is
1989 equivalent to `tar -c': both of them specify the `--create' (`-c')
1990 command to create an archive.
1992 ---------- Footnotes ----------
1994 (1) Beware that if you precede options with a dash, you are
1995 announcing the short option style instead of the old option style;
1996 short options are decoded differently.
1999 File: tar.info, Node: Mixing, Prev: Old Options, Up: Styles
2001 3.3.4 Mixing Option Styles
2002 --------------------------
2004 All three styles may be intermixed in a single `tar' command, so long
2005 as the rules for each style are fully respected(1). Old style options
2006 and either of the modern styles of options may be mixed within a single
2007 `tar' command. However, old style options must be introduced as the
2008 first arguments only, following the rule for old options (old options
2009 must appear directly after the `tar' command and some white space).
2010 Modern options may be given only after all arguments to the old options
2011 have been collected. If this rule is not respected, a modern option
2012 might be falsely interpreted as the value of the argument to one of the
2015 For example, all the following commands are wholly equivalent, and
2016 illustrate the many combinations and orderings of option styles.
2018 tar --create --file=archive.tar
2019 tar --create -f archive.tar
2020 tar --create -farchive.tar
2021 tar --file=archive.tar --create
2022 tar --file=archive.tar -c
2023 tar -c --file=archive.tar
2024 tar -c -f archive.tar
2025 tar -c -farchive.tar
2028 tar -f archive.tar --create
2029 tar -f archive.tar -c
2030 tar -farchive.tar --create
2031 tar -farchive.tar -c
2032 tar c --file=archive.tar
2033 tar c -f archive.tar
2036 tar f archive.tar --create
2037 tar f archive.tar -c
2040 On the other hand, the following commands are _not_ equivalent to
2043 tar -f -c archive.tar
2049 These last examples mean something completely different from what the
2050 user intended (judging based on the example in the previous set which
2051 uses long options, whose intent is therefore very clear). The first
2052 four specify that the `tar' archive would be a file named `-c', `c',
2053 `carchive.tar' or `archive.tarc', respectively. The first two examples
2054 also specify a single non-option, NAME argument having the value
2055 `archive.tar'. The last example contains only old style option letters
2056 (repeating option `c' twice), not all of which are meaningful (eg., `.',
2057 `h', or `i'), with no argument value.
2059 ---------- Footnotes ----------
2061 (1) Before GNU `tar' version 1.11.6, a bug prevented intermixing old
2062 style options with long options in some cases.
2065 File: tar.info, Node: All Options, Next: help, Prev: Styles, Up: tar invocation
2067 3.4 All `tar' Options
2068 =====================
2070 The coming manual sections contain an alphabetical listing of all `tar'
2071 operations and options, with brief descriptions and cross-references to
2072 more in-depth explanations in the body of the manual. They also
2073 contain an alphabetically arranged table of the short option forms with
2074 their corresponding long option. You can use this table as a reference
2075 for deciphering `tar' commands in scripts.
2079 * Operation Summary::
2081 * Short Option Summary::
2084 File: tar.info, Node: Operation Summary, Next: Option Summary, Up: All Options
2091 Appends files to the end of the archive. *Note append::.
2095 Same as `--concatenate'. *Note concatenate::.
2099 Compares archive members with their counterparts in the file
2100 system, and reports differences in file size, mode, owner,
2101 modification date and contents. *Note compare::.
2105 Appends other `tar' archives to the end of the archive. *Note
2110 Creates a new `tar' archive. *Note create::.
2113 Deletes members from the archive. Don't try this on an archive on
2114 a tape! *Note delete::.
2118 Same `--compare'. *Note compare::.
2122 Extracts members from the archive into the file system. *Note
2127 Same as `--extract'. *Note extract::.
2131 Lists the members in an archive. *Note list::.
2135 Adds files to the end of the archive, but only if they are newer
2136 than their counterparts already in the archive, or if they do not
2137 already exist in the archive. *Note update::.
2141 File: tar.info, Node: Option Summary, Next: Short Option Summary, Prev: Operation Summary, Up: All Options
2148 Normally when creating an archive, `tar' strips an initial `/'
2149 from member names. This option disables that behavior. *Note
2153 (See `--newer', *note after::)
2156 A pattern must match an initial subsequence of the name's
2157 components. *Note controlling pattern-matching::.
2160 `--atime-preserve=replace'
2161 `--atime-preserve=system'
2162 Attempt to preserve the access time of files when reading them.
2163 This option currently is effective only on files that you own,
2164 unless you have superuser privileges.
2166 `--atime-preserve=replace' remembers the access time of a file
2167 before reading it, and then restores the access time afterwards.
2168 This may cause problems if other programs are reading the file at
2169 the same time, as the times of their accesses will be lost. On
2170 most platforms restoring the access time also requires `tar' to
2171 restore the data modification time too, so this option may also
2172 cause problems if other programs are writing the file at the same
2173 time (`tar' attempts to detect this situation, but cannot do so
2174 reliably due to race conditions). Worse, on most platforms
2175 restoring the access time also updates the status change time,
2176 which means that this option is incompatible with incremental
2179 `--atime-preserve=system' avoids changing time stamps on files,
2180 without interfering with time stamp updates caused by other
2181 programs, so it works better with incremental backups. However,
2182 it requires a special `O_NOATIME' option from the underlying
2183 operating and file system implementation, and it also requires
2184 that searching directories does not update their access times. As
2185 of this writing (November 2005) this works only with Linux, and
2186 only with Linux kernels 2.6.8 and later. Worse, there is
2187 currently no reliable way to know whether this feature actually
2188 works. Sometimes `tar' knows that it does not work, and if you use
2189 `--atime-preserve=system' then `tar' complains and exits right
2190 away. But other times `tar' might think that the option works
2191 when it actually does not.
2193 Currently `--atime-preserve' with no operand defaults to
2194 `--atime-preserve=replace', but this may change in the future as
2195 support for `--atime-preserve=system' improves.
2197 If your operating or file system does not support
2198 `--atime-preserve=system', you might be able to preserve access
2199 times reliably by using the `mount' command. For example, you can
2200 mount the file system read-only, or access the file system via a
2201 read-only loopback mount, or use the `noatime' mount option
2202 available on some systems. However, mounting typically requires
2203 superuser privileges and can be a pain to manage.
2207 During a `--create' operation, enables automatic compressed format
2208 recognition based on the archive suffix. The effect of this
2209 option is cancelled by `--no-auto-compress'. *Note gzip::.
2211 `--backup=BACKUP-TYPE'
2212 Rather than deleting files from the file system, `tar' will back
2213 them up using simple or numbered backups, depending upon
2214 BACKUP-TYPE. *Note backup::.
2218 With this option present, `tar' prints error messages for read
2219 errors with the block number in the archive file. *Note
2222 `--blocking-factor=BLOCKING'
2224 Sets the blocking factor `tar' uses to BLOCKING x 512 bytes per
2225 record. *Note Blocking Factor::.
2229 This option tells `tar' to read or write archives through `bzip2'.
2233 Check device numbers when creating a list of modified files for
2234 incremental archiving. This is the default. *Note device
2235 numbers::, for a detailed description.
2237 `--checkpoint[=NUMBER]'
2238 This option directs `tar' to print periodic checkpoint messages as
2239 it reads through the archive. It is intended for when you want a
2240 visual indication that `tar' is still running, but don't want to
2241 see `--verbose' output. You can also instruct `tar' to execute a
2242 list of actions on each checkpoint, see `--checkpoint-action'
2243 below. For a detailed description, see *note checkpoints::.
2245 `--checkpoint-action=ACTION'
2246 Instruct `tar' to execute an action upon hitting a breakpoint.
2247 Here we give only a brief outline. *Note checkpoints::, for a
2248 complete description.
2250 The ACTION argument can be one of the following:
2253 Produce an audible bell on the console.
2257 Print a single dot on the standard listing stream.
2260 Display a textual message on the standard error, with the
2261 status and number of the checkpoint. This is the default.
2264 Display STRING on the standard error. Before output, the
2265 string is subject to meta-character expansion.
2268 Execute the given COMMAND.
2271 Wait for TIME seconds.
2274 Output STRING on the current console (`/dev/tty').
2276 Several `--checkpoint-action' options can be specified. The
2277 supplied actions will be executed in order of their appearance in
2280 Using `--checkpoint-action' without `--checkpoint' assumes default
2281 checkpoint frequency of one checkpoint per 10 records.
2285 If this option was given, `tar' will check the number of links
2286 dumped for each processed file. If this number does not match the
2287 total number of hard links for the file, a warning message will be
2295 `tar' will use the `compress' program when reading or writing the
2296 archive. This allows you to directly act on archives while saving
2297 space. *Note gzip::.
2300 (See `--interactive'.) *Note interactive::.
2302 `--delay-directory-restore'
2303 Delay setting modification times and permissions of extracted
2304 directories until the end of extraction. *Note Directory
2305 Modification Times and Permissions::.
2309 When reading or writing a file to be archived, `tar' accesses the
2310 file that a symbolic link points to, rather than the symlink
2311 itself. *Note dereference::.
2315 When this option is specified, `tar' will change its current
2316 directory to DIR before performing any operations. When this
2317 option is used during archive creation, it is order sensitive.
2321 When performing operations, `tar' will skip files that match
2322 PATTERN. *Note exclude::.
2325 Exclude backup and lock files. *Note exclude-backups: exclude.
2327 `--exclude-from=FILE'
2329 Similar to `--exclude', except `tar' will use the list of patterns
2330 in the file FILE. *Note exclude::.
2333 Exclude from dump any directory containing a valid cache directory
2334 tag file, but still dump the directory node and the tag file
2337 *Note exclude-caches: exclude.
2339 `--exclude-caches-under'
2340 Exclude from dump any directory containing a valid cache directory
2341 tag file, but still dump the directory node itself.
2345 `--exclude-caches-all'
2346 Exclude from dump any directory containing a valid cache directory
2347 tag file. *Note exclude::.
2349 `--exclude-tag=FILE'
2350 Exclude from dump any directory containing file named FILE, but
2351 dump the directory node and FILE itself. *Note exclude-tag:
2354 `--exclude-tag-under=FILE'
2355 Exclude from dump the contents of any directory containing file
2356 named FILE, but dump the directory node itself. *Note
2357 exclude-tag-under: exclude.
2359 `--exclude-tag-all=FILE'
2360 Exclude from dump any directory containing file named FILE. *Note
2361 exclude-tag-all: exclude.
2364 Exclude from dump directories and files, that are internal for some
2365 widely used version control systems.
2367 *Note exclude-vcs: exclude.
2371 `tar' will use the file ARCHIVE as the `tar' archive it performs
2372 operations on, rather than `tar''s compilation dependent default.
2373 *Note file tutorial::.
2377 `tar' will use the contents of FILE as a list of archive members
2378 or files to operate on, in addition to those specified on the
2379 command-line. *Note files::.
2382 Forces `tar' to interpret the file name given to `--file' as a
2383 local file, even if it looks like a remote tape drive name. *Note
2384 local and remote archives::.
2388 Selects output archive format. FORMAT may be one of the following:
2391 Creates an archive that is compatible with Unix V7 `tar'.
2394 Creates an archive that is compatible with GNU `tar' version
2398 Creates archive in GNU tar 1.13 format. Basically it is the
2399 same as `oldgnu' with the only difference in the way it
2400 handles long numeric fields.
2403 Creates a POSIX.1-1988 compatible archive.
2406 Creates a POSIX.1-2001 archive.
2409 *Note Formats::, for a detailed discussion of these formats.
2412 This option instructs `tar' to print file times to their full
2413 resolution. Usually this means 1-second resolution, but that
2414 depends on the underlying file system. The `--full-time' option
2415 takes effect only when detailed output (verbosity level 2 or
2416 higher) has been requested using the `--verbose' option, e.g.,
2417 when listing or extracting archives:
2419 $ tar -t -v --full-time -f archive.tar
2421 or, when creating an archive:
2423 $ tar -c -vv --full-time -f archive.tar .
2425 Notice, thar when creating the archive you need to specify
2426 `--verbose' twice to get a detailed output (*note verbose
2430 Files added to the `tar' archive will have a group ID of GROUP,
2431 rather than the group from the source file. GROUP is first decoded
2432 as a group symbolic name, but if this interpretation fails, it has
2433 to be a decimal numeric group ID. *Note override::.
2435 Also see the comments for the `--owner=USER' option.
2441 This option tells `tar' to read or write archives through `gzip',
2442 allowing `tar' to directly operate on several kinds of compressed
2443 archives transparently. *Note gzip::.
2445 `--hard-dereference'
2446 When creating an archive, dereference hard links and store the
2447 files they refer to, instead of creating usual hard link members.
2453 `tar' will print out a short message summarizing the operations and
2454 options to `tar' and exit. *Note help::.
2457 Ignore case when matching member or file names with patterns.
2458 *Note controlling pattern-matching::.
2460 `--ignore-command-error'
2461 Ignore exit codes of subprocesses. *Note Writing to an External
2464 `--ignore-failed-read'
2465 Do not exit unsuccessfully merely because an unreadable file was
2466 encountered. *Note Reading::.
2470 With this option, `tar' will ignore zeroed blocks in the archive,
2471 which normally signals EOF. *Note Reading::.
2475 Informs `tar' that it is working with an old GNU-format
2476 incremental backup archive. It is intended primarily for
2477 backwards compatibility only. *Note Incremental Dumps::, for a
2478 detailed discussion of incremental archives.
2481 Send verbose output to FILE instead of to standard output.
2483 `--info-script=SCRIPT-FILE'
2484 `--new-volume-script=SCRIPT-FILE'
2486 When `tar' is performing multi-tape backups, SCRIPT-FILE is run at
2487 the end of each tape. If SCRIPT-FILE exits with nonzero status,
2488 `tar' fails immediately. *Note info-script::, for a detailed
2489 discussion of SCRIPT-FILE.
2494 Specifies that `tar' should ask the user for confirmation before
2495 performing potentially destructive options, such as overwriting
2496 files. *Note interactive::.
2498 `--keep-newer-files'
2499 Do not replace existing files that are newer than their archive
2500 copies when extracting files from an archive.
2504 Do not overwrite existing files when extracting files from an
2505 archive. *Note Keep Old Files::.
2509 When creating an archive, instructs `tar' to write NAME as a name
2510 record in the archive. When extracting or listing archives, `tar'
2511 will only operate on archives that have a label matching the
2512 pattern specified in NAME. *Note Tape Files::.
2515 Force incremental backup of level N. As of GNU `tar' version
2516 1.26, the option `--level=0' truncates the snapshot file, thereby
2517 forcing the level 0 dump. Other values of N are effectively
2518 ignored. *Note --level=0::, for details and examples.
2520 The use of this option is valid only in conjunction with the
2521 `--listed-incremental' option. *Note Incremental Dumps::, for a
2522 detailed description.
2524 `--listed-incremental=SNAPSHOT-FILE'
2526 During a `--create' operation, specifies that the archive that
2527 `tar' creates is a new GNU-format incremental backup, using
2528 SNAPSHOT-FILE to determine which files to backup. With other
2529 operations, informs `tar' that the archive is in incremental
2530 format. *Note Incremental Dumps::.
2533 This option tells `tar' to read or write archives through `lzip'.
2537 This option tells `tar' to read or write archives through `lzma'.
2541 This option tells `tar' to read or write archives through `lzop'.
2544 `--mode=PERMISSIONS'
2545 When adding files to an archive, `tar' will use PERMISSIONS for
2546 the archive members, rather than the permissions from the files.
2547 PERMISSIONS can be specified either as an octal number or as
2548 symbolic permissions, like with `chmod'. *Note override::.
2551 When adding files to an archive, `tar' will use DATE as the
2552 modification time of members when creating archives, instead of
2553 their actual modification times. The value of DATE can be either
2554 a textual date representation (*note Date input formats::) or a
2555 name of the existing file, starting with `/' or `.'. In the
2556 latter case, the modification time of that file is used. *Note
2561 Informs `tar' that it should create or otherwise operate on a
2562 multi-volume `tar' archive. *Note Using Multiple Tapes::.
2564 `--new-volume-script'
2565 (see `--info-script')
2570 When creating an archive, `tar' will only add files that have
2571 changed since DATE. If DATE begins with `/' or `.', it is taken
2572 to be the name of a file whose data modification time specifies
2573 the date. *Note after::.
2575 `--newer-mtime=DATE'
2576 Like `--newer', but add only files whose contents have changed (as
2577 opposed to just `--newer', which will also back up files for which
2578 any status information has changed). *Note after::.
2581 An exclude pattern can match any subsequence of the name's
2582 components. *Note controlling pattern-matching::.
2584 `--no-auto-compress'
2585 Disables automatic compressed format recognition based on the
2586 archive suffix. *Note --auto-compress::. *Note gzip::.
2589 Do not check device numbers when creating a list of modified files
2590 for incremental archiving. *Note device numbers::, for a detailed
2593 `--no-delay-directory-restore'
2594 Modification times and permissions of extracted directories are
2595 set when all files from this directory have been extracted. This
2596 is the default. *Note Directory Modification Times and
2600 Use case-sensitive matching. *Note controlling pattern-matching::.
2602 `--no-ignore-command-error'
2603 Print warnings about subprocesses that terminated with a nonzero
2604 exit code. *Note Writing to an External Program::.
2607 If the `--null' option was given previously, this option cancels
2608 its effect, so that any following `--files-from' options will
2609 expect their file lists to be newline-terminated.
2611 `--no-overwrite-dir'
2612 Preserve metadata of existing directories when extracting files
2613 from an archive. *Note Overwrite Old Files::.
2615 `--no-quote-chars=STRING'
2616 Remove characters listed in STRING from the list of quoted
2617 characters set by the previous `--quote-chars' option (*note
2621 With this option, `tar' will not recurse into directories. *Note
2626 When extracting an archive, do not attempt to preserve the owner
2627 specified in the `tar' archive. This the default behavior for
2630 `--no-same-permissions'
2631 When extracting an archive, subtract the user's umask from files
2632 from the permissions specified in the archive. This is the
2633 default behavior for ordinary users.
2636 The archive media does not support seeks to arbitrary locations.
2637 Usually `tar' determines automatically whether the archive can be
2638 seeked or not. Use this option to disable this mechanism.
2641 Treat all input file or member names literally, do not interpret
2642 escape sequences. *Note input name quoting::.
2645 Do not use wildcards. *Note controlling pattern-matching::.
2647 `--no-wildcards-match-slash'
2648 Wildcards do not match `/'. *Note controlling pattern-matching::.
2651 When `tar' is using the `--files-from' option, this option
2652 instructs `tar' to expect file names terminated with NUL, so `tar'
2653 can correctly work with file names that contain newlines. *Note
2657 This option will notify `tar' that it should use numeric user and
2658 group IDs when creating a `tar' file, rather than names. *Note
2662 The function of this option depends on the action `tar' is
2663 performing. When extracting files, `-o' is a synonym for
2664 `--no-same-owner', i.e., it prevents `tar' from restoring
2665 ownership of files being extracted.
2667 When creating an archive, it is a synonym for `--old-archive'.
2668 This behavior is for compatibility with previous versions of GNU
2669 `tar', and will be removed in future releases.
2671 *Note Changes::, for more information.
2673 `--occurrence[=NUMBER]'
2674 This option can be used in conjunction with one of the subcommands
2675 `--delete', `--diff', `--extract' or `--list' when a list of files
2676 is given either on the command line or via `-T' option.
2678 This option instructs `tar' to process only the NUMBERth
2679 occurrence of each named file. NUMBER defaults to 1, so
2681 tar -x -f archive.tar --occurrence filename
2683 will extract the first occurrence of the member `filename' from
2684 `archive.tar' and will terminate without scanning to the end of
2688 Synonym for `--format=v7'.
2691 Used when creating an archive. Prevents `tar' from recursing into
2692 directories that are on different file systems from the current
2696 Overwrite existing files and directory metadata when extracting
2697 files from an archive. *Note Overwrite Old Files::.
2700 Overwrite the metadata of existing directories when extracting
2701 files from an archive. *Note Overwrite Old Files::.
2704 Specifies that `tar' should use USER as the owner of members when
2705 creating archives, instead of the user associated with the source
2706 file. USER is first decoded as a user symbolic name, but if this
2707 interpretation fails, it has to be a decimal numeric user ID.
2710 This option does not affect extraction from archives.
2712 `--pax-option=KEYWORD-LIST'
2713 This option enables creation of the archive in POSIX.1-2001 format
2714 (*note posix::) and modifies the way `tar' handles the extended
2715 header keywords. KEYWORD-LIST is a comma-separated list of
2716 keyword options. *Note PAX keywords::, for a detailed discussion.
2720 Synonym for `--format=v7'.
2723 Same as `--format=posix'.
2726 Synonymous with specifying both `--preserve-permissions' and
2727 `--same-order'. *Note Setting Access Permissions::.
2730 (See `--same-order'; *note Reading::.)
2732 `--preserve-permissions'
2733 `--same-permissions'
2735 When `tar' is extracting an archive, it normally subtracts the
2736 users' umask from the permissions specified in the archive and uses
2737 that number as the permissions to create the destination file.
2738 Specifying this option instructs `tar' that it should use the
2739 permissions directly from the archive. *Note Setting Access
2742 `--quote-chars=STRING'
2743 Always quote characters from STRING, even if the selected quoting
2744 style would not quote them (*note quoting styles::).
2746 `--quoting-style=STYLE'
2747 Set quoting style to use when printing member and file names
2748 (*note quoting styles::). Valid STYLE values are: `literal',
2749 `shell', `shell-always', `c', `escape', `locale', and `clocale'.
2750 Default quoting style is `escape', unless overridden while
2751 configuring the package.
2753 `--read-full-records'
2755 Specifies that `tar' should reblock its input, for reading from
2756 pipes on systems with buggy implementations. *Note Reading::.
2758 `--record-size=SIZE[SUF]'
2759 Instructs `tar' to use SIZE bytes per record when accessing the
2760 archive. The argument can be suffixed with a "size suffix", e.g.
2761 `--record-size=10K' for 10 Kilobytes. *Note size-suffixes::, for
2762 a list of valid suffixes. *Note Blocking Factor::, for a detailed
2763 description of this option.
2766 With this option, `tar' recurses into directories (default).
2769 `--recursive-unlink'
2770 Remove existing directory hierarchies before extracting
2771 directories of the same name from the archive. *Note Recursive
2775 Directs `tar' to remove the source file from the file system after
2776 appending it to an archive. *Note remove files::.
2779 Disable use of some potentially harmful `tar' options. Currently
2780 this option disables shell invocation from multi-volume menu
2781 (*note Using Multiple Tapes::).
2784 Notifies `tar' that it should use CMD instead of the default
2785 `/usr/libexec/rmt' (*note Remote Tape Server::).
2788 Notifies `tar' that is should use CMD to communicate with remote
2789 devices. *Note Device::.
2794 This option is an optimization for `tar' when running on machines
2795 with small amounts of memory. It informs `tar' that the list of
2796 file arguments has already been sorted to match the order of files
2797 in the archive. *Note Reading::.
2800 When extracting an archive, `tar' will attempt to preserve the
2801 owner specified in the `tar' archive with this option present.
2802 This is the default behavior for the superuser; this option has an
2803 effect only for ordinary users. *Note Attributes::.
2805 `--same-permissions'
2806 (See `--preserve-permissions'; *note Setting Access Permissions::.)
2810 Assume that the archive media supports seeks to arbitrary
2811 locations. Usually `tar' determines automatically whether the
2812 archive can be seeked or not. This option is intended for use in
2813 cases when such recognition fails. It takes effect only if the
2814 archive is open for reading (e.g. with `--list' or `--extract'
2818 Displays the default options used by `tar' and exits successfully.
2819 This option is intended for use in shell scripts. Here is an
2820 example of what you can see using this option:
2822 $ tar --show-defaults
2823 --format=gnu -f- -b20 --quoting-style=escape
2824 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
2826 Notice, that this option outputs only one line. The example output
2827 above has been split to fit page boundaries.
2829 `--show-omitted-dirs'
2830 Instructs `tar' to mention the directories it is skipping when
2831 operating on a `tar' archive. *Note show-omitted-dirs::.
2833 `--show-transformed-names'
2834 `--show-stored-names'
2835 Display file or member names after applying any transformations
2836 (*note transform::). In particular, when used in conjunction with
2837 one of the archive creation operations it instructs `tar' to list
2838 the member names stored in the archive, as opposed to the actual
2839 file names. *Note listing member and file names::.
2843 Invokes a GNU extension when adding files to an archive that
2844 handles sparse files efficiently. *Note sparse::.
2846 `--sparse-version=VERSION'
2847 Specifies the "format version" to use when archiving sparse files.
2848 Implies `--sparse'. *Note sparse::. For the description of the
2849 supported sparse formats, *Note Sparse Formats::.
2851 `--starting-file=NAME'
2853 This option affects extraction only; `tar' will skip extracting
2854 files in the archive until it finds one that matches NAME. *Note
2857 `--strip-components=NUMBER'
2858 Strip given NUMBER of leading components from file names before
2859 extraction. For example, if archive `archive.tar' contained
2860 `/some/file/name', then running
2862 tar --extract --file archive.tar --strip-components=2
2864 would extract this file to file `name'.
2867 Alters the suffix `tar' uses when backing up files from the default
2868 `~'. *Note backup::.
2870 `--tape-length=NUM[SUF]'
2872 Specifies the length of tapes that `tar' is writing as being
2873 NUM x 1024 bytes long. If optional SUF is given, it specifies a
2874 multiplicative factor to be used instead of 1024. For example,
2875 `-L2M' means 2 megabytes. *Note size-suffixes::, for a list of
2876 allowed suffixes. *Note Using Multiple Tapes::, for a detailed
2877 discussion of this option.
2880 Reads the volume label. If an argument is specified, test whether
2881 it matches the volume label. *Note --test-label option::.
2883 `--to-command=COMMAND'
2884 During extraction `tar' will pipe extracted files to the standard
2885 input of COMMAND. *Note Writing to an External Program::.
2889 During extraction, `tar' will extract files to stdout rather than
2890 to the file system. *Note Writing to Standard Output::.
2893 Displays the total number of bytes transferred when processing an
2894 archive. If an argument is given, these data are displayed on
2895 request, when signal SIGNO is delivered to `tar'. *Note totals::.
2899 Sets the data modification time of extracted files to the
2900 extraction time, rather than the data modification time stored in
2901 the archive. *Note Data Modification Times::.
2903 `--transform=SED-EXPR'
2905 Transform file or member names using `sed' replacement expression
2906 SED-EXPR. For example,
2908 $ tar cf archive.tar --transform 's,^\./,usr/,' .
2910 will add to `archive' files from the current working directory,
2911 replacing initial `./' prefix with `usr/'. For the detailed
2912 discussion, *Note transform::.
2914 To see transformed member names in verbose listings, use
2915 `--show-transformed-names' option (*note show-transformed-names::).
2918 (See `--compress', *note gzip::)
2921 (See `--gzip', *note gzip::)
2925 Directs `tar' to remove the corresponding file from the file
2926 system before extracting it from the archive. *Note Unlink
2930 Enable unquoting input file or member names (default). *Note
2931 input name quoting::.
2933 `--use-compress-program=PROG'
2935 Instructs `tar' to access the archive through PROG, which is
2936 presumed to be a compression program of some sort. *Note gzip::.
2939 Display file modification dates in UTC. This option implies
2944 Specifies that `tar' should be more verbose about the operations
2945 it is performing. This option can be specified multiple times for
2946 some operations to increase the amount of information displayed.
2951 Verifies that the archive was correctly written when creating an
2952 archive. *Note verify::.
2955 Print information about the program's name, version, origin and
2956 legal status, all on standard output, and then exit successfully.
2960 Used in conjunction with `--multi-volume'. `tar' will keep track
2961 of which volume of a multi-volume archive it is working in FILE.
2965 Enable or disable warning messages identified by KEYWORD. The
2966 messages are suppressed if KEYWORD is prefixed with `no-'. *Note
2970 Use wildcards when matching member names with patterns. *Note
2971 controlling pattern-matching::.
2973 `--wildcards-match-slash'
2974 Wildcards match `/'. *Note controlling pattern-matching::.
2978 Use `xz' for compressing or decompressing the archives. *Note
2982 ---------- Footnotes ----------
2984 (1) Earlier versions of GNU `tar' understood `-l' as a synonym for
2985 `--one-file-system'. The current semantics, which complies to UNIX98,
2986 was introduced with version 1.15.91. *Note Changes::, for more
2990 File: tar.info, Node: Short Option Summary, Prev: Option Summary, Up: All Options
2992 3.4.3 Short Options Cross Reference
2993 -----------------------------------
2995 Here is an alphabetized list of all of the short option forms, matching
2996 them with the equivalent long option.
2998 Short Option Reference
2999 --------------------------------------------------------------------------
3000 -A *note --concatenate::.
3001 -B *note --read-full-records::.
3002 -C *note --directory::.
3003 -F *note --info-script::.
3004 -G *note --incremental::.
3006 -K *note --starting-file::.
3007 -L *note --tape-length::.
3008 -M *note --multi-volume::.
3010 -O *note --to-stdout::.
3011 -P *note --absolute-names::.
3012 -R *note --block-number::.
3013 -S *note --sparse::.
3014 -T *note --files-from::.
3015 -U *note --unlink-first::.
3017 -W *note --verify::.
3018 -X *note --exclude-from::.
3019 -Z *note --compress::.
3020 -b *note --blocking-factor::.
3021 -c *note --create::.
3022 -d *note --compare::.
3024 -g *note --listed-incremental::.
3025 -h *note --dereference::.
3026 -i *note --ignore-zeros::.
3028 -k *note --keep-old-files::.
3029 -l *note --check-links::.
3031 -o When creating, *note --no-same-owner::, when extracting --
3032 *note --portability::.
3034 The latter usage is deprecated. It is retained for
3035 compatibility with the earlier versions of GNU `tar'. In
3036 future releases `-o' will be equivalent to
3037 `--no-same-owner' only.
3038 -p *note --preserve-permissions::.
3039 -r *note --append::.
3040 -s *note --same-order::.
3042 -u *note --update::.
3043 -v *note --verbose::.
3044 -w *note --interactive::.
3045 -x *note --extract::.
3049 File: tar.info, Node: help, Next: defaults, Prev: All Options, Up: tar invocation
3051 3.5 GNU `tar' documentation
3052 ===========================
3054 Being careful, the first thing is really checking that you are using
3055 GNU `tar', indeed. The `--version' option causes `tar' to print
3056 information about its name, version, origin and legal status, all on
3057 standard output, and then exit successfully. For example,
3058 `tar --version' might print:
3061 Copyright (C) 2010 Free Software Foundation, Inc.
3062 Copyright (C) 2010 Free Software Foundation, Inc.
3063 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3064 This is free software: you are free to change and redistribute it.
3065 There is NO WARRANTY, to the extent permitted by law.
3067 Written by John Gilmore and Jay Fenlason.
3069 The first occurrence of `tar' in the result above is the program name
3070 in the package (for example, `rmt' is another program), while the
3071 second occurrence of `tar' is the name of the package itself,
3072 containing possibly many programs. The package is currently named
3073 `tar', after the name of the main program it contains(1).
3075 Another thing you might want to do is checking the spelling or
3076 meaning of some particular `tar' option, without resorting to this
3077 manual, for once you have carefully read it. GNU `tar' has a short
3078 help feature, triggerable through the `--help' option. By using this
3079 option, `tar' will print a usage message listing all available options
3080 on standard output, then exit successfully, without doing anything else
3081 and ignoring all other options. Even if this is only a brief summary,
3082 it may be several screens long. So, if you are not using some kind of
3083 scrollable window, you might prefer to use something like:
3087 presuming, here, that you like using `less' for a pager. Other popular
3088 pagers are `more' and `pg'. If you know about some KEYWORD which
3089 interests you and do not want to read all the `--help' output, another
3090 common idiom is doing:
3092 tar --help | grep KEYWORD
3094 for getting only the pertinent lines. Notice, however, that some `tar'
3095 options have long description lines and the above command will list
3096 only the first of them.
3098 The exact look of the option summary displayed by `tar --help' is
3099 configurable. *Note Configuring Help Summary::, for a detailed
3102 If you only wish to check the spelling of an option, running `tar
3103 --usage' may be a better choice. This will display a terse list of
3104 `tar' options without accompanying explanations.
3106 The short help output is quite succinct, and you might have to get
3107 back to the full documentation for precise points. If you are reading
3108 this paragraph, you already have the `tar' manual in some form. This
3109 manual is available in a variety of forms from
3110 `http://www.gnu.org/software/tar/manual'. It may be printed out of the
3111 GNU `tar' distribution, provided you have TeX already installed
3112 somewhere, and a laser printer around. Just configure the
3113 distribution, execute the command `make dvi', then print `doc/tar.dvi'
3114 the usual way (contact your local guru to know how). If GNU `tar' has
3115 been conveniently installed at your place, this manual is also
3116 available in interactive, hypertextual form as an Info file. Just call
3117 `info tar' or, if you do not have the `info' program handy, use the
3118 Info reader provided within GNU Emacs, calling `tar' from the main Info
3121 There is currently no `man' page for GNU `tar'. If you observe such
3122 a `man' page on the system you are running, either it does not belong
3123 to GNU `tar', or it has not been produced by GNU. Some package
3124 maintainers convert `tar --help' output to a man page, using
3125 `help2man'. In any case, please bear in mind that the authoritative
3126 source of information about GNU `tar' is this Texinfo documentation.
3128 ---------- Footnotes ----------
3130 (1) There are plans to merge the `cpio' and `tar' packages into a
3131 single one which would be called `paxutils'. So, who knows if, one of
3132 this days, the `--version' would not output `tar (GNU paxutils) 3.2'.
3135 File: tar.info, Node: defaults, Next: verbose, Prev: help, Up: tar invocation
3137 3.6 Obtaining GNU `tar' default values
3138 ======================================
3140 GNU `tar' has some predefined defaults that are used when you do not
3141 explicitly specify another values. To obtain a list of such defaults,
3142 use `--show-defaults' option. This will output the values in the form
3143 of `tar' command line options:
3145 $ tar --show-defaults
3146 --format=gnu -f- -b20 --quoting-style=escape
3147 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3149 Notice, that this option outputs only one line. The example output
3150 above has been split to fit page boundaries.
3152 The above output shows that this version of GNU `tar' defaults to using
3153 `gnu' archive format (*note Formats::), it uses standard output as the
3154 archive, if no `--file' option has been given (*note file tutorial::),
3155 the default blocking factor is 20 (*note Blocking Factor::). It also
3156 shows the default locations where `tar' will look for `rmt' and `rsh'
3160 File: tar.info, Node: verbose, Next: checkpoints, Prev: defaults, Up: tar invocation
3162 3.7 Checking `tar' progress
3163 ===========================
3165 Typically, `tar' performs most operations without reporting any
3166 information to the user except error messages. When using `tar' with
3167 many options, particularly ones with complicated or
3168 difficult-to-predict behavior, it is possible to make serious mistakes.
3169 `tar' provides several options that make observing `tar' easier. These
3170 options cause `tar' to print information as it progresses in its job,
3171 and you might want to use them just for being more careful about what
3172 is going on, or merely for entertaining yourself. If you have
3173 encountered a problem when operating on an archive, however, you may
3174 need more information than just an error message in order to solve the
3175 problem. The following options can be helpful diagnostic tools.
3177 Normally, the `--list' (`-t') command to list an archive prints just
3178 the file names (one per line) and the other commands are silent. When
3179 used with most operations, the `--verbose' (`-v') option causes `tar'
3180 to print the name of each file or archive member as it is processed.
3181 This and the other options which make `tar' print status information
3182 can be useful in monitoring `tar'.
3184 With `--create' or `--extract', `--verbose' used once just prints
3185 the names of the files or members as they are processed. Using it
3186 twice causes `tar' to print a longer listing (*Note verbose member
3187 listing::, for the description) for each member. Since `--list'
3188 already prints the names of the members, `--verbose' used once with
3189 `--list' causes `tar' to print an `ls -l' type listing of the files in
3190 the archive. The following examples both extract members with long
3193 $ tar --extract --file=archive.tar --verbose --verbose
3194 $ tar xvvf archive.tar
3196 Verbose output appears on the standard output except when an archive
3197 is being written to the standard output, as with `tar --create --file=-
3198 --verbose' (`tar cfv -', or even `tar cv'--if the installer let
3199 standard output be the default archive). In that case `tar' writes
3200 verbose output to the standard error stream.
3202 If `--index-file=FILE' is specified, `tar' sends verbose output to
3203 FILE rather than to standard output or standard error.
3205 The `--totals' option causes `tar' to print on the standard error
3206 the total amount of bytes transferred when processing an archive. When
3207 creating or appending to an archive, this option prints the number of
3208 bytes written to the archive and the average speed at which they have
3211 $ tar -c -f archive.tar --totals /home
3212 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3214 When reading an archive, this option displays the number of bytes
3217 $ tar -x -f archive.tar --totals
3218 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3220 Finally, when deleting from an archive, the `--totals' option
3221 displays both numbers plus number of bytes removed from the archive:
3223 $ tar --delete -f foo.tar --totals --wildcards '*~'
3224 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3225 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3226 Total bytes deleted: 1474048
3228 You can also obtain this information on request. When `--totals' is
3229 used with an argument, this argument is interpreted as a symbolic name
3230 of a signal, upon delivery of which the statistics is to be printed:
3233 Print statistics upon delivery of signal SIGNO. Valid arguments
3234 are: `SIGHUP', `SIGQUIT', `SIGINT', `SIGUSR1' and `SIGUSR2'.
3235 Shortened names without `SIG' prefix are also accepted.
3237 Both forms of `--totals' option can be used simultaneously. Thus,
3238 `tar -x --totals --totals=USR1' instructs `tar' to extract all members
3239 from its default archive and print statistics after finishing the
3240 extraction, as well as when receiving signal `SIGUSR1'.
3242 The `--checkpoint' option prints an occasional message as `tar'
3243 reads or writes the archive. It is designed for those who don't need
3244 the more detailed (and voluminous) output of `--block-number' (`-R'),
3245 but do want visual confirmation that `tar' is actually making forward
3246 progress. By default it prints a message each 10 records read or
3247 written. This can be changed by giving it a numeric argument after an
3250 $ tar -c --checkpoint=1000 /var
3251 tar: Write checkpoint 1000
3252 tar: Write checkpoint 2000
3253 tar: Write checkpoint 3000
3255 This example shows the default checkpoint message used by `tar'. If
3256 you place a dot immediately after the equal sign, it will print a `.'
3257 at each checkpoint(1). For example:
3259 $ tar -c --checkpoint=.1000 /var
3262 The `--checkpoint' option provides a flexible mechanism for
3263 executing arbitrary actions upon hitting checkpoints, see the next
3264 section (*note checkpoints::), for more information on it.
3266 The `--show-omitted-dirs' option, when reading an archive--with
3267 `--list' or `--extract', for example--causes a message to be printed
3268 for each directory in the archive which is skipped. This happens
3269 regardless of the reason for skipping: the directory might not have
3270 been named on the command line (implicitly or explicitly), it might be
3271 excluded by the use of the `--exclude=PATTERN' option, or some other
3274 If `--block-number' (`-R') is used, `tar' prints, along with every
3275 message it would normally produce, the block number within the archive
3276 where the message was triggered. Also, supplementary messages are
3277 triggered when reading blocks full of NULs, or when hitting end of file
3278 on the archive. As of now, if the archive is properly terminated with
3279 a NUL block, the reading of the file may stop before end of file is
3280 met, so the position of end of file will not usually show when
3281 `--block-number' (`-R') is used. Note that GNU `tar' drains the
3282 archive before exiting when reading the archive from a pipe.
3284 This option is especially useful when reading damaged archives, since
3285 it helps pinpoint the damaged sections. It can also be used with
3286 `--list' (`-t') when listing a file-system backup tape, allowing you to
3287 choose among several backup tapes when retrieving a file later, in
3288 favor of the tape where the file appears earliest (closest to the front
3289 of the tape). *Note backup::.
3291 ---------- Footnotes ----------
3293 (1) This is actually a shortcut for `--checkpoint=N
3294 --checkpoint-action=dot'. *Note dot: checkpoints.
3297 File: tar.info, Node: checkpoints, Next: warnings, Prev: verbose, Up: tar invocation
3302 A "checkpoint" is a moment of time before writing Nth record to the
3303 archive (a "write checkpoint"), or before reading Nth record from the
3304 archive (a "read checkpoint"). Checkpoints allow to periodically
3305 execute arbitrary actions.
3307 The checkpoint facility is enabled using the following option:
3310 Schedule checkpoints before writing or reading each Nth record.
3311 The default value for N is 10.
3313 A list of arbitrary "actions" can be executed at each checkpoint.
3314 These actions include: pausing, displaying textual messages, and
3315 executing arbitrary external programs. Actions are defined using the
3316 `--checkpoint-action' option.
3318 `--checkpoint-action=ACTION'
3319 Execute an ACTION at each checkpoint.
3321 The simplest value of ACTION is `echo'. It instructs `tar' to
3322 display the default message on the standard error stream upon arriving
3323 at each checkpoint. The default message is (in POSIX locale) `Write
3324 checkpoint N', for write checkpoints, and `Read checkpoint N', for read
3325 checkpoints. Here, N represents ordinal number of the checkpoint.
3327 In another locales, translated versions of this message are used.
3329 This is the default action, so running:
3331 $ tar -c --checkpoint=1000 --checkpoint-action=echo /var
3335 $ tar -c --checkpoint=1000 /var
3337 The `echo' action also allows to supply a customized message. You
3338 do so by placing an equals sign and the message right after it, e.g.:
3340 --checkpoint-action="echo=Hit %s checkpoint #%u"
3342 The `%s' and `%u' in the above example are "meta-characters". The
3343 `%s' meta-character is replaced with the "type" of the checkpoint:
3344 `write' or `read' (or a corresponding translated version in locales
3345 other than POSIX). The `%u' meta-character is replaced with the
3346 ordinal number of the checkpoint. Thus, the above example could
3347 produce the following output when used with the `--create' option:
3349 tar: Hit write checkpoint #10
3350 tar: Hit write checkpoint #20
3351 tar: Hit write checkpoint #30
3353 Aside from meta-character expansion, the message string is subject to
3354 "unquoting", during which the backslash "escape sequences" are replaced
3355 with their corresponding ASCII characters (*note escape sequences::).
3356 E.g. the following action will produce an audible bell and the message
3357 described above at each checkpoint:
3359 --checkpoint-action='echo=\aHit %s checkpoint #%u'
3361 There is also a special action which produces an audible signal:
3362 `bell'. It is not equivalent to `echo='\a'', because `bell' sends the
3363 bell directly to the console (`/dev/tty'), whereas `echo='\a'' sends it
3364 to the standard error.
3366 The `ttyout=STRING' action outputs STRING to `/dev/tty', so it can
3367 be used even if the standard output is redirected elsewhere. The
3368 STRING is subject to the same modifications as with `echo' action. In
3369 contrast to the latter, `ttyout' does not prepend `tar' executable name
3370 to the string, nor does it output a newline after it. For example, the
3371 following action will print the checkpoint message at the same screen
3372 line, overwriting any previous message:
3374 --checkpoint-action="ttyout=\rHit %s checkpoint #%u"
3376 Another available checkpoint action is `dot' (or `.'). It instructs
3377 `tar' to print a single dot on the standard listing stream, e.g.:
3379 $ tar -c --checkpoint=1000 --checkpoint-action=dot /var
3382 For compatibility with previous GNU `tar' versions, this action can
3383 be abbreviated by placing a dot in front of the checkpoint frequency,
3384 as shown in the previous section.
3386 Yet another action, `sleep', pauses `tar' for a specified amount of
3387 seconds. The following example will stop for 30 seconds at each
3390 $ tar -c --checkpoint=1000 --checkpoint-action=sleep=30
3392 Finally, the `exec' action executes a given external program. For
3395 $ tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint
3397 This program is executed using `/bin/sh -c', with no additional
3398 arguments. Its exit code is ignored. It gets a copy of `tar''s
3399 environment plus the following variables:
3402 GNU `tar' version number.
3405 The name of the archive `tar' is processing.
3407 `TAR_BLOCKING_FACTOR'
3408 Current blocking factor (*note Blocking::).
3411 Number of the checkpoint.
3414 A short option describing the operation `tar' is executing. *Note
3415 Operations::, for a complete list of subcommand options.
3418 Format of the archive being processed. *Note Formats::, for a
3419 complete list of archive format names.
3421 Any number of actions can be defined, by supplying several
3422 `--checkpoint-action' options in the command line. For example, the
3423 command below displays two messages, pauses execution for 30 seconds
3424 and executes the `/sbin/cpoint' script:
3426 $ tar -c -f arc.tar \
3427 --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
3428 --checkpoint-action='echo=Sleeping for 30 seconds' \
3429 --checkpoint-action='sleep=30' \
3430 --checkpoint-action='exec=/sbin/cpoint'
3432 This example also illustrates the fact that `--checkpoint-action'
3433 can be used without `--checkpoint'. In this case, the default
3434 checkpoint frequency (at each 10th record) is assumed.
3437 File: tar.info, Node: warnings, Next: interactive, Prev: checkpoints, Up: tar invocation
3439 3.9 Controlling Warning Messages
3440 ================================
3442 Sometimes, while performing the requested task, GNU `tar' notices some
3443 conditions that are not exactly errors, but which the user should be
3444 aware of. When this happens, `tar' issues a "warning message"
3445 describing the condition. Warning messages are output to the standard
3446 error and they do not affect the exit code of `tar' command.
3448 GNU `tar' allows the user to suppress some or all of its warning
3452 Control display of the warning messages identified by KEYWORD. If
3453 KEYWORD starts with the prefix `no-', such messages are
3454 suppressed. Otherwise, they are enabled.
3456 Multiple `--warning' messages accumulate.
3458 The tables below list allowed values for KEYWORD along with the
3459 warning messages they control.
3461 Keywords controlling `tar' operation
3462 ------------------------------------
3465 Enable all warning messages. This is the default.
3468 Disable all warning messages.
3471 `%s: file name read contains nul character'
3474 `A lone zero block at %s'
3476 Keywords applicable for `tar --create'
3477 --------------------------------------
3480 `%s: contains a cache directory tag %s; %s'
3483 `%s: File shrank by %s bytes; padding with zeros'
3486 `%s: file is on a different filesystem; not dumped'
3489 `%s: Unknown file type; file ignored'
3490 `%s: socket ignored'
3494 `%s: file is unchanged; not dumped'
3497 `%s: file is the archive; not dumped'
3500 `%s: File removed before we read it'
3503 `%s: file changed as we read it'
3505 Keywords applicable for `tar --extract'
3506 ---------------------------------------
3509 `%s: implausibly old time stamp %s'
3510 `%s: time stamp %s is %s s in the future'
3513 `Extracting contiguous files as regular files'
3516 `Attempting extraction of symbolic links as hard links'
3519 `%s: Unknown file type `%c', extracted as normal file'
3522 `Current %s is newer or same age'
3525 `Ignoring unknown extended header keyword `%s''
3528 Controls verbose description of failures occurring when trying to
3529 run alternative decompressor programs (*note alternative
3530 decompression programs::). This warning is disabled by default
3531 (unless `--verbose' is used). A common example of what you can get
3532 when using this warning is:
3534 $ tar --warning=decompress-program -x -f archive.Z
3535 tar (child): cannot run compress: No such file or directory
3536 tar (child): trying gzip
3538 This means that `tar' first tried to decompress `archive.Z' using
3539 `compress', and, when that failed, switched to `gzip'.
3541 Keywords controlling incremental extraction:
3542 --------------------------------------------
3545 `%s: Directory has been renamed from %s'
3546 `%s: Directory has been renamed'
3549 `%s: Directory is new'
3552 `%s: directory is on a different device: not purging'
3555 `Malformed dumpdir: 'X' never used'
3558 File: tar.info, Node: interactive, Prev: warnings, Up: tar invocation
3560 3.10 Asking for Confirmation During Operations
3561 ==============================================
3563 Typically, `tar' carries out a command without stopping for further
3564 instructions. In some situations however, you may want to exclude some
3565 files and archive members from the operation (for instance if disk or
3566 storage space is tight). You can do this by excluding certain files
3567 automatically (*note Choosing::), or by performing an operation
3568 interactively, using the `--interactive' (`-w') option. `tar' also
3569 accepts `--confirmation' for this option.
3571 When the `--interactive' (`-w') option is specified, before reading,
3572 writing, or deleting files, `tar' first prints a message for each such
3573 file, telling what operation it intends to take, then asks for
3574 confirmation on the terminal. The actions which require confirmation
3575 include adding a file to the archive, extracting a file from the
3576 archive, deleting a file from the archive, and deleting a file from
3577 disk. To confirm the action, you must type a line of input beginning
3578 with `y'. If your input line begins with anything other than `y',
3579 `tar' skips that file.
3581 If `tar' is reading the archive from the standard input, `tar' opens
3582 the file `/dev/tty' to support the interactive communications.
3584 Verbose output is normally sent to standard output, separate from
3585 other error messages. However, if the archive is produced directly on
3586 standard output, then verbose output is mixed with errors on `stderr'.
3587 Producing the archive on standard output may be used as a way to avoid
3588 using disk space, when the archive is soon to be consumed by another
3589 process reading it, say. Some people felt the need of producing an
3590 archive on stdout, still willing to segregate between verbose output
3591 and error output. A possible approach would be using a named pipe to
3592 receive the archive, and having the consumer process to read from that
3593 named pipe. This has the advantage of letting standard output free to
3594 receive verbose output, all separate from errors.
3597 File: tar.info, Node: operations, Next: Backups, Prev: tar invocation, Up: Top
3599 4 GNU `tar' Operations
3600 **********************
3613 File: tar.info, Node: Basic tar, Next: Advanced tar, Up: operations
3615 4.1 Basic GNU `tar' Operations
3616 ==============================
3618 The basic `tar' operations, `--create' (`-c'), `--list' (`-t') and
3619 `--extract' (`--get', `-x'), are currently presented and described in
3620 the tutorial chapter of this manual. This section provides some
3621 complementary notes for these operations.
3625 Creating an empty archive would have some kind of elegance. One
3626 can initialize an empty archive and later use `--append' (`-r')
3627 for adding all members. Some applications would not welcome
3628 making an exception in the way of adding the first archive member.
3629 On the other hand, many people reported that it is dangerously too
3630 easy for `tar' to destroy a magnetic tape with an empty
3631 archive(1). The two most common errors are:
3633 1. Mistakingly using `create' instead of `extract', when the
3634 intent was to extract the full contents of an archive. This
3635 error is likely: keys `c' and `x' are right next to each
3636 other on the QWERTY keyboard. Instead of being unpacked, the
3637 archive then gets wholly destroyed. When users speak about
3638 "exploding" an archive, they usually mean something else :-).
3640 2. Forgetting the argument to `file', when the intent was to
3641 create an archive with a single file in it. This error is
3642 likely because a tired user can easily add the `f' key to the
3643 cluster of option letters, by the mere force of habit,
3644 without realizing the full consequence of doing so. The
3645 usual consequence is that the single file, which was meant to
3646 be saved, is rather destroyed.
3648 So, recognizing the likelihood and the catastrophic nature of these
3649 errors, GNU `tar' now takes some distance from elegance, and
3650 cowardly refuses to create an archive when `--create' option is
3651 given, there are no arguments besides options, and `--files-from'
3652 (`-T') option is _not_ used. To get around the cautiousness of
3653 GNU `tar' and nevertheless create an archive with nothing in it,
3654 one may still use, as the value for the `--files-from' option, a
3655 file with no names in it, as shown in the following commands:
3657 tar --create --file=empty-archive.tar --files-from=/dev/null
3658 tar cfT empty-archive.tar /dev/null
3663 A socket is stored, within a GNU `tar' archive, as a pipe.
3666 GNU `tar' now shows dates as `1996-08-30', while it used to show
3667 them as `Aug 30 1996'. Preferably, people should get used to ISO
3668 8601 dates. Local American dates should be made available again
3669 with full date localization support, once ready. In the meantime,
3670 programs not being localizable for dates should prefer
3671 international dates, that's really the way to go.
3673 Look up `http://www.cl.cam.ac.uk/~mgk25/iso-time.html' if you are
3674 curious, it contains a detailed explanation of the ISO 8601
3678 ---------- Footnotes ----------
3680 (1) This is well described in `Unix-haters Handbook', by Simson
3681 Garfinkel, Daniel Weise & Steven Strassmann, IDG Books, ISBN
3685 File: tar.info, Node: Advanced tar, Next: create options, Prev: Basic tar, Up: operations
3687 4.2 Advanced GNU `tar' Operations
3688 =================================
3690 Now that you have learned the basics of using GNU `tar', you may want
3691 to learn about further ways in which `tar' can help you.
3693 This chapter presents five, more advanced operations which you
3694 probably won't use on a daily basis, but which serve more specialized
3695 functions. We also explain the different styles of options and why you
3696 might want to use one or another, or a combination of them in your `tar'
3697 commands. Additionally, this chapter includes options which allow you
3698 to define the output from `tar' more carefully, and provide help and
3699 error correction in special circumstances.
3711 File: tar.info, Node: Operations, Next: append, Up: Advanced tar
3713 4.2.1 The Five Advanced `tar' Operations
3714 ----------------------------------------
3716 In the last chapter, you learned about the first three operations to
3717 `tar'. This chapter presents the remaining five operations to `tar':
3718 `--append', `--update', `--concatenate', `--delete', and `--compare'.
3720 You are not likely to use these operations as frequently as those
3721 covered in the last chapter; however, since they perform specialized
3722 functions, they are quite useful when you do need to use them. We will
3723 give examples using the same directory and files that you created in
3724 the last chapter. As you may recall, the directory is called
3725 `practice', the files are `jazz', `blues', `folk', and the two archive
3726 files you created are `collection.tar' and `music.tar'.
3728 We will also use the archive files `afiles.tar' and `bfiles.tar'.
3729 The archive `afiles.tar' contains the members `apple', `angst', and
3730 `aspic'; `bfiles.tar' contains the members `./birds', `baboon', and
3733 Unless we state otherwise, all practicing you do and examples you
3734 follow in this chapter will take place in the `practice' directory that
3735 you created in the previous chapter; see *note prepare for examples::.
3736 (Below in this section, we will remind you of the state of the examples
3737 where the last chapter left them.)
3739 The five operations that we will cover in this chapter are:
3743 Add new entries to an archive that already exists.
3747 Add more recent copies of archive members to the end of an
3748 archive, if they exist.
3753 Add one or more pre-existing archives to the end of another
3757 Delete items from an archive (does not work on tapes).
3762 Compare archive members to their counterparts in the file system.
3765 File: tar.info, Node: append, Next: update, Prev: Operations, Up: Advanced tar
3767 4.2.2 How to Add Files to Existing Archives: `--append'
3768 -------------------------------------------------------
3770 If you want to add files to an existing archive, you don't need to
3771 create a new archive; you can use `--append' (`-r'). The archive must
3772 already exist in order to use `--append'. (A related operation is the
3773 `--update' operation; you can use this to add newer versions of archive
3774 members to an existing archive. To learn how to do this with
3775 `--update', *note update::.)
3777 If you use `--append' to add a file that has the same name as an
3778 archive member to an archive containing that archive member, then the
3779 old member is not deleted. What does happen, however, is somewhat
3780 complex. `tar' _allows_ you to have infinite number of files with the
3781 same name. Some operations treat these same-named members no
3782 differently than any other set of archive members: for example, if you
3783 view an archive with `--list' (`-t'), you will see all of those members
3784 listed, with their data modification times, owners, etc.
3786 Other operations don't deal with these members as perfectly as you
3787 might prefer; if you were to use `--extract' to extract the archive,
3788 only the most recently added copy of a member with the same name as
3789 other members would end up in the working directory. This is because
3790 `--extract' extracts an archive in the order the members appeared in
3791 the archive; the most recently archived members will be extracted last.
3792 Additionally, an extracted member will _replace_ a file of the same
3793 name which existed in the directory already, and `tar' will not prompt
3794 you about this(1). Thus, only the most recently archived member will
3795 end up being extracted, as it will replace the one extracted before it,
3798 There exists a special option that allows you to get around this
3799 behavior and extract (or list) only a particular copy of the file.
3800 This is `--occurrence' option. If you run `tar' with this option, it
3801 will extract only the first copy of the file. You may also give this
3802 option an argument specifying the number of copy to be extracted.
3803 Thus, for example if the archive `archive.tar' contained three copies
3804 of file `myfile', then the command
3806 tar --extract --file archive.tar --occurrence=2 myfile
3808 would extract only the second copy. *Note --occurrence: Option
3809 Summary, for the description of `--occurrence' option.
3811 If you want to replace an archive member, use `--delete' to delete
3812 the member you want to remove from the archive, and then use `--append'
3813 to add the member you want to be in the archive. Note that you can not
3814 change the order of the archive; the most recently added member will
3815 still appear last. In this sense, you cannot truly "replace" one
3816 member with another. (Replacing one member with another will not work
3817 on certain types of media, such as tapes; see *note delete:: and *note
3818 Media::, for more information.)
3822 * appending files:: Appending Files to an Archive
3825 ---------- Footnotes ----------
3827 (1) Unless you give it `--keep-old-files' option, or the disk copy
3828 is newer than the one in the archive and you invoke `tar' with
3829 `--keep-newer-files' option.
3832 File: tar.info, Node: appending files, Next: multiple, Up: append
3834 4.2.2.1 Appending Files to an Archive
3835 .....................................
3837 The simplest way to add a file to an already existing archive is the
3838 `--append' (`-r') operation, which writes specified files into the
3839 archive whether or not they are already among the archived files.
3841 When you use `--append', you _must_ specify file name arguments, as
3842 there is no default. If you specify a file that already exists in the
3843 archive, another copy of the file will be added to the end of the
3844 archive. As with other operations, the member names of the newly added
3845 files will be exactly the same as their names given on the command
3846 line. The `--verbose' (`-v') option will print out the names of the
3847 files as they are written into the archive.
3849 `--append' cannot be performed on some tape drives, unfortunately,
3850 due to deficiencies in the formats those tape drives use. The archive
3851 must be a valid `tar' archive, or else the results of using this
3852 operation will be unpredictable. *Note Media::.
3854 To demonstrate using `--append' to add a file to an archive, create
3855 a file called `rock' in the `practice' directory. Make sure you are in
3856 the `practice' directory. Then, run the following `tar' command to add
3857 `rock' to `collection.tar':
3859 $ tar --append --file=collection.tar rock
3861 If you now use the `--list' (`-t') operation, you will see that `rock'
3862 has been added to the archive:
3864 $ tar --list --file=collection.tar
3865 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
3866 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
3867 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
3868 -rw-r--r-- me/user 20 1996-09-23 16:44 rock
3871 File: tar.info, Node: multiple, Prev: appending files, Up: append
3873 4.2.2.2 Multiple Members with the Same Name
3874 ...........................................
3876 You can use `--append' (`-r') to add copies of files which have been
3877 updated since the archive was created. (However, we do not recommend
3878 doing this since there is another `tar' option called `--update'; *Note
3879 update::, for more information. We describe this use of `--append'
3880 here for the sake of completeness.) When you extract the archive, the
3881 older version will be effectively lost. This works because files are
3882 extracted from an archive in the order in which they were archived.
3883 Thus, when the archive is extracted, a file archived later in time will
3884 replace a file of the same name which was archived earlier, even though
3885 the older version of the file will remain in the archive unless you
3886 delete all versions of the file.
3888 Supposing you change the file `blues' and then append the changed
3889 version to `collection.tar'. As you saw above, the original `blues' is
3890 in the archive `collection.tar'. If you change the file and append the
3891 new version of the file to the archive, there will be two copies in the
3892 archive. When you extract the archive, the older version of the file
3893 will be extracted first, and then replaced by the newer version when it
3896 You can append the new, changed copy of the file `blues' to the
3897 archive in this way:
3899 $ tar --append --verbose --file=collection.tar blues
3902 Because you specified the `--verbose' option, `tar' has printed the
3903 name of the file being appended as it was acted on. Now list the
3904 contents of the archive:
3906 $ tar --list --verbose --file=collection.tar
3907 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
3908 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
3909 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
3910 -rw-r--r-- me/user 20 1996-09-23 16:44 rock
3911 -rw-r--r-- me/user 58 1996-10-24 18:30 blues
3913 The newest version of `blues' is now at the end of the archive (note
3914 the different creation dates and file sizes). If you extract the
3915 archive, the older version of the file `blues' will be replaced by the
3916 newer version. You can confirm this by extracting the archive and
3917 running `ls' on the directory.
3919 If you wish to extract the first occurrence of the file `blues' from
3920 the archive, use `--occurrence' option, as shown in the following
3923 $ tar --extract -vv --occurrence --file=collection.tar blues
3924 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
3926 *Note Writing::, for more information on `--extract' and see *note
3927 -occurrence: Option Summary, for a description of `--occurrence' option.
3930 File: tar.info, Node: update, Next: concatenate, Prev: append, Up: Advanced tar
3932 4.2.3 Updating an Archive
3933 -------------------------
3935 In the previous section, you learned how to use `--append' to add a
3936 file to an existing archive. A related operation is `--update' (`-u').
3937 The `--update' operation updates a `tar' archive by comparing the date
3938 of the specified archive members against the date of the file with the
3939 same name. If the file has been modified more recently than the
3940 archive member, then the newer version of the file is added to the
3941 archive (as with `--append').
3943 Unfortunately, you cannot use `--update' with magnetic tape drives.
3944 The operation will fail.
3946 Both `--update' and `--append' work by adding to the end of the
3947 archive. When you extract a file from the archive, only the version
3948 stored last will wind up in the file system, unless you use the
3949 `--backup' option. *Note multiple::, for a detailed discussion.
3956 File: tar.info, Node: how to update, Up: update
3958 4.2.3.1 How to Update an Archive Using `--update'
3959 .................................................
3961 You must use file name arguments with the `--update' (`-u') operation.
3962 If you don't specify any files, `tar' won't act on any files and won't
3963 tell you that it didn't do anything (which may end up confusing you).
3965 To see the `--update' option at work, create a new file,
3966 `classical', in your practice directory, and some extra text to the
3967 file `blues', using any text editor. Then invoke `tar' with the
3968 `update' operation and the `--verbose' (`-v') option specified, using
3969 the names of all the files in the `practice' directory as file name
3972 $ tar --update -v -f collection.tar blues folk rock classical
3977 Because we have specified verbose mode, `tar' prints out the names of
3978 the files it is working on, which in this case are the names of the
3979 files that needed to be updated. If you run `tar --list' and look at
3980 the archive, you will see `blues' and `classical' at its end. There
3981 will be a total of two versions of the member `blues'; the one at the
3982 end will be newer and larger, since you added text before updating it.
3984 The reason `tar' does not overwrite the older file when updating it
3985 is because writing to the middle of a section of tape is a difficult
3986 process. Tapes are not designed to go backward. *Note Media::, for
3987 more information about tapes.
3989 `--update' (`-u') is not suitable for performing backups for two
3990 reasons: it does not change directory content entries, and it lengthens
3991 the archive every time it is used. The GNU `tar' options intended
3992 specifically for backups are more efficient. If you need to run
3993 backups, please consult *note Backups::.
3996 File: tar.info, Node: concatenate, Next: delete, Prev: update, Up: Advanced tar
3998 4.2.4 Combining Archives with `--concatenate'
3999 ---------------------------------------------
4001 Sometimes it may be convenient to add a second archive onto the end of
4002 an archive rather than adding individual files to the archive. To add
4003 one or more archives to the end of another archive, you should use the
4004 `--concatenate' (`--catenate', `-A') operation.
4006 To use `--concatenate', give the first archive with `--file' option
4007 and name the rest of archives to be concatenated on the command line.
4008 The members, and their member names, will be copied verbatim from those
4009 archives to the first one(1). The new, concatenated archive will be
4010 called by the same name as the one given with the `--file' option. As
4011 usual, if you omit `--file', `tar' will use the value of the environment
4012 variable `TAPE', or, if this has not been set, the default archive name.
4014 To demonstrate how `--concatenate' works, create two small archives
4015 called `bluesrock.tar' and `folkjazz.tar', using the relevant files
4018 $ tar -cvf bluesrock.tar blues rock
4021 $ tar -cvf folkjazz.tar folk jazz
4025 If you like, You can run `tar --list' to make sure the archives contain
4026 what they are supposed to:
4028 $ tar -tvf bluesrock.tar
4029 -rw-r--r-- melissa/user 105 1997-01-21 19:42 blues
4030 -rw-r--r-- melissa/user 33 1997-01-20 15:34 rock
4031 $ tar -tvf jazzfolk.tar
4032 -rw-r--r-- melissa/user 20 1996-09-23 16:44 folk
4033 -rw-r--r-- melissa/user 65 1997-01-30 14:15 jazz
4035 We can concatenate these two archives with `tar':
4038 $ tar --concatenate --file=bluesrock.tar jazzfolk.tar
4040 If you now list the contents of the `bluesrock.tar', you will see
4041 that now it also contains the archive members of `jazzfolk.tar':
4043 $ tar --list --file=bluesrock.tar
4049 When you use `--concatenate', the source and target archives must
4050 already exist and must have been created using compatible format
4051 parameters. Notice, that `tar' does not check whether the archives it
4052 concatenates have compatible formats, it does not even check if the
4053 files are really tar archives.
4055 Like `--append' (`-r'), this operation cannot be performed on some
4056 tape drives, due to deficiencies in the formats those tape drives use.
4058 It may seem more intuitive to you to want or try to use `cat' to
4059 concatenate two archives instead of using the `--concatenate'
4060 operation; after all, `cat' is the utility for combining files.
4062 However, `tar' archives incorporate an end-of-file marker which must
4063 be removed if the concatenated archives are to be read properly as one
4064 archive. `--concatenate' removes the end-of-archive marker from the
4065 target archive before each new archive is appended. If you use `cat'
4066 to combine the archives, the result will not be a valid `tar' format
4067 archive. If you need to retrieve files from an archive that was added
4068 to using the `cat' utility, use the `--ignore-zeros' (`-i') option.
4069 *Note Ignore Zeros::, for further information on dealing with archives
4070 improperly combined using the `cat' shell utility.
4072 ---------- Footnotes ----------
4074 (1) This can cause multiple members to have the same name. For
4075 information on how this affects reading the archive, see *note
4079 File: tar.info, Node: delete, Next: compare, Prev: concatenate, Up: Advanced tar
4081 4.2.5 Removing Archive Members Using `--delete'
4082 -----------------------------------------------
4084 You can remove members from an archive by using the `--delete' option.
4085 Specify the name of the archive with `--file' (`-f') and then specify
4086 the names of the members to be deleted; if you list no member names,
4087 nothing will be deleted. The `--verbose' option will cause `tar' to
4088 print the names of the members as they are deleted. As with
4089 `--extract', you must give the exact member names when using `tar
4090 --delete'. `--delete' will remove all versions of the named file from
4091 the archive. The `--delete' operation can run very slowly.
4093 Unlike other operations, `--delete' has no short form.
4095 This operation will rewrite the archive. You can only use
4096 `--delete' on an archive if the archive device allows you to write to
4097 any point on the media, such as a disk; because of this, it does not
4098 work on magnetic tapes. Do not try to delete an archive member from a
4099 magnetic tape; the action will not succeed, and you will be likely to
4100 scramble the archive and damage your tape. There is no safe way
4101 (except by completely re-writing the archive) to delete files from most
4102 kinds of magnetic tape. *Note Media::.
4104 To delete all versions of the file `blues' from the archive
4105 `collection.tar' in the `practice' directory, make sure you are in that
4106 directory, and then,
4108 $ tar --list --file=collection.tar
4113 $ tar --delete --file=collection.tar blues
4114 $ tar --list --file=collection.tar
4119 The `--delete' option has been reported to work properly when `tar'
4120 acts as a filter from `stdin' to `stdout'.
4123 File: tar.info, Node: compare, Prev: delete, Up: Advanced tar
4125 4.2.6 Comparing Archive Members with the File System
4126 ----------------------------------------------------
4128 The `--compare' (`-d'), or `--diff' operation compares specified
4129 archive members against files with the same names, and then reports
4130 differences in file size, mode, owner, modification date and contents.
4131 You should _only_ specify archive member names, not file names. If you
4132 do not name any members, then `tar' will compare the entire archive.
4133 If a file is represented in the archive but does not exist in the file
4134 system, `tar' reports a difference.
4136 You have to specify the record size of the archive when modifying an
4137 archive with a non-default record size.
4139 `tar' ignores files in the file system that do not have
4140 corresponding members in the archive.
4142 The following example compares the archive members `rock', `blues'
4143 and `funk' in the archive `bluesrock.tar' with files of the same name
4144 in the file system. (Note that there is no file, `funk'; `tar' will
4145 report an error message.)
4147 $ tar --compare --file=bluesrock.tar rock blues funk
4150 tar: funk not found in archive
4152 The spirit behind the `--compare' (`--diff', `-d') option is to
4153 check whether the archive represents the current state of files on
4154 disk, more than validating the integrity of the archive media. For
4155 this latter goal, see *note verify::.
4158 File: tar.info, Node: create options, Next: extract options, Prev: Advanced tar, Up: operations
4160 4.3 Options Used by `--create'
4161 ==============================
4163 The previous chapter described the basics of how to use `--create'
4164 (`-c') to create an archive from a set of files. *Note create::. This
4165 section described advanced options to be used with `--create'.
4169 * override:: Overriding File Metadata.
4170 * Ignore Failed Read::
4173 File: tar.info, Node: override, Next: Ignore Failed Read, Up: create options
4175 4.3.1 Overriding File Metadata
4176 ------------------------------
4178 As described above, a `tar' archive keeps, for each member it contains,
4179 its "metadata", such as modification time, mode and ownership of the
4180 file. GNU `tar' allows to replace these data with other values when
4181 adding files to the archive. The options described in this section
4182 affect creation of archives of any type. For POSIX archives, see also
4183 *note PAX keywords::, for additional ways of controlling metadata,
4184 stored in the archive.
4186 `--mode=PERMISSIONS'
4187 When adding files to an archive, `tar' will use PERMISSIONS for
4188 the archive members, rather than the permissions from the files.
4189 PERMISSIONS can be specified either as an octal number or as
4190 symbolic permissions, like with `chmod' (*Note Permissions:
4191 (fileutils)File permissions. This reference also has useful
4192 information for those not being overly familiar with the UNIX
4193 permission system). Using latter syntax allows for more
4194 flexibility. For example, the value `a+rw' adds read and write
4195 permissions for everybody, while retaining executable bits on
4196 directories or on any other file already marked as executable:
4198 $ tar -c -f archive.tar --mode='a+rw' .
4201 When adding files to an archive, `tar' will use DATE as the
4202 modification time of members when creating archives, instead of
4203 their actual modification times. The argument DATE can be either
4204 a textual date representation in almost arbitrary format (*note
4205 Date input formats::) or a name of an existing file, starting with
4206 `/' or `.'. In the latter case, the modification time of that
4209 The following example will set the modification date to 00:00:00,
4212 $ tar -c -f archive.tar --mtime='1970-01-01' .
4214 When used with `--verbose' (*note verbose tutorial::) GNU `tar'
4215 will try to convert the specified date back to its textual
4216 representation and compare it with the one given with `--mtime'
4217 options. If the two dates differ, `tar' will print a warning
4218 saying what date it will use. This is to help user ensure he is
4219 using the right date.
4223 $ tar -c -f archive.tar -v --mtime=yesterday .
4224 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4229 Specifies that `tar' should use USER as the owner of members when
4230 creating archives, instead of the user associated with the source
4231 file. The argument USER can be either an existing user symbolic
4232 name, or a decimal numeric user ID.
4234 There is no value indicating a missing number, and `0' usually
4235 means `root'. Some people like to force `0' as the value to offer
4236 in their distributions for the owner of files, because the `root'
4237 user is anonymous anyway, so that might as well be the owner of
4238 anonymous archives. For example:
4240 $ tar -c -f archive.tar --owner=0 .
4244 $ tar -c -f archive.tar --owner=root .
4247 Files added to the `tar' archive will have a group ID of GROUP,
4248 rather than the group from the source file. The argument GROUP
4249 can be either an existing group symbolic name, or a decimal
4253 File: tar.info, Node: Ignore Failed Read, Prev: override, Up: create options
4255 4.3.2 Ignore Fail Read
4256 ----------------------
4258 `--ignore-failed-read'
4259 Do not exit with nonzero on unreadable files or directories.
4262 File: tar.info, Node: extract options, Next: backup, Prev: create options, Up: operations
4264 4.4 Options Used by `--extract'
4265 ===============================
4267 The previous chapter showed how to use `--extract' to extract an
4268 archive into the file system. Various options cause `tar' to extract
4269 more information than just file contents, such as the owner, the
4270 permissions, the modification date, and so forth. This section
4271 presents options to be used with `--extract' when certain special
4272 considerations arise. You may review the information presented in
4273 *note extract:: for more basic information about the `--extract'
4278 * Reading:: Options to Help Read Archives
4279 * Writing:: Changing How `tar' Writes Files
4280 * Scarce:: Coping with Scarce Resources
4283 File: tar.info, Node: Reading, Next: Writing, Up: extract options
4285 4.4.1 Options to Help Read Archives
4286 -----------------------------------
4288 Normally, `tar' will request data in full record increments from an
4289 archive storage device. If the device cannot return a full record,
4290 `tar' will report an error. However, some devices do not always return
4291 full records, or do not require the last record of an archive to be
4292 padded out to the next record boundary. To keep reading until you
4293 obtain a full record, or to accept an incomplete record if it contains
4294 an end-of-archive marker, specify the `--read-full-records' (`-B')
4295 option in conjunction with the `--extract' or `--list' operations.
4298 The `--read-full-records' (`-B') option is turned on by default when
4299 `tar' reads an archive from standard input, or from a remote machine.
4300 This is because on BSD Unix systems, attempting to read a pipe returns
4301 however much happens to be in the pipe, even if it is less than was
4302 requested. If this option were not enabled, `tar' would fail as soon
4303 as it read an incomplete record from the pipe.
4305 If you're not sure of the blocking factor of an archive, you can
4306 read the archive by specifying `--read-full-records' (`-B') and
4307 `--blocking-factor=512-SIZE' (`-b 512-SIZE'), using a blocking factor
4308 larger than what the archive uses. This lets you avoid having to
4309 determine the blocking factor of an archive. *Note Blocking Factor::.
4313 * read full records::
4317 File: tar.info, Node: read full records, Next: Ignore Zeros, Up: Reading
4319 Reading Full Records
4320 ....................
4322 `--read-full-records'
4325 Use in conjunction with `--extract' (`--get', `-x') to read an
4326 archive which contains incomplete records, or one which has a
4327 blocking factor less than the one specified.
4330 File: tar.info, Node: Ignore Zeros, Prev: read full records, Up: Reading
4332 Ignoring Blocks of Zeros
4333 ........................
4335 Normally, `tar' stops reading when it encounters a block of zeros
4336 between file entries (which usually indicates the end of the archive).
4337 `--ignore-zeros' (`-i') allows `tar' to completely read an archive
4338 which contains a block of zeros before the end (i.e., a damaged
4339 archive, or one that was created by concatenating several archives
4342 The `--ignore-zeros' (`-i') option is turned off by default because
4343 many versions of `tar' write garbage after the end-of-archive entry,
4344 since that part of the media is never supposed to be read. GNU `tar'
4345 does not write after the end of an archive, but seeks to maintain
4346 compatibility among archiving utilities.
4350 To ignore blocks of zeros (i.e., end-of-archive entries) which may
4351 be encountered while reading an archive. Use in conjunction with
4352 `--extract' or `--list'.
4355 File: tar.info, Node: Writing, Next: Scarce, Prev: Reading, Up: extract options
4357 4.4.2 Changing How `tar' Writes Files
4358 -------------------------------------
4360 _(This message will disappear, once this node revised.)_
4364 * Dealing with Old Files::
4365 * Overwrite Old Files::
4367 * Keep Newer Files::
4369 * Recursive Unlink::
4370 * Data Modification Times::
4371 * Setting Access Permissions::
4372 * Directory Modification Times and Permissions::
4373 * Writing to Standard Output::
4374 * Writing to an External Program::
4378 File: tar.info, Node: Dealing with Old Files, Next: Overwrite Old Files, Up: Writing
4380 Options Controlling the Overwriting of Existing Files
4381 .....................................................
4383 When extracting files, if `tar' discovers that the extracted file
4384 already exists, it normally replaces the file by removing it before
4385 extracting it, to prevent confusion in the presence of hard or symbolic
4386 links. (If the existing file is a symbolic link, it is removed, not
4387 followed.) However, if a directory cannot be removed because it is
4388 nonempty, `tar' normally overwrites its metadata (ownership,
4389 permission, etc.). The `--overwrite-dir' option enables this default
4390 behavior. To be more cautious and preserve the metadata of such a
4391 directory, use the `--no-overwrite-dir' option.
4393 To be even more cautious and prevent existing files from being
4394 replaced, use the `--keep-old-files' (`-k') option. It causes `tar' to
4395 refuse to replace or update a file that already exists, i.e., a file
4396 with the same name as an archive member prevents extraction of that
4397 archive member. Instead, it reports an error.
4399 To be more aggressive about altering existing files, use the
4400 `--overwrite' option. It causes `tar' to overwrite existing files and
4401 to follow existing symbolic links when extracting.
4403 Some people argue that GNU `tar' should not hesitate to overwrite
4404 files with other files when extracting. When extracting a `tar'
4405 archive, they expect to see a faithful copy of the state of the file
4406 system when the archive was created. It is debatable that this would
4407 always be a proper behavior. For example, suppose one has an archive
4408 in which `usr/local' is a link to `usr/local2'. Since then, maybe the
4409 site removed the link and renamed the whole hierarchy from
4410 `/usr/local2' to `/usr/local'. Such things happen all the time. I
4411 guess it would not be welcome at all that GNU `tar' removes the whole
4412 hierarchy just to make room for the link to be reinstated (unless it
4413 _also_ simultaneously restores the full `/usr/local2', of course!) GNU
4414 `tar' is indeed able to remove a whole hierarchy to reestablish a
4415 symbolic link, for example, but _only if_ `--recursive-unlink' is
4416 specified to allow this behavior. In any case, single files are
4419 Finally, the `--unlink-first' (`-U') option can improve performance
4420 in some cases by causing `tar' to remove files unconditionally before
4424 File: tar.info, Node: Overwrite Old Files, Next: Keep Old Files, Prev: Dealing with Old Files, Up: Writing
4430 Overwrite existing files and directory metadata when extracting
4431 files from an archive.
4433 This causes `tar' to write extracted files into the file system
4434 without regard to the files already on the system; i.e., files
4435 with the same names as archive members are overwritten when the
4436 archive is extracted. It also causes `tar' to extract the
4437 ownership, permissions, and time stamps onto any preexisting files
4438 or directories. If the name of a corresponding file name is a
4439 symbolic link, the file pointed to by the symbolic link will be
4440 overwritten instead of the symbolic link itself (if this is
4441 possible). Moreover, special devices, empty directories and even
4442 symbolic links are automatically removed if they are in the way of
4445 Be careful when using the `--overwrite' option, particularly when
4446 combined with the `--absolute-names' (`-P') option, as this
4447 combination can change the contents, ownership or permissions of
4448 any file on your system. Also, many systems do not take kindly to
4449 overwriting files that are currently being executed.
4452 Overwrite the metadata of directories when extracting files from an
4453 archive, but remove other files before extracting.
4456 File: tar.info, Node: Keep Old Files, Next: Keep Newer Files, Prev: Overwrite Old Files, Up: Writing
4463 Do not replace existing files from archive. The
4464 `--keep-old-files' (`-k') option prevents `tar' from replacing
4465 existing files with files with the same name from the archive. The
4466 `--keep-old-files' option is meaningless with `--list' (`-t').
4467 Prevents `tar' from replacing files in the file system during
4471 File: tar.info, Node: Keep Newer Files, Next: Unlink First, Prev: Keep Old Files, Up: Writing
4476 `--keep-newer-files'
4477 Do not replace existing files that are newer than their archive
4478 copies. This option is meaningless with `--list' (`-t').
4481 File: tar.info, Node: Unlink First, Next: Recursive Unlink, Prev: Keep Newer Files, Up: Writing
4488 Remove files before extracting over them. This can make `tar' run
4489 a bit faster if you know in advance that the extracted files all
4490 need to be removed. Normally this option slows `tar' down
4491 slightly, so it is disabled by default.
4494 File: tar.info, Node: Recursive Unlink, Next: Data Modification Times, Prev: Unlink First, Up: Writing
4499 `--recursive-unlink'
4500 When this option is specified, try removing files and directory
4501 hierarchies before extracting over them. _This is a dangerous
4504 If you specify the `--recursive-unlink' option, `tar' removes
4505 _anything_ that keeps you from extracting a file as far as current
4506 permissions will allow it. This could include removal of the contents
4507 of a full directory hierarchy.
4510 File: tar.info, Node: Data Modification Times, Next: Setting Access Permissions, Prev: Recursive Unlink, Up: Writing
4512 Setting Data Modification Times
4513 ...............................
4515 Normally, `tar' sets the data modification times of extracted files to
4516 the corresponding times recorded for the files in the archive, but
4517 limits the permissions of extracted files by the current `umask'
4520 To set the data modification times of extracted files to the time
4521 when the files were extracted, use the `--touch' (`-m') option in
4522 conjunction with `--extract' (`--get', `-x').
4526 Sets the data modification time of extracted archive members to
4527 the time they were extracted, not the time recorded for them in
4528 the archive. Use in conjunction with `--extract' (`--get', `-x').
4531 File: tar.info, Node: Setting Access Permissions, Next: Directory Modification Times and Permissions, Prev: Data Modification Times, Up: Writing
4533 Setting Access Permissions
4534 ..........................
4536 To set the modes (access permissions) of extracted files to those
4537 recorded for those files in the archive, use `--same-permissions' in
4538 conjunction with the `--extract' (`--get', `-x') operation.
4540 `--preserve-permissions'
4541 `--same-permissions'
4543 Set modes of extracted archive members to those recorded in the
4544 archive, instead of current umask settings. Use in conjunction
4545 with `--extract' (`--get', `-x').
4548 File: tar.info, Node: Directory Modification Times and Permissions, Next: Writing to Standard Output, Prev: Setting Access Permissions, Up: Writing
4550 Directory Modification Times and Permissions
4551 ............................................
4553 After successfully extracting a file member, GNU `tar' normally
4554 restores its permissions and modification times, as described in the
4555 previous sections. This cannot be done for directories, because after
4556 extracting a directory `tar' will almost certainly extract files into
4557 that directory and this will cause the directory modification time to
4558 be updated. Moreover, restoring that directory permissions may not
4559 permit file creation within it. Thus, restoring directory permissions
4560 and modification times must be delayed at least until all files have
4561 been extracted into that directory. GNU `tar' restores directories
4562 using the following approach.
4564 The extracted directories are created with the mode specified in the
4565 archive, as modified by the umask of the user, which gives sufficient
4566 permissions to allow file creation. The meta-information about the
4567 directory is recorded in the temporary list of directories. When
4568 preparing to extract next archive member, GNU `tar' checks if the
4569 directory prefix of this file contains the remembered directory. If it
4570 does not, the program assumes that all files have been extracted into
4571 that directory, restores its modification time and permissions and
4572 removes its entry from the internal list. This approach allows to
4573 correctly restore directory meta-information in the majority of cases,
4574 while keeping memory requirements sufficiently small. It is based on
4575 the fact, that most `tar' archives use the predefined order of members:
4576 first the directory, then all the files and subdirectories in that
4579 However, this is not always true. The most important exception are
4580 incremental archives (*note Incremental Dumps::). The member order in
4581 an incremental archive is reversed: first all directory members are
4582 stored, followed by other (non-directory) members. So, when extracting
4583 from incremental archives, GNU `tar' alters the above procedure. It
4584 remembers all restored directories, and restores their meta-data only
4585 after the entire archive has been processed. Notice, that you do not
4586 need to specify any special options for that, as GNU `tar'
4587 automatically detects archives in incremental format.
4589 There may be cases, when such processing is required for normal
4590 archives too. Consider the following example:
4592 $ tar --no-recursion -cvf archive \
4593 foo foo/file1 bar bar/file foo/file2
4600 During the normal operation, after encountering `bar' GNU `tar' will
4601 assume that all files from the directory `foo' were already extracted
4602 and will therefore restore its timestamp and permission bits. However,
4603 after extracting `foo/file2' the directory timestamp will be offset
4606 To correctly restore directory meta-information in such cases, use
4607 the `--delay-directory-restore' command line option:
4609 `--delay-directory-restore'
4610 Delays restoring of the modification times and permissions of
4611 extracted directories until the end of extraction. This way,
4612 correct meta-information is restored even if the archive has
4613 unusual member ordering.
4615 `--no-delay-directory-restore'
4616 Cancel the effect of the previous `--delay-directory-restore'.
4617 Use this option if you have used `--delay-directory-restore' in
4618 `TAR_OPTIONS' variable (*note TAR_OPTIONS::) and wish to
4619 temporarily disable it.
4622 File: tar.info, Node: Writing to Standard Output, Next: Writing to an External Program, Prev: Directory Modification Times and Permissions, Up: Writing
4624 Writing to Standard Output
4625 ..........................
4627 To write the extracted files to the standard output, instead of
4628 creating the files on the file system, use `--to-stdout' (`-O') in
4629 conjunction with `--extract' (`--get', `-x'). This option is useful if
4630 you are extracting files to send them through a pipe, and do not need to
4631 preserve them in the file system. If you extract multiple members,
4632 they appear on standard output concatenated, in the order they are
4633 found in the archive.
4637 Writes files to the standard output. Use only in conjunction with
4638 `--extract' (`--get', `-x'). When this option is used, instead of
4639 creating the files specified, `tar' writes the contents of the
4640 files extracted to its standard output. This may be useful if you
4641 are only extracting the files in order to send them through a
4642 pipe. This option is meaningless with `--list' (`-t').
4644 This can be useful, for example, if you have a tar archive containing
4645 a big file and don't want to store the file on disk before processing
4646 it. You can use a command like this:
4648 tar -xOzf foo.tgz bigfile | process
4650 or even like this if you want to process the concatenation of the
4653 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4655 However, `--to-command' may be more convenient for use with multiple
4656 files. See the next section.
4659 File: tar.info, Node: Writing to an External Program, Next: remove files, Prev: Writing to Standard Output, Up: Writing
4661 Writing to an External Program
4662 ..............................
4664 You can instruct `tar' to send the contents of each extracted file to
4665 the standard input of an external program:
4667 `--to-command=COMMAND'
4668 Extract files and pipe their contents to the standard input of
4669 COMMAND. When this option is used, instead of creating the files
4670 specified, `tar' invokes COMMAND and pipes the contents of the
4671 files to its standard output. The COMMAND may contain command line
4672 arguments. The program is executed via `sh -c'. Notice, that
4673 COMMAND is executed once for each regular file extracted.
4674 Non-regular files (directories, etc.) are ignored when this option
4677 The command can obtain the information about the file it processes
4678 from the following environment variables:
4681 Type of the file. It is a single letter with the following meaning:
4690 Currently only regular files are supported.
4693 File mode, an octal number.
4696 The name of the file.
4699 Name of the file as stored in the archive.
4702 Name of the file owner.
4705 Name of the file owner group.
4708 Time of last access. It is a decimal number, representing seconds
4709 since the Epoch. If the archive provides times with nanosecond
4710 precision, the nanoseconds are appended to the timestamp after a
4714 Time of last modification.
4717 Time of last status change.
4723 UID of the file owner.
4726 GID of the file owner.
4728 Additionally, the following variables contain information about tar
4729 mode and the archive being processed:
4732 GNU `tar' version number.
4735 The name of the archive `tar' is processing.
4737 `TAR_BLOCKING_FACTOR'
4738 Current blocking factor (*note Blocking::).
4741 Ordinal number of the volume `tar' is processing.
4744 Format of the archive being processed. *Note Formats::, for a
4745 complete list of archive format names.
4747 If COMMAND exits with a non-0 status, `tar' will print an error
4748 message similar to the following:
4750 tar: 2345: Child returned status 1
4752 Here, `2345' is the PID of the finished process.
4754 If this behavior is not wanted, use `--ignore-command-error':
4756 `--ignore-command-error'
4757 Ignore exit codes of subprocesses. Notice that if the program
4758 exits on signal or otherwise terminates abnormally, the error
4759 message will be printed even if this option is used.
4761 `--no-ignore-command-error'
4762 Cancel the effect of any previous `--ignore-command-error' option.
4763 This option is useful if you have set `--ignore-command-error' in
4764 `TAR_OPTIONS' (*note TAR_OPTIONS::) and wish to temporarily cancel
4768 File: tar.info, Node: remove files, Prev: Writing to an External Program, Up: Writing
4774 Remove files after adding them to the archive.
4777 File: tar.info, Node: Scarce, Prev: Writing, Up: extract options
4779 4.4.3 Coping with Scarce Resources
4780 ----------------------------------
4782 _(This message will disappear, once this node revised.)_
4790 File: tar.info, Node: Starting File, Next: Same Order, Up: Scarce
4795 `--starting-file=NAME'
4797 Starts an operation in the middle of an archive. Use in
4798 conjunction with `--extract' (`--get', `-x') or `--list' (`-t').
4800 If a previous attempt to extract files failed due to lack of disk
4801 space, you can use `--starting-file=NAME' (`-K NAME') to start
4802 extracting only after member NAME of the archive. This assumes, of
4803 course, that there is now free space, or that you are now extracting
4804 into a different file system. (You could also choose to suspend `tar',
4805 remove unnecessary files from the file system, and then resume the same
4806 `tar' operation. In this case, `--starting-file' is not necessary.)
4807 See also *note interactive::, and *note exclude::.
4810 File: tar.info, Node: Same Order, Prev: Starting File, Up: Scarce
4818 To process large lists of file names on machines with small
4819 amounts of memory. Use in conjunction with `--compare' (`--diff',
4820 `-d'), `--list' (`-t') or `--extract' (`--get', `-x').
4822 The `--same-order' (`--preserve-order', `-s') option tells `tar'
4823 that the list of file names to be listed or extracted is sorted in the
4824 same order as the files in the archive. This allows a large list of
4825 names to be used, even on a small machine that would not otherwise be
4826 able to hold all the names in memory at the same time. Such a sorted
4827 list can easily be created by running `tar -t' on the archive and
4830 This option is probably never needed on modern computer systems.
4833 File: tar.info, Node: backup, Next: Applications, Prev: extract options, Up: operations
4838 GNU `tar' offers options for making backups of files before writing new
4839 versions. These options control the details of these backups. They
4840 may apply to the archive itself before it is created or rewritten, as
4841 well as individual extracted members. Other GNU programs (`cp',
4842 `install', `ln', and `mv', for example) offer similar options.
4844 Backup options may prove unexpectedly useful when extracting archives
4845 containing many members having identical name, or when extracting
4846 archives on systems having file name limitations, making different
4847 members appear as having similar names through the side-effect of name
4850 When any existing file is backed up before being overwritten by
4851 extraction, then clashing files are automatically be renamed to be
4852 unique, and the true name is kept for only the last file of a series of
4853 clashing files. By using verbose mode, users may track exactly what
4856 At the detail level, some decisions are still experimental, and may
4857 change in the future, we are waiting comments from our users. So,
4858 please do not learn to depend blindly on the details of the backup
4859 features. For example, currently, directories themselves are never
4860 renamed through using these options, so, extracting a file over a
4861 directory still has good chances to fail. Also, backup options apply
4862 to created archives, not only to extracted members. For created
4863 archives, backups will not be attempted when the archive is a block or
4864 character device, or when it refers to a remote file.
4866 For the sake of simplicity and efficiency, backups are made by
4867 renaming old files prior to creation or extraction, and not by copying.
4868 The original name is restored if the file creation fails. If a failure
4869 occurs after a partial extraction of a file, both the backup and the
4870 partially extracted file are kept.
4873 Back up files that are about to be overwritten or removed.
4874 Without this option, the original versions are destroyed.
4876 Use METHOD to determine the type of backups made. If METHOD is
4877 not specified, use the value of the `VERSION_CONTROL' environment
4878 variable. And if `VERSION_CONTROL' is not set, use the `existing'
4881 This option corresponds to the Emacs variable `version-control';
4882 the same values for METHOD are accepted as in Emacs. This option
4883 also allows more descriptive names. The valid METHODs are:
4887 Always make numbered backups.
4891 Make numbered backups of files that already have them, simple
4892 backups of the others.
4896 Always make simple backups.
4900 Append SUFFIX to each backup file made with `--backup'. If this
4901 option is not specified, the value of the `SIMPLE_BACKUP_SUFFIX'
4902 environment variable is used. And if `SIMPLE_BACKUP_SUFFIX' is not
4903 set, the default is `~', just as in Emacs.
4907 File: tar.info, Node: Applications, Next: looking ahead, Prev: backup, Up: operations
4909 4.6 Notable `tar' Usages
4910 ========================
4912 _(This message will disappear, once this node revised.)_
4914 You can easily use archive files to transport a group of files from one
4915 system to another: put all relevant files into an archive on one
4916 computer system, transfer the archive to another system, and extract
4917 the contents there. The basic transfer medium might be magnetic tape,
4918 Internet FTP, or even electronic mail (though you must encode the
4919 archive with `uuencode' in order to transport it properly by mail).
4920 Both machines do not have to use the same operating system, as long as
4921 they both support the `tar' program.
4923 For example, here is how you might copy a directory's contents from
4924 one disk to another, while preserving the dates, modes, owners and
4925 link-structure of all the files therein. In this case, the transfer
4928 $ (cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)
4930 You can avoid subshells by using `-C' option:
4932 $ tar -C sourcedir -cf - . | tar -C targetdir -xf -
4934 The command also works using long option forms:
4936 $ (cd sourcedir; tar --create --file=- . ) \
4937 | (cd targetdir; tar --extract --file=-)
4941 $ tar --directory sourcedir --create --file=- . \
4942 | tar --directory targetdir --extract --file=-
4944 This is one of the easiest methods to transfer a `tar' archive.
4947 File: tar.info, Node: looking ahead, Prev: Applications, Up: operations
4949 4.7 Looking Ahead: The Rest of this Manual
4950 ==========================================
4952 You have now seen how to use all eight of the operations available to
4953 `tar', and a number of the possible options. The next chapter explains
4954 how to choose and change file and archive names, how to use files to
4955 store names of other files which you can then call as arguments to
4956 `tar' (this can help you save time if you expect to archive the same
4957 list of files a number of times), and so forth.
4959 If there are too many files to conveniently list on the command line,
4960 you can list the names in a file, and `tar' will read that file. *Note
4963 There are various ways of causing `tar' to skip over some files, and
4964 not archive them. *Note Choosing::.
4967 File: tar.info, Node: Backups, Next: Choosing, Prev: operations, Up: Top
4969 5 Performing Backups and Restoring Files
4970 ****************************************
4972 GNU `tar' is distributed along with the scripts for performing backups
4973 and restores. Even if there is a good chance those scripts may be
4974 satisfying to you, they are not the only scripts or methods available
4975 for doing backups and restore. You may well create your own, or use
4976 more sophisticated packages dedicated to that purpose.
4978 Some users are enthusiastic about `Amanda' (The Advanced Maryland
4979 Automatic Network Disk Archiver), a backup system developed by James da
4980 Silva `jds@cs.umd.edu' and available on many Unix systems. This is
4981 free software, and it is available from `http://www.amanda.org'.
4983 This chapter documents both the provided shell scripts and `tar'
4984 options which are more specific to usage as a backup tool.
4986 To "back up" a file system means to create archives that contain all
4987 the files in that file system. Those archives can then be used to
4988 restore any or all of those files (for instance if a disk crashes or a
4989 file is accidentally deleted). File system "backups" are also called
4994 * Full Dumps:: Using `tar' to Perform Full Dumps
4995 * Incremental Dumps:: Using `tar' to Perform Incremental Dumps
4996 * Backup Levels:: Levels of Backups
4997 * Backup Parameters:: Setting Parameters for Backups and Restoration
4998 * Scripted Backups:: Using the Backup Scripts
4999 * Scripted Restoration:: Using the Restore Script
5002 File: tar.info, Node: Full Dumps, Next: Incremental Dumps, Up: Backups
5004 5.1 Using `tar' to Perform Full Dumps
5005 =====================================
5007 _(This message will disappear, once this node revised.)_
5009 Full dumps should only be made when no other people or programs are
5010 modifying files in the file system. If files are modified while `tar'
5011 is making the backup, they may not be stored properly in the archive,
5012 in which case you won't be able to restore them if you have to. (Files
5013 not being modified are written with no trouble, and do not corrupt the
5016 You will want to use the `--label=ARCHIVE-LABEL' (`-V
5017 ARCHIVE-LABEL') option to give the archive a volume label, so you can
5018 tell what this archive is even if the label falls off the tape, or
5021 Unless the file system you are dumping is guaranteed to fit on one
5022 volume, you will need to use the `--multi-volume' (`-M') option. Make
5023 sure you have enough tapes on hand to complete the backup.
5025 If you want to dump each file system separately you will need to use
5026 the `--one-file-system' option to prevent `tar' from crossing file
5027 system boundaries when storing (sub)directories.
5029 The `--incremental' (`-G') (*note Incremental Dumps::) option is not
5030 needed, since this is a complete copy of everything in the file system,
5031 and a full restore from this backup would only be done onto a completely
5034 Unless you are in a hurry, and trust the `tar' program (and your
5035 tapes), it is a good idea to use the `--verify' (`-W') option, to make
5036 sure your files really made it onto the dump properly. This will also
5037 detect cases where the file was modified while (or just after) it was
5038 being archived. Not all media (notably cartridge tapes) are capable of
5039 being verified, unfortunately.
5042 File: tar.info, Node: Incremental Dumps, Next: Backup Levels, Prev: Full Dumps, Up: Backups
5044 5.2 Using `tar' to Perform Incremental Dumps
5045 ============================================
5047 "Incremental backup" is a special form of GNU `tar' archive that stores
5048 additional metadata so that exact state of the file system can be
5049 restored when extracting the archive.
5051 GNU `tar' currently offers two options for handling incremental
5052 backups: `--listed-incremental=SNAPSHOT-FILE' (`-g SNAPSHOT-FILE') and
5053 `--incremental' (`-G').
5055 The option `--listed-incremental' instructs tar to operate on an
5056 incremental archive with additional metadata stored in a standalone
5057 file, called a "snapshot file". The purpose of this file is to help
5058 determine which files have been changed, added or deleted since the
5059 last backup, so that the next incremental backup will contain only
5060 modified files. The name of the snapshot file is given as an argument
5063 `--listed-incremental=FILE'
5065 Handle incremental backups with snapshot data in FILE.
5067 To create an incremental backup, you would use
5068 `--listed-incremental' together with `--create' (*note create::). For
5072 --file=archive.1.tar \
5073 --listed-incremental=/var/log/usr.snar \
5076 This will create in `archive.1.tar' an incremental backup of the
5077 `/usr' file system, storing additional metadata in the file
5078 `/var/log/usr.snar'. If this file does not exist, it will be created.
5079 The created archive will then be a "level 0 backup"; please see the
5080 next section for more on backup levels.
5082 Otherwise, if the file `/var/log/usr.snar' exists, it determines
5083 which files are modified. In this case only these files will be stored
5084 in the archive. Suppose, for example, that after running the above
5085 command, you delete file `/usr/doc/old' and create directory
5086 `/usr/local/db' with the following contents:
5092 Some time later you create another incremental backup. You will
5096 --file=archive.2.tar \
5097 --listed-incremental=/var/log/usr.snar \
5099 tar: usr/local/db: Directory is new
5104 The created archive `archive.2.tar' will contain only these three
5105 members. This archive is called a "level 1 backup". Notice that
5106 `/var/log/usr.snar' will be updated with the new data, so if you plan
5107 to create more `level 1' backups, it is necessary to create a working
5108 copy of the snapshot file before running `tar'. The above example will
5109 then be modified as follows:
5111 $ cp /var/log/usr.snar /var/log/usr.snar-1
5113 --file=archive.2.tar \
5114 --listed-incremental=/var/log/usr.snar-1 \
5117 You can force `level 0' backups either by removing the snapshot file
5118 before running `tar', or by supplying the `--level=0' option, e.g.:
5121 --file=archive.2.tar \
5122 --listed-incremental=/var/log/usr.snar-0 \
5126 Incremental dumps depend crucially on time stamps, so the results are
5127 unreliable if you modify a file's time stamps during dumping (e.g.,
5128 with the `--atime-preserve=replace' option), or if you set the clock
5131 Metadata stored in snapshot files include device numbers, which,
5132 obviously are supposed to be non-volatile values. However, it turns
5133 out that NFS devices have undependable values when an automounter gets
5134 in the picture. This can lead to a great deal of spurious redumping in
5135 incremental dumps, so it is somewhat useless to compare two NFS devices
5136 numbers over time. The solution implemented currently is to consider
5137 all NFS devices as being equal when it comes to comparing directories;
5138 this is fairly gross, but there does not seem to be a better way to go.
5140 Apart from using NFS, there are a number of cases where relying on
5141 device numbers can cause spurious redumping of unmodified files. For
5142 example, this occurs when archiving LVM snapshot volumes. To avoid
5143 this, use `--no-check-device' option:
5146 Do not rely on device numbers when preparing a list of changed
5147 files for an incremental dump.
5150 Use device numbers when preparing a list of changed files for an
5151 incremental dump. This is the default behavior. The purpose of
5152 this option is to undo the effect of the `--no-check-device' if it
5153 was given in `TAR_OPTIONS' environment variable (*note
5156 There is also another way to cope with changing device numbers. It
5157 is described in detail in *note Fixing Snapshot Files::.
5159 Note that incremental archives use `tar' extensions and may not be
5160 readable by non-GNU versions of the `tar' program.
5162 To extract from the incremental dumps, use `--listed-incremental'
5163 together with `--extract' option (*note extracting files::). In this
5164 case, `tar' does not need to access snapshot file, since all the data
5165 necessary for extraction are stored in the archive itself. So, when
5166 extracting, you can give whatever argument to `--listed-incremental',
5167 the usual practice is to use `--listed-incremental=/dev/null'.
5168 Alternatively, you can use `--incremental', which needs no arguments.
5169 In general, `--incremental' (`-G') can be used as a shortcut for
5170 `--listed-incremental' when listing or extracting incremental backups
5171 (for more information regarding this option, *note incremental-op::).
5173 When extracting from the incremental backup GNU `tar' attempts to
5174 restore the exact state the file system had when the archive was
5175 created. In particular, it will _delete_ those files in the file
5176 system that did not exist in their directories when the archive was
5177 created. If you have created several levels of incremental files, then
5178 in order to restore the exact contents the file system had when the
5179 last level was created, you will need to restore from all backups in
5180 turn. Continuing our example, to restore the state of `/usr' file
5181 system, one would do(1):
5184 --listed-incremental=/dev/null \
5185 --file archive.1.tar
5187 --listed-incremental=/dev/null \
5188 --file archive.2.tar
5190 To list the contents of an incremental archive, use `--list' (*note
5191 list::), as usual. To obtain more information about the archive, use
5192 `--listed-incremental' or `--incremental' combined with two `--verbose'
5195 tar --list --incremental --verbose --verbose archive.tar
5197 This command will print, for each directory in the archive, the list
5198 of files in that directory at the time the archive was created. This
5199 information is put out in a format which is both human-readable and
5200 unambiguous for a program: each file name is printed as
5204 where X is a letter describing the status of the file: `Y' if the file
5205 is present in the archive, `N' if the file is not included in the
5206 archive, or a `D' if the file is a directory (and is included in the
5207 archive). *Note Dumpdir::, for the detailed description of dumpdirs
5208 and status codes. Each such line is terminated by a newline character.
5209 The last line is followed by an additional newline to indicate the end
5212 The option `--incremental' (`-G') gives the same behavior as
5213 `--listed-incremental' when used with `--list' and `--extract' options.
5214 When used with `--create' option, it creates an incremental archive
5215 without creating snapshot file. Thus, it is impossible to create
5216 several levels of incremental backups with `--incremental' option.
5218 ---------- Footnotes ----------
5220 (1) Notice, that since both archives were created without `-P'
5221 option (*note absolute::), these commands should be run from the root
5224 (2) Two `--verbose' options were selected to avoid breaking usual
5225 verbose listing output (`--list --verbose') when using in scripts.
5227 Versions of GNU `tar' up to 1.15.1 used to dump verbatim binary
5228 contents of the DUMPDIR header (with terminating nulls) when
5229 `--incremental' or `--listed-incremental' option was given, no matter
5230 what the verbosity level. This behavior, and, especially, the binary
5231 output it produced were considered inconvenient and were changed in
5235 File: tar.info, Node: Backup Levels, Next: Backup Parameters, Prev: Incremental Dumps, Up: Backups
5237 5.3 Levels of Backups
5238 =====================
5240 An archive containing all the files in the file system is called a
5241 "full backup" or "full dump". You could insure your data by creating a
5242 full dump every day. This strategy, however, would waste a substantial
5243 amount of archive media and user time, as unchanged files are daily
5246 It is more efficient to do a full dump only occasionally. To back up
5247 files between full dumps, you can use "incremental dumps". A "level
5248 one" dump archives all the files that have changed since the last full
5251 A typical dump strategy would be to perform a full dump once a week,
5252 and a level one dump once a day. This means some versions of files
5253 will in fact be archived more than once, but this dump strategy makes
5254 it possible to restore a file system to within one day of accuracy by
5255 only extracting two archives--the last weekly (full) dump and the last
5256 daily (level one) dump. The only information lost would be in files
5257 changed or created since the last daily backup. (Doing dumps more than
5258 once a day is usually not worth the trouble.)
5260 GNU `tar' comes with scripts you can use to do full and level-one
5261 (actually, even level-two and so on) dumps. Using scripts (shell
5262 programs) to perform backups and restoration is a convenient and
5263 reliable alternative to typing out file name lists and `tar' commands
5266 Before you use these scripts, you need to edit the file
5267 `backup-specs', which specifies parameters used by the backup scripts
5268 and by the restore script. This file is usually located in
5269 `/etc/backup' directory. *Note Backup Parameters::, for its detailed
5270 description. Once the backup parameters are set, you can perform
5271 backups or restoration by running the appropriate script.
5273 The name of the backup script is `backup'. The name of the restore
5274 script is `restore'. The following sections describe their use in
5277 _Please Note:_ The backup and restoration scripts are designed to be
5278 used together. While it is possible to restore files by hand from an
5279 archive which was created using a backup script, and to create an
5280 archive by hand which could then be extracted using the restore script,
5281 it is easier to use the scripts. *Note Incremental Dumps::, before
5282 making such an attempt.
5285 File: tar.info, Node: Backup Parameters, Next: Scripted Backups, Prev: Backup Levels, Up: Backups
5287 5.4 Setting Parameters for Backups and Restoration
5288 ==================================================
5290 The file `backup-specs' specifies backup parameters for the backup and
5291 restoration scripts provided with `tar'. You must edit `backup-specs'
5292 to fit your system configuration and schedule before using these
5295 Syntactically, `backup-specs' is a shell script, containing mainly
5296 variable assignments. However, any valid shell construct is allowed in
5297 this file. Particularly, you may wish to define functions within that
5298 script (e.g., see `RESTORE_BEGIN' below). For more information about
5299 shell script syntax, please refer to the definition of the Shell
5301 (http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5302 g_02). See also *note Bash Features: (bashref)Top.
5304 The shell variables controlling behavior of `backup' and `restore'
5305 are described in the following subsections.
5309 * General-Purpose Variables::
5310 * Magnetic Tape Control::
5312 * backup-specs example:: An Example Text of `Backup-specs'
5315 File: tar.info, Node: General-Purpose Variables, Next: Magnetic Tape Control, Up: Backup Parameters
5317 5.4.1 General-Purpose Variables
5318 -------------------------------
5320 -- Backup variable: ADMINISTRATOR
5321 The user name of the backup administrator. `Backup' scripts sends
5322 a backup report to this address.
5324 -- Backup variable: BACKUP_HOUR
5325 The hour at which the backups are done. This can be a number from
5326 0 to 23, or the time specification in form HOURS:MINUTES, or the
5329 This variable is used by `backup'. Its value may be overridden
5330 using `--time' option (*note Scripted Backups::).
5332 -- Backup variable: TAPE_FILE
5333 The device `tar' writes the archive to. If TAPE_FILE is a remote
5334 archive (*note remote-dev::), backup script will suppose that your
5335 `mt' is able to access remote devices. If RSH (*note RSH::) is
5336 set, `--rsh-command' option will be added to invocations of `mt'.
5338 -- Backup variable: BLOCKING
5339 The blocking factor `tar' will use when writing the dump archive.
5340 *Note Blocking Factor::.
5342 -- Backup variable: BACKUP_DIRS
5343 A list of file systems to be dumped (for `backup'), or restored
5344 (for `restore'). You can include any directory name in the list
5345 -- subdirectories on that file system will be included, regardless
5346 of how they may look to other networked machines. Subdirectories
5347 on other file systems will be ignored.
5349 The host name specifies which host to run `tar' on, and should
5350 normally be the host that actually contains the file system.
5351 However, the host machine must have GNU `tar' installed, and must
5352 be able to access the directory containing the backup scripts and
5353 their support files using the same file name that is used on the
5354 machine where the scripts are run (i.e., what `pwd' will print
5355 when in that directory on that machine). If the host that contains
5356 the file system does not have this capability, you can specify
5357 another host as long as it can access the file system through NFS.
5359 If the list of file systems is very long you may wish to put it in
5360 a separate file. This file is usually named `/etc/backup/dirs',
5361 but this name may be overridden in `backup-specs' using `DIRLIST'
5364 -- Backup variable: DIRLIST
5365 The name of the file that contains a list of file systems to backup
5366 or restore. By default it is `/etc/backup/dirs'.
5368 -- Backup variable: BACKUP_FILES
5369 A list of individual files to be dumped (for `backup'), or restored
5370 (for `restore'). These should be accessible from the machine on
5371 which the backup script is run.
5373 If the list of individual files is very long you may wish to store
5374 it in a separate file. This file is usually named
5375 `/etc/backup/files', but this name may be overridden in
5376 `backup-specs' using `FILELIST' variable.
5378 -- Backup variable: FILELIST
5379 The name of the file that contains a list of individual files to
5380 backup or restore. By default it is `/etc/backup/files'.
5382 -- Backup variable: MT
5383 Full file name of `mt' binary.
5385 -- Backup variable: RSH
5386 Full file name of `rsh' binary or its equivalent. You may wish to
5387 set it to `ssh', to improve security. In this case you will have
5388 to use public key authentication.
5390 -- Backup variable: RSH_COMMAND
5391 Full file name of `rsh' binary on remote machines. This will be
5392 passed via `--rsh-command' option to the remote invocation of GNU
5395 -- Backup variable: VOLNO_FILE
5396 Name of temporary file to hold volume numbers. This needs to be
5397 accessible by all the machines which have file systems to be
5400 -- Backup variable: XLIST
5401 Name of "exclude file list". An "exclude file list" is a file
5402 located on the remote machine and containing the list of files to
5403 be excluded from the backup. Exclude file lists are searched in
5404 /etc/tar-backup directory. A common use for exclude file lists is
5405 to exclude files containing security-sensitive information (e.g.,
5406 `/etc/shadow' from backups).
5408 This variable affects only `backup'.
5410 -- Backup variable: SLEEP_TIME
5411 Time to sleep between dumps of any two successive file systems
5413 This variable affects only `backup'.
5415 -- Backup variable: DUMP_REMIND_SCRIPT
5416 Script to be run when it's time to insert a new tape in for the
5417 next volume. Administrators may want to tailor this script for
5418 their site. If this variable isn't set, GNU `tar' will display
5419 its built-in prompt, and will expect confirmation from the
5420 console. For the description of the default prompt, see *note
5421 change volume prompt::.
5424 -- Backup variable: SLEEP_MESSAGE
5425 Message to display on the terminal while waiting for dump time.
5426 Usually this will just be some literal text.
5428 -- Backup variable: TAR
5429 Full file name of the GNU `tar' executable. If this is not set,
5430 backup scripts will search `tar' in the current shell path.
5433 File: tar.info, Node: Magnetic Tape Control, Next: User Hooks, Prev: General-Purpose Variables, Up: Backup Parameters
5435 5.4.2 Magnetic Tape Control
5436 ---------------------------
5438 Backup scripts access tape device using special "hook functions".
5439 These functions take a single argument -- the name of the tape device.
5440 Their names are kept in the following variables:
5442 -- Backup variable: MT_BEGIN
5443 The name of "begin" function. This function is called before
5444 accessing the drive. By default it retensions the tape:
5449 mt -f "$1" retension
5452 -- Backup variable: MT_REWIND
5453 The name of "rewind" function. The default definition is as
5463 -- Backup variable: MT_OFFLINE
5464 The name of the function switching the tape off line. By default
5465 it is defined as follows:
5467 MT_OFFLINE=mt_offline
5473 -- Backup variable: MT_STATUS
5474 The name of the function used to obtain the status of the archive
5475 device, including error count. Default definition:
5484 File: tar.info, Node: User Hooks, Next: backup-specs example, Prev: Magnetic Tape Control, Up: Backup Parameters
5489 "User hooks" are shell functions executed before and after each `tar'
5490 invocation. Thus, there are "backup hooks", which are executed before
5491 and after dumping each file system, and "restore hooks", executed
5492 before and after restoring a file system. Each user hook is a shell
5493 function taking four arguments:
5495 -- User Hook Function: hook LEVEL HOST FS FSNAME
5499 Current backup or restore level.
5502 Name or IP address of the host machine being dumped or
5506 Full file name of the file system being dumped or restored.
5509 File system name with directory separators replaced with
5510 colons. This is useful, e.g., for creating unique files.
5512 Following variables keep the names of user hook functions:
5514 -- Backup variable: DUMP_BEGIN
5515 Dump begin function. It is executed before dumping the file
5518 -- Backup variable: DUMP_END
5519 Executed after dumping the file system.
5521 -- Backup variable: RESTORE_BEGIN
5522 Executed before restoring the file system.
5524 -- Backup variable: RESTORE_END
5525 Executed after restoring the file system.
5528 File: tar.info, Node: backup-specs example, Prev: User Hooks, Up: Backup Parameters
5530 5.4.4 An Example Text of `Backup-specs'
5531 ---------------------------------------
5533 The following is an example of `backup-specs':
5535 # site-specific parameters for file system backup.
5537 ADMINISTRATOR=friedman
5539 TAPE_FILE=/dev/nrsmt0
5541 # Use `ssh' instead of the less secure `rsh'
5543 RSH_COMMAND=/usr/bin/ssh
5545 # Override MT_STATUS function:
5551 # Disable MT_OFFLINE function
5568 apple-gunkies:/com/mailer/gnu
5569 apple-gunkies:/com/archive/gnu"
5571 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5574 File: tar.info, Node: Scripted Backups, Next: Scripted Restoration, Prev: Backup Parameters, Up: Backups
5576 5.5 Using the Backup Scripts
5577 ============================
5579 The syntax for running a backup script is:
5581 backup --level=LEVEL --time=TIME
5583 The `--level' option requests the dump level. Thus, to produce a
5584 full dump, specify `--level=0' (this is the default, so `--level' may
5585 be omitted if its value is `0')(1).
5587 The `--time' option determines when should the backup be run. TIME
5588 may take three forms:
5591 The dump must be run at HH hours MM minutes.
5594 The dump must be run at HH hours.
5597 The dump must be run immediately.
5599 You should start a script with a tape or disk mounted. Once you
5600 start a script, it prompts you for new tapes or disks as it needs them.
5601 Media volumes don't have to correspond to archive files -- a
5602 multi-volume archive can be started in the middle of a tape that
5603 already contains the end of another multi-volume archive. The
5604 `restore' script prompts for media by its archive volume, so to avoid
5605 an error message you should keep track of which tape (or disk) contains
5606 which volume of the archive (*note Scripted Restoration::).
5608 The backup scripts write two files on the file system. The first is
5609 a record file in `/etc/tar-backup/', which is used by the scripts to
5610 store and retrieve information about which files were dumped. This
5611 file is not meant to be read by humans, and should not be deleted by
5612 them. *Note Snapshot Files::, for a more detailed explanation of this
5615 The second file is a log file containing the names of the file
5616 systems and files dumped, what time the backup was made, and any error
5617 messages that were generated, as well as how much space was left in the
5618 media volume after the last volume of the archive was written. You
5619 should check this log file after every backup. The file name is
5620 `log-MM-DD-YYYY-level-N', where MM-DD-YYYY represents current date, and
5621 N represents current dump level number.
5623 The script also prints the name of each system being dumped to the
5626 Following is the full list of options accepted by `backup' script:
5630 Do backup level LEVEL (default 0).
5634 Force backup even if today's log file already exists.
5638 Set verbosity level. The higher the level is, the more debugging
5639 information will be output during execution. Default LEVEL is
5640 100, which means the highest debugging level.
5644 Wait till TIME, then do backup.
5648 Display short help message and exit.
5652 Display information about the program's name, version, origin and
5653 legal status, all on standard output, and then exit successfully.
5655 ---------- Footnotes ----------
5657 (1) For backward compatibility, the `backup' will also try to deduce
5658 the requested dump level from the name of the script itself. If the
5659 name consists of a string `level-' followed by a single decimal digit,
5660 that digit is taken as the dump level number. Thus, you may create a
5661 link from `backup' to `level-1' and then run `level-1' whenever you
5662 need to create a level one dump.
5665 File: tar.info, Node: Scripted Restoration, Prev: Scripted Backups, Up: Backups
5667 5.6 Using the Restore Script
5668 ============================
5670 To restore files that were archived using a scripted backup, use the
5671 `restore' script. Its usage is quite straightforward. In the simplest
5672 form, invoke `restore --all', it will then restore all the file systems
5673 and files specified in `backup-specs' (*note BACKUP_DIRS:
5674 General-Purpose Variables.).
5676 You may select the file systems (and/or files) to restore by giving
5677 `restore' a list of "patterns" in its command line. For example,
5682 will restore all file systems on the machine `albert'. A more
5683 complicated example:
5685 restore 'albert:*' '*:/var'
5687 This command will restore all file systems on the machine `albert' as
5688 well as `/var' file system on all machines.
5690 By default `restore' will start restoring files from the lowest
5691 available dump level (usually zero) and will continue through all
5692 available dump levels. There may be situations where such a thorough
5693 restore is not necessary. For example, you may wish to restore only
5694 files from the recent level one backup. To do so, use `--level'
5695 option, as shown in the example below:
5699 The full list of options accepted by `restore' follows:
5703 Restore all file systems and files specified in `backup-specs'.
5707 Start restoring from the given backup level, instead of the
5712 Set verbosity level. The higher the level is, the more debugging
5713 information will be output during execution. Default LEVEL is
5714 100, which means the highest debugging level.
5718 Display short help message and exit.
5722 Display information about the program's name, version, origin and
5723 legal status, all on standard output, and then exit successfully.
5725 You should start the restore script with the media containing the
5726 first volume of the archive mounted. The script will prompt for other
5727 volumes as they are needed. If the archive is on tape, you don't need
5728 to rewind the tape to to its beginning--if the tape head is positioned
5729 past the beginning of the archive, the script will rewind the tape as
5730 needed. *Note Tape Positioning::, for a discussion of tape positioning.
5732 *Warning:* The script will delete files from the active file
5733 system if they were not in the file system when the archive was
5736 *Note Incremental Dumps::, for an explanation of how the script makes
5740 File: tar.info, Node: Choosing, Next: Date input formats, Prev: Backups, Up: Top
5742 6 Choosing Files and Names for `tar'
5743 ************************************
5745 Certain options to `tar' enable you to specify a name for your archive.
5746 Other options let you decide which files to include or exclude from the
5747 archive, based on when or whether files were modified, whether the file
5748 names do or don't match specified patterns, or whether files are in
5749 specified directories.
5751 This chapter discusses these options in detail.
5755 * file:: Choosing the Archive's Name
5756 * Selecting Archive Members::
5757 * files:: Reading Names from a File
5758 * exclude:: Excluding Some Files
5759 * wildcards:: Wildcards Patterns and Matching
5760 * quoting styles:: Ways of Quoting Special Characters in Names
5761 * transform:: Modifying File and Member Names
5762 * after:: Operating Only on New Files
5763 * recurse:: Descending into Directories
5764 * one:: Crossing File System Boundaries
5767 File: tar.info, Node: file, Next: Selecting Archive Members, Up: Choosing
5769 6.1 Choosing and Naming Archive Files
5770 =====================================
5772 By default, `tar' uses an archive file name that was compiled when it
5773 was built on the system; usually this name refers to some physical tape
5774 drive on the machine. However, the person who installed `tar' on the
5775 system may not have set the default to a meaningful value as far as
5776 most users are concerned. As a result, you will usually want to tell
5777 `tar' where to find (or create) the archive. The `--file=ARCHIVE-NAME'
5778 (`-f ARCHIVE-NAME') option allows you to either specify or name a file
5779 to use as the archive instead of the default archive file location.
5781 `--file=ARCHIVE-NAME'
5783 Name the archive to create or operate on. Use in conjunction with
5786 For example, in this `tar' command,
5788 $ tar -cvf collection.tar blues folk jazz
5790 `collection.tar' is the name of the archive. It must directly follow
5791 the `-f' option, since whatever directly follows `-f' _will_ end up
5792 naming the archive. If you neglect to specify an archive name, you may
5793 end up overwriting a file in the working directory with the archive you
5794 create since `tar' will use this file's name for the archive name.
5796 An archive can be saved as a file in the file system, sent through a
5797 pipe or over a network, or written to an I/O device such as a tape,
5798 floppy disk, or CD write drive.
5800 If you do not name the archive, `tar' uses the value of the
5801 environment variable `TAPE' as the file name for the archive. If that
5802 is not available, `tar' uses a default, compiled-in archive name,
5803 usually that for tape unit zero (i.e., `/dev/tu00').
5805 If you use `-' as an ARCHIVE-NAME, `tar' reads the archive from
5806 standard input (when listing or extracting files), or writes it to
5807 standard output (when creating an archive). If you use `-' as an
5808 ARCHIVE-NAME when modifying an archive, `tar' reads the original
5809 archive from its standard input and writes the entire new archive to
5810 its standard output.
5812 The following example is a convenient way of copying directory
5813 hierarchy from `sourcedir' to `targetdir'.
5815 $ (cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)
5817 The `-C' option allows to avoid using subshells:
5819 $ tar -C sourcedir -cf - . | tar -C targetdir -xpf -
5821 In both examples above, the leftmost `tar' invocation archives the
5822 contents of `sourcedir' to the standard output, while the rightmost one
5823 reads this archive from its standard input and extracts it. The `-p'
5824 option tells it to restore permissions of the extracted files.
5826 To specify an archive file on a device attached to a remote machine,
5829 --file=HOSTNAME:/DEV/FILE-NAME
5831 `tar' will set up the remote connection, if possible, and prompt you
5832 for a username and password. If you use
5833 `--file=@HOSTNAME:/DEV/FILE-NAME', `tar' will attempt to set up the
5834 remote connection using your username as the username on the remote
5837 If the archive file name includes a colon (`:'), then it is assumed
5838 to be a file on another machine. If the archive file is
5839 `USER@HOST:FILE', then FILE is used on the host HOST. The remote host
5840 is accessed using the `rsh' program, with a username of USER. If the
5841 username is omitted (along with the `@' sign), then your user name will
5842 be used. (This is the normal `rsh' behavior.) It is necessary for the
5843 remote machine, in addition to permitting your `rsh' access, to have
5844 the `rmt' program installed (this command is included in the GNU `tar'
5845 distribution and by default is installed under `PREFIX/libexec/rmt',
5846 where PREFIX means your installation prefix). If you need to use a
5847 file whose name includes a colon, then the remote tape drive behavior
5848 can be inhibited by using the `--force-local' option.
5850 When the archive is being created to `/dev/null', GNU `tar' tries to
5851 minimize input and output operations. The Amanda backup system, when
5852 used with GNU `tar', has an initial sizing pass which uses this feature.
5855 File: tar.info, Node: Selecting Archive Members, Next: files, Prev: file, Up: Choosing
5857 6.2 Selecting Archive Members
5858 =============================
5860 "File Name arguments" specify which files in the file system `tar'
5861 operates on, when creating or adding to an archive, or which archive
5862 members `tar' operates on, when reading or deleting from an archive.
5865 To specify file names, you can include them as the last arguments on
5866 the command line, as follows:
5867 tar OPERATION [OPTION1 OPTION2 ...] [FILE NAME-1 FILE NAME-2 ...]
5869 If a file name begins with dash (`-'), precede it with `--add-file'
5870 option to prevent it from being treated as an option.
5872 By default GNU `tar' attempts to "unquote" each file or member name,
5873 replacing "escape sequences" according to the following table:
5875 Escape Replaced with
5876 -----------------------------------------------------------
5877 \a Audible bell (ASCII 7)
5878 \b Backspace (ASCII 8)
5879 \f Form feed (ASCII 12)
5880 \n New line (ASCII 10)
5881 \r Carriage return (ASCII 13)
5882 \t Horizontal tabulation (ASCII 9)
5883 \v Vertical tabulation (ASCII 11)
5885 \N ASCII N (N should be an octal number
5888 A backslash followed by any other symbol is retained.
5890 This default behavior is controlled by the following command line
5894 Enable unquoting input file or member names (default).
5897 Disable unquoting input file or member names.
5899 If you specify a directory name as a file name argument, all the
5900 files in that directory are operated on by `tar'.
5902 If you do not specify files, `tar' behavior differs depending on the
5903 operation mode as described below:
5905 When `tar' is invoked with `--create' (`-c'), `tar' will stop
5906 immediately, reporting the following:
5909 tar: Cowardly refusing to create an empty archive
5910 Try `tar --help' or `tar --usage' for more information.
5912 If you specify either `--list' (`-t') or `--extract' (`--get',
5913 `-x'), `tar' operates on all the archive members in the archive.
5915 If run with `--diff' option, tar will compare the archive with the
5916 contents of the current working directory.
5918 If you specify any other operation, `tar' does nothing.
5920 By default, `tar' takes file names from the command line. However,
5921 there are other ways to specify file or member names, or to modify the
5922 manner in which `tar' selects the files or members upon which to
5923 operate. In general, these methods work both for specifying the names
5924 of files and archive members.
5927 File: tar.info, Node: files, Next: exclude, Prev: Selecting Archive Members, Up: Choosing
5929 6.3 Reading Names from a File
5930 =============================
5932 Instead of giving the names of files or archive members on the command
5933 line, you can put the names into a file, and then use the
5934 `--files-from=FILE-OF-NAMES' (`-T FILE-OF-NAMES') option to `tar'.
5935 Give the name of the file which contains the list of files to include
5936 as the argument to `--files-from'. In the list, the file names should
5937 be separated by newlines. You will frequently use this option when you
5938 have generated the list of files to archive with the `find' utility.
5940 `--files-from=FILE-NAME'
5942 Get names to extract or create from file FILE-NAME.
5944 If you give a single dash as a file name for `--files-from', (i.e.,
5945 you specify either `--files-from=-' or `-T -'), then the file names are
5946 read from standard input.
5948 Unless you are running `tar' with `--create', you can not use both
5949 `--files-from=-' and `--file=-' (`-f -') in the same command.
5951 Any number of `-T' options can be given in the command line.
5953 The following example shows how to use `find' to generate a list of
5954 files smaller than 400K in length and put that list into a file called
5955 `small-files'. You can then use the `-T' option to `tar' to specify
5956 the files from that file, `small-files', to create the archive
5957 `little.tgz'. (The `-z' option to `tar' compresses the archive with
5958 `gzip'; *note gzip:: for more information.)
5960 $ find . -size -400 -print > small-files
5961 $ tar -c -v -z -T small-files -f little.tgz
5963 In the file list given by `-T' option, any file name beginning with `-'
5964 character is considered a `tar' option and is processed accordingly(1).
5965 For example, the common use of this feature is to change to another
5966 directory by specifying `-C' option:
5974 $ tar -c -f foo.tar --files-from list
5976 In this example, `tar' will first switch to `/etc' directory and add
5977 files `passwd' and `hosts' to the archive. Then it will change to
5978 `/lib' directory and will archive the file `libc.a'. Thus, the
5979 resulting archive `foo.tar' will contain:
5987 Notice that the option parsing algorithm used with `-T' is stricter
5988 than the one used by shell. Namely, when specifying option arguments,
5989 you should observe the following rules:
5991 * When using short (single-letter) option form, its argument must
5992 immediately follow the option letter, without any intervening
5993 whitespace. For example: `-Cdir'.
5995 * When using long option form, the option argument must be separated
5996 from the option by a single equal sign. No whitespace is allowed
5997 on any side of the equal sign. For example: `--directory=dir'.
5999 * For both short and long option forms, the option argument can be
6000 given on the next line after the option name, e.g.:
6010 If you happen to have a file whose name starts with `-', precede it
6011 with `--add-file' option to prevent it from being recognized as an
6012 option. For example: `--add-file=--my-file'.
6018 ---------- Footnotes ----------
6020 (1) Versions of GNU `tar' up to 1.15.1 recognized only `-C' option
6021 in file lists, and only if the option and its argument occupied two
6025 File: tar.info, Node: nul, Up: files
6027 6.3.1 `NUL'-Terminated File Names
6028 ---------------------------------
6030 The `--null' option causes `--files-from=FILE-OF-NAMES' (`-T
6031 FILE-OF-NAMES') to read file names terminated by a `NUL' instead of a
6032 newline, so files whose names contain newlines can be archived using
6036 Only consider `NUL'-terminated file names, instead of files that
6037 terminate in a newline.
6040 Undo the effect of any previous `--null' option.
6042 The `--null' option is just like the one in GNU `xargs' and `cpio',
6043 and is useful with the `-print0' predicate of GNU `find'. In `tar',
6044 `--null' also disables special handling for file names that begin with
6047 This example shows how to use `find' to generate a list of files
6048 larger than 800K in length and put that list into a file called
6049 `long-files'. The `-print0' option to `find' is just like `-print',
6050 except that it separates files with a `NUL' rather than with a newline.
6051 You can then run `tar' with both the `--null' and `-T' options to
6052 specify that `tar' gets the files from that file, `long-files', to
6053 create the archive `big.tgz'. The `--null' option to `tar' will cause
6054 `tar' to recognize the `NUL' separator between files.
6056 $ find . -size +800 -print0 > long-files
6057 $ tar -c -v --null --files-from=long-files --file=big.tar
6059 The `--no-null' option can be used if you need to read both
6060 `NUL'-terminated and newline-terminated files on the same command line.
6061 For example, if `flist' is a newline-terminated file, then the
6062 following command can be used to combine it with the above command:
6064 $ find . -size +800 -print0 |
6065 tar -c -f big.tar --null -T - --no-null -T flist
6067 This example uses short options for typographic reasons, to avoid
6070 GNU `tar' is able to automatically detect `NUL'-terminated file
6071 lists, so it is safe to use them even without the `--null' option. In
6072 this case `tar' will print a warning and continue reading such a file
6073 as if `--null' were actually given:
6075 $ find . -size +800 -print0 | tar -c -f big.tar -T -
6076 tar: -: file name read contains nul character
6078 The null terminator, however, remains in effect only for this
6079 particular file, any following `-T' options will assume newline
6080 termination. Of course, the null autodetection applies to these
6081 eventual surplus `-T' options as well.
6084 File: tar.info, Node: exclude, Next: wildcards, Prev: files, Up: Choosing
6086 6.4 Excluding Some Files
6087 ========================
6089 To avoid operating on files whose names match a particular pattern, use
6090 the `--exclude' or `--exclude-from' options.
6093 Causes `tar' to ignore files that match the PATTERN.
6095 The `--exclude=PATTERN' option prevents any file or member whose
6096 name matches the shell wildcard (PATTERN) from being operated on. For
6097 example, to create an archive with all the contents of the directory
6098 `src' except for files whose names end in `.o', use the command `tar
6099 -cf src.tar --exclude='*.o' src'.
6101 You may give multiple `--exclude' options.
6103 `--exclude-from=FILE'
6105 Causes `tar' to ignore files that match the patterns listed in
6108 Use the `--exclude-from' option to read a list of patterns, one per
6109 line, from FILE; `tar' will ignore files matching those patterns. Thus
6110 if `tar' is called as `tar -c -X foo .' and the file `foo' contains a
6111 single line `*.o', no files whose names end in `.o' will be added to
6114 Notice, that lines from FILE are read verbatim. One of the frequent
6115 errors is leaving some extra whitespace after a file name, which is
6116 difficult to catch using text editors.
6118 However, empty lines are OK.
6121 Exclude files and directories used by following version control
6122 systems: `CVS', `RCS', `SCCS', `SVN', `Arch', `Bazaar',
6123 `Mercurial', and `Darcs'.
6125 As of version 1.26, the following files are excluded:
6127 * `CVS/', and everything under it
6129 * `RCS/', and everything under it
6131 * `SCCS/', and everything under it
6133 * `.git/', and everything under it
6139 * `.svn/', and everything under it
6141 * `.arch-ids/', and everything under it
6143 * `{arch}/', and everything under it
6166 Exclude backup and lock files. This option causes exclusion of
6167 files that match the following shell globbing patterns:
6176 When creating an archive, the `--exclude-caches' option family
6177 causes `tar' to exclude all directories that contain a "cache directory
6178 tag". A cache directory tag is a short file with the well-known name
6179 `CACHEDIR.TAG' and having a standard header specified in
6180 `http://www.brynosaurus.com/cachedir/spec.html'. Various applications
6181 write cache directory tags into directories they use to hold
6182 regenerable, non-precious data, so that such data can be more easily
6183 excluded from backups.
6185 There are three `exclude-caches' options, each providing a different
6186 exclusion semantics:
6189 Do not archive the contents of the directory, but archive the
6190 directory itself and the `CACHEDIR.TAG' file.
6192 `--exclude-caches-under'
6193 Do not archive the contents of the directory, nor the
6194 `CACHEDIR.TAG' file, archive only the directory itself.
6196 `--exclude-caches-all'
6197 Omit directories containing `CACHEDIR.TAG' file entirely.
6199 Another option family, `--exclude-tag', provides a generalization of
6200 this concept. It takes a single argument, a file name to look for.
6201 Any directory that contains this file will be excluded from the dump.
6202 Similarly to `exclude-caches', there are three options in this option
6205 `--exclude-tag=FILE'
6206 Do not dump the contents of the directory, but dump the directory
6207 itself and the FILE.
6209 `--exclude-tag-under=FILE'
6210 Do not dump the contents of the directory, nor the FILE, archive
6211 only the directory itself.
6213 `--exclude-tag-all=FILE'
6214 Omit directories containing FILE file entirely.
6216 Multiple `--exclude-tag*' options can be given.
6218 For example, given this directory:
6229 The `--exclude-tag' will produce the following:
6231 $ tar -cf archive.tar --exclude-tag=tagfile -v dir
6236 tar: dir/folk/: contains a cache directory tag tagfile;
6240 Both the `dir/folk' directory and its tagfile are preserved in the
6241 archive, however the rest of files in this directory are not.
6243 Now, using the `--exclude-tag-under' option will exclude `tagfile'
6244 from the dump, while still preserving the directory itself, as shown in
6247 $ tar -cf archive.tar --exclude-tag-under=tagfile -v dir
6252 ./tar: dir/folk/: contains a cache directory tag tagfile;
6255 Finally, using `--exclude-tag-all' omits the `dir/folk' directory
6258 $ tar -cf archive.tar --exclude-tag-all=tagfile -v dir
6262 ./tar: dir/folk/: contains a cache directory tag tagfile;
6263 directory not dumped
6267 * problems with exclude::
6270 File: tar.info, Node: problems with exclude, Up: exclude
6272 Problems with Using the `exclude' Options
6273 -----------------------------------------
6275 Some users find `exclude' options confusing. Here are some common
6278 * The main operating mode of `tar' does not act on a file name
6279 explicitly listed on the command line, if one of its file name
6280 components is excluded. In the example above, if you create an
6281 archive and exclude files that end with `*.o', but explicitly name
6282 the file `dir.o/foo' after all the options have been listed,
6283 `dir.o/foo' will be excluded from the archive.
6285 * You can sometimes confuse the meanings of `--exclude' and
6286 `--exclude-from'. Be careful: use `--exclude' when files to be
6287 excluded are given as a pattern on the command line. Use
6288 `--exclude-from' to introduce the name of a file which contains a
6289 list of patterns, one per line; each of these patterns can exclude
6290 zero, one, or many files.
6292 * When you use `--exclude=PATTERN', be sure to quote the PATTERN
6293 parameter, so GNU `tar' sees wildcard characters like `*'. If you
6294 do not do this, the shell might expand the `*' itself using files
6295 at hand, so `tar' might receive a list of files instead of one
6296 pattern, or none at all, making the command somewhat illegal.
6297 This might not correspond to what you want.
6301 $ tar -c -f ARCHIVE.TAR --exclude '*.o' DIRECTORY
6306 $ tar -c -f ARCHIVE.TAR --exclude *.o DIRECTORY
6308 * You must use use shell syntax, or globbing, rather than `regexp'
6309 syntax, when using exclude options in `tar'. If you try to use
6310 `regexp' syntax to describe files to be excluded, your command
6313 * In earlier versions of `tar', what is now the `--exclude-from'
6314 option was called `--exclude' instead. Now, `--exclude' applies
6315 to patterns listed on the command line and `--exclude-from'
6316 applies to patterns listed in a file.
6320 File: tar.info, Node: wildcards, Next: quoting styles, Prev: exclude, Up: Choosing
6322 6.5 Wildcards Patterns and Matching
6323 ===================================
6325 "Globbing" is the operation by which "wildcard" characters, `*' or `?'
6326 for example, are replaced and expanded into all existing files matching
6327 the given pattern. GNU `tar' can use wildcard patterns for matching
6328 (or globbing) archive members when extracting from or listing an
6329 archive. Wildcard patterns are also used for verifying volume labels
6330 of `tar' archives. This section has the purpose of explaining wildcard
6333 A PATTERN should be written according to shell syntax, using wildcard
6334 characters to effect globbing. Most characters in the pattern stand
6335 for themselves in the matched string, and case is significant: `a' will
6336 match only `a', and not `A'. The character `?' in the pattern matches
6337 any single character in the matched string. The character `*' in the
6338 pattern matches zero, one, or more single characters in the matched
6339 string. The character `\' says to take the following character of the
6340 pattern _literally_; it is useful when one needs to match the `?', `*',
6341 `[' or `\' characters, themselves.
6343 The character `[', up to the matching `]', introduces a character
6344 class. A "character class" is a list of acceptable characters for the
6345 next single character of the matched string. For example, `[abcde]'
6346 would match any of the first five letters of the alphabet. Note that
6347 within a character class, all of the "special characters" listed above
6348 other than `\' lose their special meaning; for example, `[-\\[*?]]'
6349 would match any of the characters, `-', `\', `[', `*', `?', or `]'.
6350 (Due to parsing constraints, the characters `-' and `]' must either
6351 come _first_ or _last_ in a character class.)
6353 If the first character of the class after the opening `[' is `!' or
6354 `^', then the meaning of the class is reversed. Rather than listing
6355 character to match, it lists those characters which are _forbidden_ as
6356 the next single character of the matched string.
6358 Other characters of the class stand for themselves. The special
6359 construction `[A-E]', using an hyphen between two letters, is meant to
6360 represent all characters between A and E, inclusive.
6362 Periods (`.') or forward slashes (`/') are not considered special
6363 for wildcard matches. However, if a pattern completely matches a
6364 directory prefix of a matched string, then it matches the full matched
6365 string: thus, excluding a directory also excludes all the files beneath
6370 * controlling pattern-matching::
6373 File: tar.info, Node: controlling pattern-matching, Up: wildcards
6375 Controlling Pattern-Matching
6376 ----------------------------
6378 For the purposes of this section, we call "exclusion members" all
6379 member names obtained while processing `--exclude' and `--exclude-from'
6380 options, and "inclusion members" those member names that were given in
6381 the command line or read from the file specified with `--files-from'
6384 These two pairs of member lists are used in the following operations:
6385 `--diff', `--extract', `--list', `--update'.
6387 There are no inclusion members in create mode (`--create' and
6388 `--append'), since in this mode the names obtained from the command
6389 line refer to _files_, not archive members.
6391 By default, inclusion members are compared with archive members
6392 literally (1) and exclusion members are treated as globbing patterns.
6400 # Member names are used verbatim:
6401 $ tar -xf foo.tar -v '[remarks]'
6403 # Exclude member names are globbed:
6404 $ tar -xf foo.tar -v --exclude '*.c'
6408 This behavior can be altered by using the following options:
6411 Treat all member names as wildcards.
6414 Treat all member names as literal strings.
6416 Thus, to extract files whose names end in `.c', you can use:
6418 $ tar -xf foo.tar -v --wildcards '*.c'
6422 Notice quoting of the pattern to prevent the shell from interpreting it.
6424 The effect of `--wildcards' option is canceled by `--no-wildcards'.
6425 This can be used to pass part of the command line arguments verbatim
6426 and other part as globbing patterns. For example, the following
6429 $ tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'
6431 instructs `tar' to extract from `foo.tar' all files whose names end in
6432 `.txt' and the file named `[remarks]'.
6434 Normally, a pattern matches a name if an initial subsequence of the
6435 name's components matches the pattern, where `*', `?', and `[...]' are
6436 the usual shell wildcards, `\' escapes wildcards, and wildcards can
6439 Other than optionally stripping leading `/' from names (*note
6440 absolute::), patterns and names are used as-is. For example, trailing
6441 `/' is not trimmed from a user-specified name before deciding whether
6444 However, this matching procedure can be altered by the options listed
6445 below. These options accumulate. For example:
6447 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6449 ignores case when excluding `makefile', but not when excluding `readme'.
6453 If anchored, a pattern must match an initial subsequence of the
6454 name's components. Otherwise, the pattern can match any
6455 subsequence. Default is `--no-anchored' for exclusion members and
6456 `--anchored' inclusion members.
6460 When ignoring case, upper-case patterns match lower-case names and
6461 vice versa. When not ignoring case (the default), matching is
6464 `--wildcards-match-slash'
6465 `--no-wildcards-match-slash'
6466 When wildcards match slash (the default for exclusion members), a
6467 wildcard like `*' in the pattern can match a `/' in the name.
6468 Otherwise, `/' is matched only by `/'.
6471 The `--recursion' and `--no-recursion' options (*note recurse::)
6472 also affect how member patterns are interpreted. If recursion is in
6473 effect, a pattern matches a name if it matches any of the name's parent
6476 The following table summarizes pattern-matching default values:
6478 Members Default settings
6479 --------------------------------------------------------------------------
6480 Inclusion `--no-wildcards --anchored
6481 --no-wildcards-match-slash'
6482 Exclusion `--wildcards --no-anchored
6483 --wildcards-match-slash'
6485 ---------- Footnotes ----------
6487 (1) Notice that earlier GNU `tar' versions used globbing for
6488 inclusion members, which contradicted to UNIX98 specification and was
6489 not documented. *Note Changes::, for more information on this and other
6493 File: tar.info, Node: quoting styles, Next: transform, Prev: wildcards, Up: Choosing
6495 6.6 Quoting Member Names
6496 ========================
6498 When displaying member names, `tar' takes care to avoid ambiguities
6499 caused by certain characters. This is called "name quoting". The
6500 characters in question are:
6502 * Non-printable control characters:
6503 Character ASCII Character name
6504 ---------------------------------------------------------------
6509 \r 13 Carriage return
6510 \t 9 Horizontal tabulation
6511 \v 11 Vertical tabulation
6515 * Single and double quotes (`'' and `"')
6519 The exact way `tar' uses to quote these characters depends on the
6520 "quoting style". The default quoting style, called "escape" (see
6521 below), uses backslash notation to represent control characters, space
6522 and backslash. Using this quoting style, control characters are
6523 represented as listed in column `Character' in the above table, a space
6524 is printed as `\ ' and a backslash as `\\'.
6526 GNU `tar' offers seven distinct quoting styles, which can be selected
6527 using `--quoting-style' option:
6529 `--quoting-style=STYLE'
6530 Sets quoting style. Valid values for STYLE argument are: literal,
6531 shell, shell-always, c, escape, locale, clocale.
6533 These styles are described in detail below. To illustrate their
6534 effect, we will use an imaginary tar archive `arch.tar' containing the
6537 # 1. Contains horizontal tabulation character.
6539 # 2. Contains newline character
6542 # 3. Contains a space
6544 # 4. Contains double quotes
6546 # 5. Contains single quotes
6548 # 6. Contains a backslash character:
6551 Here is how usual `ls' command would have listed them, if they had
6552 existed in the current working directory:
6565 No quoting, display each character as is:
6567 $ tar tf arch.tar --quoting-style=literal
6578 Display characters the same way Bourne shell does: control
6579 characters, except `\t' and `\n', are printed using backslash
6580 escapes, `\t' and `\n' are printed as is, and a single quote is
6581 printed as `\''. If a name contains any quoted characters, it is
6582 enclosed in single quotes. In particular, if a name contains
6583 single quotes, it is printed as several single-quoted strings:
6585 $ tar tf arch.tar --quoting-style=shell
6588 './a'\''single'\''quote'
6596 Same as `shell', but the names are always enclosed in single
6599 $ tar tf arch.tar --quoting-style=shell-always
6602 './a'\''single'\''quote'
6610 Use the notation of the C programming language. All names are
6611 enclosed in double quotes. Control characters are quoted using
6612 backslash notations, double quotes are represented as `\"',
6613 backslash characters are represented as `\\'. Single quotes and
6614 spaces are not quoted:
6616 $ tar tf arch.tar --quoting-style=c
6620 "./a\"double\"quote"
6626 Control characters are printed using backslash notation, a space is
6627 printed as `\ ' and a backslash as `\\'. This is the default
6628 quoting style, unless it was changed when configured the package.
6630 $ tar tf arch.tar --quoting-style=escape
6640 Control characters, single quote and backslash are printed using
6641 backslash notation. All names are quoted using left and right
6642 quotation marks, appropriate to the current locale. If it does not
6643 define quotation marks, use ``' as left and `'' as right quotation
6644 marks. Any occurrences of the right quotation mark in a name are
6645 escaped with `\', for example:
6649 $ tar tf arch.tar --quoting-style=locale
6652 `./a\'single\'quote'
6659 Same as `locale', but `"' is used for both left and right
6660 quotation marks, if not provided by the currently selected locale:
6662 $ tar tf arch.tar --quoting-style=clocale
6666 "./a\"double\"quote"
6671 You can specify which characters should be quoted in addition to
6672 those implied by the current quoting style:
6674 `--quote-chars=STRING'
6675 Always quote characters from STRING, even if the selected quoting
6676 style would not quote them.
6678 For example, using `escape' quoting (compare with the usual escape
6681 $ tar tf arch.tar --quoting-style=escape --quote-chars=' "'
6690 To disable quoting of such additional characters, use the following
6693 `--no-quote-chars=STRING'
6694 Remove characters listed in STRING from the list of quoted
6695 characters set by the previous `--quote-chars' option.
6697 This option is particularly useful if you have added `--quote-chars'
6698 to your `TAR_OPTIONS' (*note TAR_OPTIONS::) and wish to disable it for
6699 the current invocation.
6701 Note, that `--no-quote-chars' does _not_ disable those characters
6702 that are quoted by default in the selected quoting style.
6705 File: tar.info, Node: transform, Next: after, Prev: quoting styles, Up: Choosing
6707 6.7 Modifying File and Member Names
6708 ===================================
6710 `Tar' archives contain detailed information about files stored in them
6711 and full file names are part of that information. When storing a file
6712 to an archive, its file name is recorded in it, along with the actual
6713 file contents. When restoring from an archive, a file is created on
6714 disk with exactly the same name as that stored in the archive. In the
6715 majority of cases this is the desired behavior of a file archiver.
6716 However, there are some cases when it is not.
6718 First of all, it is often unsafe to extract archive members with
6719 absolute file names or those that begin with a `../'. GNU `tar' takes
6720 special precautions when extracting such names and provides a special
6721 option for handling them, which is described in *note absolute::.
6723 Secondly, you may wish to extract file names without some leading
6724 directory components, or with otherwise modified names. In other cases
6725 it is desirable to store files under differing names in the archive.
6727 GNU `tar' provides several options for these needs.
6729 `--strip-components=NUMBER'
6730 Strip given NUMBER of leading components from file names before
6733 For example, suppose you have archived whole `/usr' hierarchy to a
6734 tar archive named `usr.tar'. Among other files, this archive contains
6735 `usr/include/stdlib.h', which you wish to extract to the current
6736 working directory. To do so, you type:
6738 $ tar -xf usr.tar --strip=2 usr/include/stdlib.h
6740 The option `--strip=2' instructs `tar' to strip the two leading
6741 components (`usr/' and `include/') off the file name.
6743 If you add the `--verbose' (`-v') option to the invocation above,
6744 you will note that the verbose listing still contains the full file
6745 name, with the two removed components still in place. This can be
6746 inconvenient, so `tar' provides a special option for altering this
6749 `--show-transformed-names'
6750 Display file or member names with all requested transformations
6755 $ tar -xf usr.tar -v --strip=2 usr/include/stdlib.h
6756 usr/include/stdlib.h
6757 $ tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h
6760 Notice that in both cases the file `stdlib.h' is extracted to the
6761 current working directory, `--show-transformed-names' affects only the
6762 way its name is displayed.
6764 This option is especially useful for verifying whether the invocation
6765 will have the desired effect. Thus, before running
6769 it is often advisable to run
6771 $ tar -t -v --show-transformed --strip=N
6773 to make sure the command will produce the intended results.
6775 In case you need to apply more complex modifications to the file
6776 name, GNU `tar' provides a general-purpose transformation option:
6778 `--transform=EXPRESSION'
6779 `--xform=EXPRESSION'
6780 Modify file names using supplied EXPRESSION.
6782 The EXPRESSION is a `sed'-like replace expression of the form:
6784 s/REGEXP/REPLACE/[FLAGS]
6786 where REGEXP is a "regular expression", REPLACE is a replacement for
6787 each file name part that matches REGEXP. Both REGEXP and REPLACE are
6788 described in detail in *note The "s" Command: (sed)The "s" Command.
6790 Any delimiter can be used in lieu of `/', the only requirement being
6791 that it be used consistently throughout the expression. For example,
6792 the following two expressions are equivalent:
6797 Changing delimiters is often useful when the REGEX contains slashes.
6798 For example, it is more convenient to write `s,/,-,' than `s/\//-/'.
6800 As in `sed', you can give several replace expressions, separated by
6803 Supported FLAGS are:
6806 Apply the replacement to _all_ matches to the REGEXP, not just the
6810 Use case-insensitive matching.
6813 REGEXP is an "extended regular expression" (*note Extended regular
6814 expressions: (sed)Extended regexps.).
6817 Only replace the NUMBERth match of the REGEXP.
6819 Note: the POSIX standard does not specify what should happen when
6820 you mix the `g' and NUMBER modifiers. GNU `tar' follows the GNU
6821 `sed' implementation in this regard, so the interaction is defined
6822 to be: ignore matches before the NUMBERth, and then match and
6823 replace all matches from the NUMBERth on.
6826 In addition, several "transformation scope" flags are supported,
6827 that control to what files transformations apply. These are:
6830 Apply transformation to regular archive members.
6833 Do not apply transformation to regular archive members.
6836 Apply transformation to symbolic link targets.
6839 Do not apply transformation to symbolic link targets.
6842 Apply transformation to hard link targets.
6845 Do not apply transformation to hard link targets.
6847 Default is `rsh', which means to apply tranformations to both archive
6848 members and targets of symbolic and hard links.
6850 Default scope flags can also be changed using `flags=' statement in
6851 the transform expression. The flags set this way remain in force until
6852 next `flags=' statement or end of expression, whichever occurs first.
6855 --transform 'flags=S;s|^|/usr/local/|'
6857 Here are several examples of `--transform' usage:
6859 1. Extract `usr/' hierarchy into `usr/local/':
6861 $ tar --transform='s,usr/,usr/local/,' -x -f arch.tar
6863 2. Strip two leading directory components (equivalent to
6864 `--strip-components=2'):
6866 $ tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar
6868 3. Convert each file name to lower case:
6870 $ tar --transform 's/.*/\L&/' -x -f arch.tar
6872 4. Prepend `/prefix/' to each file name:
6874 $ tar --transform 's,^,/prefix/,' -x -f arch.tar
6876 5. Archive the `/lib' directory, prepending `/usr/local' to each
6879 $ tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib
6881 Notice the use of flags in the last example. The `/lib' directory
6882 often contains many symbolic links to files within it. It may look,
6883 for example, like this:
6886 drwxr-xr-x root/root 0 2008-07-08 16:20 /lib/
6887 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
6888 lrwxrwxrwx root/root 0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
6891 Using the expression `s,^,/usr/local/,' would mean adding
6892 `/usr/local' to both regular archive members and to link targets. In
6893 this case, `/lib/libc.so.6' would become:
6895 /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
6897 This is definitely not desired. To avoid this, the `S' flag is
6898 used, which excludes symbolic link targets from filename
6899 transformations. The result is:
6901 $ tar --transform 's,^,/usr/local/,S', -c -v -f arch.tar \
6902 --show-transformed /lib
6903 drwxr-xr-x root/root 0 2008-07-08 16:20 /usr/local/lib/
6904 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
6905 lrwxrwxrwx root/root 0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
6908 Unlike `--strip-components', `--transform' can be used in any GNU
6909 `tar' operation mode. For example, the following command adds files to
6910 the archive while replacing the leading `usr/' component with `var/':
6912 $ tar -cf arch.tar --transform='s,^usr/,var/,' /
6914 To test `--transform' effect we suggest using
6915 `--show-transformed-names' option:
6917 $ tar -cf arch.tar --transform='s,^usr/,var/,' \
6918 --verbose --show-transformed-names /
6920 If both `--strip-components' and `--transform' are used together,
6921 then `--transform' is applied first, and the required number of
6922 components is then stripped from its result.
6924 You can use as many `--transform' options in a single command line
6925 as you want. The specified expressions will then be applied in order
6926 of their appearance. For example, the following two invocations are
6929 $ tar -cf arch.tar --transform='s,/usr/var,/var/' \
6930 --transform='s,/usr/local,/usr/,'
6931 $ tar -cf arch.tar \
6932 --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'
6935 File: tar.info, Node: after, Next: recurse, Prev: transform, Up: Choosing
6937 6.8 Operating Only on New Files
6938 ===============================
6940 The `--after-date=DATE' (`--newer=DATE', `-N DATE') option causes `tar'
6941 to only work on files whose data modification or status change times
6942 are newer than the DATE given. If DATE starts with `/' or `.', it is
6943 taken to be a file name; the data modification time of that file is
6944 used as the date. If you use this option when creating or appending to
6945 an archive, the archive will only include new files. If you use
6946 `--after-date' when extracting an archive, `tar' will only extract
6947 files newer than the DATE you specify.
6949 If you only want `tar' to make the date comparison based on
6950 modification of the file's data (rather than status changes), then use
6951 the `--newer-mtime=DATE' option.
6953 You may use these options with any operation. Note that these
6954 options differ from the `--update' (`-u') operation in that they allow
6955 you to specify a particular date against which `tar' can compare when
6956 deciding whether or not to archive the files.
6961 Only store files newer than DATE.
6963 Acts on files only if their data modification or status change
6964 times are later than DATE. Use in conjunction with any operation.
6966 If DATE starts with `/' or `.', it is taken to be a file name; the
6967 data modification time of that file is used as the date.
6969 `--newer-mtime=DATE'
6970 Acts like `--after-date', but only looks at data modification
6973 These options limit `tar' to operate only on files which have been
6974 modified after the date specified. A file's status is considered to
6975 have changed if its contents have been modified, or if its owner,
6976 permissions, and so forth, have been changed. (For more information on
6977 how to specify a date, see *note Date input formats::; remember that the
6978 entire date argument must be quoted if it contains any spaces.)
6980 Gurus would say that `--after-date' tests both the data modification
6981 time (`mtime', the time the contents of the file were last modified)
6982 and the status change time (`ctime', the time the file's status was
6983 last changed: owner, permissions, etc.) fields, while `--newer-mtime'
6984 tests only the `mtime' field.
6986 To be precise, `--after-date' checks _both_ `mtime' and `ctime' and
6987 processes the file if either one is more recent than DATE, while
6988 `--newer-mtime' only checks `mtime' and disregards `ctime'. Neither
6989 does it use `atime' (the last time the contents of the file were looked
6992 Date specifiers can have embedded spaces. Because of this, you may
6993 need to quote date arguments to keep the shell from parsing them as
6994 separate arguments. For example, the following command will add to the
6995 archive all the files modified less than two days ago:
6997 $ tar -cf foo.tar --newer-mtime '2 days ago'
6999 When any of these options is used with the option `--verbose' (*note
7000 verbose tutorial::) GNU `tar' will try to convert the specified date
7001 back to its textual representation and compare that with the one given
7002 with the option. If the two dates differ, `tar' will print a warning
7003 saying what date it will use. This is to help user ensure he is using
7004 the right date. For example:
7006 $ tar -c -f archive.tar --after-date='10 days ago' .
7007 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7010 *Please Note:* `--after-date' and `--newer-mtime' should not be
7011 used for incremental backups. *Note Incremental Dumps::, for
7012 proper way of creating incremental backups.
7015 File: tar.info, Node: recurse, Next: one, Prev: after, Up: Choosing
7017 6.9 Descending into Directories
7018 ===============================
7020 Usually, `tar' will recursively explore all directories (either those
7021 given on the command line or through the `--files-from' option) for the
7022 various files they contain. However, you may not always want `tar' to
7025 The `--no-recursion' option inhibits `tar''s recursive descent into
7026 specified directories. If you specify `--no-recursion', you can use
7027 the `find' (*note find: (find)Top.) utility for hunting through levels
7028 of directories to construct a list of file names which you could then
7029 pass to `tar'. `find' allows you to be more selective when choosing
7030 which files to archive; see *note files::, for more information on
7031 using `find' with `tar'.
7034 Prevents `tar' from recursively descending directories.
7037 Requires `tar' to recursively descend directories. This is the
7040 When you use `--no-recursion', GNU `tar' grabs directory entries
7041 themselves, but does not descend on them recursively. Many people use
7042 `find' for locating files they want to back up, and since `tar'
7043 _usually_ recursively descends on directories, they have to use the
7044 `-not -type d' test in their `find' invocation (*note Type:
7045 (find)Type.), as they usually do not want all the files in a directory.
7046 They then use the `--files-from' option to archive the files located
7049 The problem when restoring files archived in this manner is that the
7050 directories themselves are not in the archive; so the
7051 `--same-permissions' (`--preserve-permissions', `-p') option does not
7052 affect them--while users might really like it to. Specifying
7053 `--no-recursion' is a way to tell `tar' to grab only the directory
7054 entries given to it, adding no new files on its own. To summarize, if
7055 you use `find' to create a list of files to be stored in an archive,
7058 $ find DIR TESTS | \
7059 tar -cf ARCHIVE -T - --no-recursion
7061 The `--no-recursion' option also applies when extracting: it causes
7062 `tar' to extract only the matched directory entries, not the files
7063 under those directories.
7065 The `--no-recursion' option also affects how globbing patterns are
7066 interpreted (*note controlling pattern-matching::).
7068 The `--no-recursion' and `--recursion' options apply to later
7069 options and operands, and can be overridden by later occurrences of
7070 `--no-recursion' and `--recursion'. For example:
7072 $ tar -cf jams.tar --no-recursion grape --recursion grape/concord
7074 creates an archive with one entry for `grape', and the recursive
7075 contents of `grape/concord', but no entries under `grape' other than
7079 File: tar.info, Node: one, Prev: recurse, Up: Choosing
7081 6.10 Crossing File System Boundaries
7082 ====================================
7084 `tar' will normally automatically cross file system boundaries in order
7085 to archive files which are part of a directory tree. You can change
7086 this behavior by running `tar' and specifying `--one-file-system'.
7087 This option only affects files that are archived because they are in a
7088 directory that is being archived; `tar' will still archive files
7089 explicitly named on the command line or through `--files-from',
7090 regardless of where they reside.
7093 Prevents `tar' from crossing file system boundaries when
7094 archiving. Use in conjunction with any write operation.
7096 The `--one-file-system' option causes `tar' to modify its normal
7097 behavior in archiving the contents of directories. If a file in a
7098 directory is not on the same file system as the directory itself, then
7099 `tar' will not archive that file. If the file is a directory itself,
7100 `tar' will not archive anything beneath it; in other words, `tar' will
7101 not cross mount points.
7103 This option is useful for making full or incremental archival
7104 backups of a file system. If this option is used in conjunction with
7105 `--verbose' (`-v'), files that are excluded are mentioned by name on
7110 * directory:: Changing Directory
7111 * absolute:: Absolute File Names
7114 File: tar.info, Node: directory, Next: absolute, Up: one
7116 6.10.1 Changing the Working Directory
7117 -------------------------------------
7119 To change the working directory in the middle of a list of file names,
7120 either on the command line or in a file specified using `--files-from'
7121 (`-T'), use `--directory' (`-C'). This will change the working
7122 directory to the specified directory after that point in the list.
7124 `--directory=DIRECTORY'
7126 Changes the working directory in the middle of a command line.
7130 $ tar -c -f jams.tar grape prune -C food cherry
7132 will place the files `grape' and `prune' from the current directory
7133 into the archive `jams.tar', followed by the file `cherry' from the
7134 directory `food'. This option is especially useful when you have
7135 several widely separated files that you want to store in the same
7138 Note that the file `cherry' is recorded in the archive under the
7139 precise name `cherry', _not_ `food/cherry'. Thus, the archive will
7140 contain three files that all appear to have come from the same
7141 directory; if the archive is extracted with plain `tar --extract', all
7142 three files will be written in the current directory.
7144 Contrast this with the command,
7146 $ tar -c -f jams.tar grape prune -C food red/cherry
7148 which records the third file in the archive under the name `red/cherry'
7149 so that, if the archive is extracted using `tar --extract', the third
7150 file will be written in a subdirectory named `red'.
7152 You can use the `--directory' option to make the archive independent
7153 of the original name of the directory holding the files. The following
7154 command places the files `/etc/passwd', `/etc/hosts', and `/lib/libc.a'
7155 into the archive `foo.tar':
7157 $ tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a
7159 However, the names of the archive members will be exactly what they were
7160 on the command line: `passwd', `hosts', and `libc.a'. They will not
7161 appear to be related by file name to the original directories where
7162 those files were located.
7164 Note that `--directory' options are interpreted consecutively. If
7165 `--directory' specifies a relative file name, it is interpreted
7166 relative to the then current directory, which might not be the same as
7167 the original current working directory of `tar', due to a previous
7168 `--directory' option.
7170 When using `--files-from' (*note files::), you can put various `tar'
7171 options (including `-C') in the file list. Notice, however, that in
7172 this case the option and its argument may not be separated by
7173 whitespace. If you use short option, its argument must either follow
7174 the option letter immediately, without any intervening whitespace, or
7175 occupy the next line. Otherwise, if you use long option, separate its
7176 argument by an equal sign.
7178 For instance, the file list for the above example will be:
7186 To use it, you would invoke `tar' as follows:
7188 $ tar -c -f foo.tar --files-from list
7190 The interpretation of `--directory' is disabled by `--null' option.
7193 File: tar.info, Node: absolute, Prev: directory, Up: one
7195 6.10.2 Absolute File Names
7196 --------------------------
7198 By default, GNU `tar' drops a leading `/' on input or output, and
7199 complains about file names containing a `..' component. There is an
7200 option that turns off this behavior:
7204 Do not strip leading slashes from file names, and permit file names
7205 containing a `..' file name component.
7207 When `tar' extracts archive members from an archive, it strips any
7208 leading slashes (`/') from the member name. This causes absolute
7209 member names in the archive to be treated as relative file names. This
7210 allows you to have such members extracted wherever you want, instead of
7211 being restricted to extracting the member in the exact directory named
7212 in the archive. For example, if the archive member has the name
7213 `/etc/passwd', `tar' will extract it as if the name were really
7216 File names containing `..' can cause problems when extracting, so
7217 `tar' normally warns you about such files when creating an archive, and
7218 rejects attempts to extracts such files.
7220 Other `tar' programs do not do this. As a result, if you create an
7221 archive whose member names start with a slash, they will be difficult
7222 for other people with a non-GNU `tar' program to use. Therefore, GNU
7223 `tar' also strips leading slashes from member names when putting
7224 members into the archive. For example, if you ask `tar' to add the file
7225 `/bin/ls' to an archive, it will do so, but the member name will be
7228 If you use the `--absolute-names' (`-P') option, `tar' will do none
7229 of these transformations.
7231 To archive or extract files relative to the root directory, specify
7232 the `--absolute-names' (`-P') option.
7234 Normally, `tar' acts on files relative to the working
7235 directory--ignoring superior directory names when archiving, and
7236 ignoring leading slashes when extracting.
7238 When you specify `--absolute-names' (`-P'), `tar' stores file names
7239 including all superior directory names, and preserves leading slashes.
7240 If you only invoked `tar' from the root directory you would never need
7241 the `--absolute-names' option, but using this option may be more
7242 convenient than switching to root.
7245 Preserves full file names (including superior directory names) when
7246 archiving files. Preserves leading slash when extracting files.
7249 `tar' prints out a message about removing the `/' from file names.
7250 This message appears once per GNU `tar' invocation. It represents
7251 something which ought to be told; ignoring what it means can cause very
7252 serious surprises, later.
7254 Some people, nevertheless, do not want to see this message. Wanting
7255 to play really dangerously, one may of course redirect `tar' standard
7256 error to the sink. For example, under `sh':
7258 $ tar -c -f archive.tar /home 2> /dev/null
7260 Another solution, both nicer and simpler, would be to change to the `/'
7261 directory first, and then avoid absolute notation. For example:
7263 $ tar -c -f archive.tar -C / home
7265 *Note Integrity::, for some of the security-related implications of
7268 ---------- Footnotes ----------
7270 (1) A side effect of this is that when `--create' is used with
7271 `--verbose' the resulting output is not, generally speaking, the same
7272 as the one you'd get running `tar --list' command. This may be
7273 important if you use some scripts for comparing both outputs. *Note
7274 listing member and file names::, for the information on how to handle
7278 File: tar.info, Node: Date input formats, Next: Formats, Prev: Choosing, Up: Top
7280 7 Date input formats
7281 ********************
7285 Our units of temporal measurement, from seconds on up to months,
7286 are so complicated, asymmetrical and disjunctive so as to make
7287 coherent mental reckoning in time all but impossible. Indeed, had
7288 some tyrannical god contrived to enslave our minds to time, to
7289 make it all but impossible for us to escape subjection to sodden
7290 routines and unpleasant surprises, he could hardly have done
7291 better than handing down our present system. It is like a set of
7292 trapezoidal building blocks, with no vertical or horizontal
7293 surfaces, like a language in which the simplest thought demands
7294 ornate constructions, useless particles and lengthy
7295 circumlocutions. Unlike the more successful patterns of language
7296 and science, which enable us to face experience boldly or at least
7297 level-headedly, our system of temporal calculation silently and
7298 persistently encourages our terror of time.
7300 ... It is as though architects had to measure length in feet,
7301 width in meters and height in ells; as though basic instruction
7302 manuals demanded a knowledge of five different languages. It is
7303 no wonder then that we often look into our own immediate past or
7304 future, last Tuesday or a week from Sunday, with feelings of
7305 helpless confusion. ...
7307 -- Robert Grudin, `Time and the Art of Living'.
7309 This section describes the textual date representations that GNU
7310 programs accept. These are the strings you, as a user, can supply as
7311 arguments to the various programs. The C interface (via the
7312 `parse_datetime' function) is not described here.
7316 * General date syntax:: Common rules.
7317 * Calendar date items:: 19 Dec 1994.
7318 * Time of day items:: 9:20pm.
7319 * Time zone items:: EST, PDT, GMT.
7320 * Day of week items:: Monday and others.
7321 * Relative items in date strings:: next tuesday, 2 years ago.
7322 * Pure numbers in date strings:: 19931219, 1440.
7323 * Seconds since the Epoch:: @1078100502.
7324 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
7325 * Authors of parse_datetime:: Bellovin, Eggert, Salz, Berets, et al.
7328 File: tar.info, Node: General date syntax, Next: Calendar date items, Up: Date input formats
7330 7.1 General date syntax
7331 =======================
7333 A "date" is a string, possibly empty, containing many items separated
7334 by whitespace. The whitespace may be omitted when no ambiguity arises.
7335 The empty string means the beginning of today (i.e., midnight). Order
7336 of the items is immaterial. A date string may contain many flavors of
7339 * calendar date items
7345 * day of the week items
7351 We describe each of these item types in turn, below.
7353 A few ordinal numbers may be written out in words in some contexts.
7354 This is most useful for specifying day of the week items or relative
7355 items (see below). Among the most commonly used ordinal numbers, the
7356 word `last' stands for -1, `this' stands for 0, and `first' and `next'
7357 both stand for 1. Because the word `second' stands for the unit of
7358 time there is no way to write the ordinal number 2, but for convenience
7359 `third' stands for 3, `fourth' for 4, `fifth' for 5, `sixth' for 6,
7360 `seventh' for 7, `eighth' for 8, `ninth' for 9, `tenth' for 10,
7361 `eleventh' for 11 and `twelfth' for 12.
7363 When a month is written this way, it is still considered to be
7364 written numerically, instead of being "spelled in full"; this changes
7365 the allowed strings.
7367 In the current implementation, only English is supported for words
7368 and abbreviations like `AM', `DST', `EST', `first', `January',
7369 `Sunday', `tomorrow', and `year'.
7371 The output of the `date' command is not always acceptable as a date
7372 string, not only because of the language problem, but also because
7373 there is no standard meaning for time zone items like `IST'. When using
7374 `date' to generate a date string intended to be parsed later, specify a
7375 date format that is independent of language and that does not use time
7376 zone items other than `UTC' and `Z'. Here are some ways to do this:
7378 $ LC_ALL=C TZ=UTC0 date
7379 Mon Mar 1 00:21:42 UTC 2004
7380 $ TZ=UTC0 date +'%Y-%m-%d %H:%M:%SZ'
7381 2004-03-01 00:21:42Z
7382 $ date --iso-8601=ns | tr T ' ' # --iso-8601 is a GNU extension.
7383 2004-02-29 16:21:42,692722128-0800
7384 $ date --rfc-2822 # a GNU extension
7385 Sun, 29 Feb 2004 16:21:42 -0800
7386 $ date +'%Y-%m-%d %H:%M:%S %z' # %z is a GNU extension.
7387 2004-02-29 16:21:42 -0800
7388 $ date +'@%s.%N' # %s and %N are GNU extensions.
7389 @1078100502.692722128
7391 Alphabetic case is completely ignored in dates. Comments may be
7392 introduced between round parentheses, as long as included parentheses
7393 are properly nested. Hyphens not followed by a digit are currently
7394 ignored. Leading zeros on numbers are ignored.
7396 Invalid dates like `2005-02-29' or times like `24:00' are rejected.
7397 In the typical case of a host that does not support leap seconds, a
7398 time like `23:59:60' is rejected even if it corresponds to a valid leap
7402 File: tar.info, Node: Calendar date items, Next: Time of day items, Prev: General date syntax, Up: Date input formats
7404 7.2 Calendar date items
7405 =======================
7407 A "calendar date item" specifies a day of the year. It is specified
7408 differently, depending on whether the month is specified numerically or
7409 literally. All these strings specify the same calendar date:
7411 1972-09-24 # ISO 8601.
7412 72-9-24 # Assume 19xx for 69 through 99,
7413 # 20xx for 00 through 68.
7414 72-09-24 # Leading zeros are ignored.
7415 9/24/72 # Common U.S. writing.
7417 24 Sept 72 # September has a special abbreviation.
7418 24 Sep 72 # Three-letter abbreviations always allowed.
7423 The year can also be omitted. In this case, the last specified year
7424 is used, or the current year if none. For example:
7431 For numeric months, the ISO 8601 format `YEAR-MONTH-DAY' is allowed,
7432 where YEAR is any positive number, MONTH is a number between 01 and 12,
7433 and DAY is a number between 01 and 31. A leading zero must be present
7434 if a number is less than ten. If YEAR is 68 or smaller, then 2000 is
7435 added to it; otherwise, if YEAR is less than 100, then 1900 is added to
7436 it. The construct `MONTH/DAY/YEAR', popular in the United States, is
7437 accepted. Also `MONTH/DAY', omitting the year.
7439 Literal months may be spelled out in full: `January', `February',
7440 `March', `April', `May', `June', `July', `August', `September',
7441 `October', `November' or `December'. Literal months may be abbreviated
7442 to their first three letters, possibly followed by an abbreviating dot.
7443 It is also permitted to write `Sept' instead of `September'.
7445 When months are written literally, the calendar date may be given as
7446 any of the following:
7453 Or, omitting the year:
7458 File: tar.info, Node: Time of day items, Next: Time zone items, Prev: Calendar date items, Up: Date input formats
7460 7.3 Time of day items
7461 =====================
7463 A "time of day item" in date strings specifies the time on a given day.
7464 Here are some examples, all of which represent the same time:
7469 20:02-0500 # In EST (U.S. Eastern Standard Time).
7471 More generally, the time of day may be given as
7472 `HOUR:MINUTE:SECOND', where HOUR is a number between 0 and 23, MINUTE
7473 is a number between 0 and 59, and SECOND is a number between 0 and 59
7474 possibly followed by `.' or `,' and a fraction containing one or more
7475 digits. Alternatively, `:SECOND' can be omitted, in which case it is
7476 taken to be zero. On the rare hosts that support leap seconds, SECOND
7479 If the time is followed by `am' or `pm' (or `a.m.' or `p.m.'), HOUR
7480 is restricted to run from 1 to 12, and `:MINUTE' may be omitted (taken
7481 to be zero). `am' indicates the first half of the day, `pm' indicates
7482 the second half of the day. In this notation, 12 is the predecessor of
7483 1: midnight is `12am' while noon is `12pm'. (This is the zero-oriented
7484 interpretation of `12am' and `12pm', as opposed to the old tradition
7485 derived from Latin which uses `12m' for noon and `12pm' for midnight.)
7487 The time may alternatively be followed by a time zone correction,
7488 expressed as `SHHMM', where S is `+' or `-', HH is a number of zone
7489 hours and MM is a number of zone minutes. The zone minutes term, MM,
7490 may be omitted, in which case the one- or two-digit correction is
7491 interpreted as a number of hours. You can also separate HH from MM
7492 with a colon. When a time zone correction is given this way, it forces
7493 interpretation of the time relative to Coordinated Universal Time
7494 (UTC), overriding any previous specification for the time zone or the
7495 local time zone. For example, `+0530' and `+05:30' both stand for the
7496 time zone 5.5 hours ahead of UTC (e.g., India). This is the best way to
7497 specify a time zone correction by fractional parts of an hour. The
7498 maximum zone correction is 24 hours.
7500 Either `am'/`pm' or a time zone correction may be specified, but not
7504 File: tar.info, Node: Time zone items, Next: Day of week items, Prev: Time of day items, Up: Date input formats
7509 A "time zone item" specifies an international time zone, indicated by a
7510 small set of letters, e.g., `UTC' or `Z' for Coordinated Universal
7511 Time. Any included periods are ignored. By following a
7512 non-daylight-saving time zone by the string `DST' in a separate word
7513 (that is, separated by some white space), the corresponding daylight
7514 saving time zone may be specified. Alternatively, a
7515 non-daylight-saving time zone can be followed by a time zone
7516 correction, to add the two values. This is normally done only for
7517 `UTC'; for example, `UTC+05:30' is equivalent to `+05:30'.
7519 Time zone items other than `UTC' and `Z' are obsolescent and are not
7520 recommended, because they are ambiguous; for example, `EST' has a
7521 different meaning in Australia than in the United States. Instead,
7522 it's better to use unambiguous numeric time zone corrections like
7523 `-0500', as described in the previous section.
7525 If neither a time zone item nor a time zone correction is supplied,
7526 time stamps are interpreted using the rules of the default time zone
7527 (*note Specifying time zone rules::).
7530 File: tar.info, Node: Day of week items, Next: Relative items in date strings, Prev: Time zone items, Up: Date input formats
7532 7.5 Day of week items
7533 =====================
7535 The explicit mention of a day of the week will forward the date (only
7536 if necessary) to reach that day of the week in the future.
7538 Days of the week may be spelled out in full: `Sunday', `Monday',
7539 `Tuesday', `Wednesday', `Thursday', `Friday' or `Saturday'. Days may
7540 be abbreviated to their first three letters, optionally followed by a
7541 period. The special abbreviations `Tues' for `Tuesday', `Wednes' for
7542 `Wednesday' and `Thur' or `Thurs' for `Thursday' are also allowed.
7544 A number may precede a day of the week item to move forward
7545 supplementary weeks. It is best used in expression like `third
7546 monday'. In this context, `last DAY' or `next DAY' is also acceptable;
7547 they move one week before or after the day that DAY by itself would
7550 A comma following a day of the week item is ignored.
7553 File: tar.info, Node: Relative items in date strings, Next: Pure numbers in date strings, Prev: Day of week items, Up: Date input formats
7555 7.6 Relative items in date strings
7556 ==================================
7558 "Relative items" adjust a date (or the current date if none) forward or
7559 backward. The effects of relative items accumulate. Here are some
7567 The unit of time displacement may be selected by the string `year'
7568 or `month' for moving by whole years or months. These are fuzzy units,
7569 as years and months are not all of equal duration. More precise units
7570 are `fortnight' which is worth 14 days, `week' worth 7 days, `day'
7571 worth 24 hours, `hour' worth 60 minutes, `minute' or `min' worth 60
7572 seconds, and `second' or `sec' worth one second. An `s' suffix on
7573 these units is accepted and ignored.
7575 The unit of time may be preceded by a multiplier, given as an
7576 optionally signed number. Unsigned numbers are taken as positively
7577 signed. No number at all implies 1 for a multiplier. Following a
7578 relative item by the string `ago' is equivalent to preceding the unit
7579 by a multiplier with value -1.
7581 The string `tomorrow' is worth one day in the future (equivalent to
7582 `day'), the string `yesterday' is worth one day in the past (equivalent
7585 The strings `now' or `today' are relative items corresponding to
7586 zero-valued time displacement, these strings come from the fact a
7587 zero-valued time displacement represents the current time when not
7588 otherwise changed by previous items. They may be used to stress other
7589 items, like in `12:00 today'. The string `this' also has the meaning
7590 of a zero-valued time displacement, but is preferred in date strings
7591 like `this thursday'.
7593 When a relative item causes the resulting date to cross a boundary
7594 where the clocks were adjusted, typically for daylight saving time, the
7595 resulting date and time are adjusted accordingly.
7597 The fuzz in units can cause problems with relative items. For
7598 example, `2003-07-31 -1 month' might evaluate to 2003-07-01, because
7599 2003-06-31 is an invalid date. To determine the previous month more
7600 reliably, you can ask for the month before the 15th of the current
7604 Thu, 31 Jul 2003 13:02:39 -0700
7605 $ date --date='-1 month' +'Last month was %B?'
7606 Last month was July?
7607 $ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
7608 Last month was June!
7610 Also, take care when manipulating dates around clock changes such as
7611 daylight saving leaps. In a few cases these have added or subtracted
7612 as much as 24 hours from the clock, so it is often wise to adopt
7613 universal time by setting the `TZ' environment variable to `UTC0'
7614 before embarking on calendrical calculations.
7617 File: tar.info, Node: Pure numbers in date strings, Next: Seconds since the Epoch, Prev: Relative items in date strings, Up: Date input formats
7619 7.7 Pure numbers in date strings
7620 ================================
7622 The precise interpretation of a pure decimal number depends on the
7623 context in the date string.
7625 If the decimal number is of the form YYYYMMDD and no other calendar
7626 date item (*note Calendar date items::) appears before it in the date
7627 string, then YYYY is read as the year, MM as the month number and DD as
7628 the day of the month, for the specified calendar date.
7630 If the decimal number is of the form HHMM and no other time of day
7631 item appears before it in the date string, then HH is read as the hour
7632 of the day and MM as the minute of the hour, for the specified time of
7633 day. MM can also be omitted.
7635 If both a calendar date and a time of day appear to the left of a
7636 number in the date string, but no relative item, then the number
7640 File: tar.info, Node: Seconds since the Epoch, Next: Specifying time zone rules, Prev: Pure numbers in date strings, Up: Date input formats
7642 7.8 Seconds since the Epoch
7643 ===========================
7645 If you precede a number with `@', it represents an internal time stamp
7646 as a count of seconds. The number can contain an internal decimal
7647 point (either `.' or `,'); any excess precision not supported by the
7648 internal representation is truncated toward minus infinity. Such a
7649 number cannot be combined with any other date item, as it specifies a
7650 complete time stamp.
7652 Internally, computer times are represented as a count of seconds
7653 since an epoch--a well-defined point of time. On GNU and POSIX
7654 systems, the epoch is 1970-01-01 00:00:00 UTC, so `@0' represents this
7655 time, `@1' represents 1970-01-01 00:00:01 UTC, and so forth. GNU and
7656 most other POSIX-compliant systems support such times as an extension
7657 to POSIX, using negative counts, so that `@-1' represents 1969-12-31
7660 Traditional Unix systems count seconds with 32-bit two's-complement
7661 integers and can represent times from 1901-12-13 20:45:52 through
7662 2038-01-19 03:14:07 UTC. More modern systems use 64-bit counts of
7663 seconds with nanosecond subcounts, and can represent all the times in
7664 the known lifetime of the universe to a resolution of 1 nanosecond.
7666 On most hosts, these counts ignore the presence of leap seconds.
7667 For example, on most hosts `@915148799' represents 1998-12-31 23:59:59
7668 UTC, `@915148800' represents 1999-01-01 00:00:00 UTC, and there is no
7669 way to represent the intervening leap second 1998-12-31 23:59:60 UTC.
7672 File: tar.info, Node: Specifying time zone rules, Next: Authors of parse_datetime, Prev: Seconds since the Epoch, Up: Date input formats
7674 7.9 Specifying time zone rules
7675 ==============================
7677 Normally, dates are interpreted using the rules of the current time
7678 zone, which in turn are specified by the `TZ' environment variable, or
7679 by a system default if `TZ' is not set. To specify a different set of
7680 default time zone rules that apply just to one date, start the date
7681 with a string of the form `TZ="RULE"'. The two quote characters (`"')
7682 must be present in the date, and any quotes or backslashes within RULE
7683 must be escaped by a backslash.
7685 For example, with the GNU `date' command you can answer the question
7686 "What time is it in New York when a Paris clock shows 6:30am on October
7687 31, 2004?" by using a date beginning with `TZ="Europe/Paris"' as shown
7688 in the following shell transcript:
7690 $ export TZ="America/New_York"
7691 $ date --date='TZ="Europe/Paris" 2004-10-31 06:30'
7692 Sun Oct 31 01:30:00 EDT 2004
7694 In this example, the `--date' operand begins with its own `TZ'
7695 setting, so the rest of that operand is processed according to
7696 `Europe/Paris' rules, treating the string `2004-10-31 06:30' as if it
7697 were in Paris. However, since the output of the `date' command is
7698 processed according to the overall time zone rules, it uses New York
7699 time. (Paris was normally six hours ahead of New York in 2004, but
7700 this example refers to a brief Halloween period when the gap was five
7703 A `TZ' value is a rule that typically names a location in the `tz'
7704 database (http://www.twinsun.com/tz/tz-link.htm). A recent catalog of
7705 location names appears in the TWiki Date and Time Gateway
7706 (http://twiki.org/cgi-bin/xtra/tzdate). A few non-GNU hosts require a
7707 colon before a location name in a `TZ' setting, e.g.,
7708 `TZ=":America/New_York"'.
7710 The `tz' database includes a wide variety of locations ranging from
7711 `Arctic/Longyearbyen' to `Antarctica/South_Pole', but if you are at sea
7712 and have your own private time zone, or if you are using a non-GNU host
7713 that does not support the `tz' database, you may need to use a POSIX
7714 rule instead. Simple POSIX rules like `UTC0' specify a time zone
7715 without daylight saving time; other rules can specify simple daylight
7716 saving regimes. *Note Specifying the Time Zone with `TZ': (libc)TZ
7720 File: tar.info, Node: Authors of parse_datetime, Prev: Specifying time zone rules, Up: Date input formats
7722 7.10 Authors of `parse_datetime'
7723 ================================
7725 `parse_datetime' started life as `getdate', as originally implemented
7726 by Steven M. Bellovin (<smb@research.att.com>) while at the University
7727 of North Carolina at Chapel Hill. The code was later tweaked by a
7728 couple of people on Usenet, then completely overhauled by Rich $alz
7729 (<rsalz@bbn.com>) and Jim Berets (<jberets@bbn.com>) in August, 1990.
7730 Various revisions for the GNU system were made by David MacKenzie, Jim
7731 Meyering, Paul Eggert and others, including renaming it to `get_date' to
7732 avoid a conflict with the alternative Posix function `getdate', and a
7733 later rename to `parse_datetime'. The Posix function `getdate' can
7734 parse more locale-specific dates using `strptime', but relies on an
7735 environment variable and external file, and lacks the thread-safety of
7738 This chapter was originally produced by Franc,ois Pinard
7739 (<pinard@iro.umontreal.ca>) from the `parse_datetime.y' source code,
7740 and then edited by K. Berry (<kb@cs.umb.edu>).