About Us Documentation

Contact Site Map
 

  

WinPak
Documentation

Go to the previous, next chapter.

Using the Tape Archiver

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

The tape archiver tar allows you to store many files in an archive file or tar file which describes the names and contents of the constituent files. Later you can extract some or all of these files from the archive.

Tar files are not restricted to magnetic tapes. The tar program can equally well use an ordinary file, or a pipe, or any device, as the archive. But they were originally designed for use with magnetic tapes, and that is how the name tar came about.

Archive files can be used for transporting a group of files from one system to another: put all relevant files into an archive on one computer system, transfer the archive to another, and extract the contents there. The basic transfer medium might be magnetic tape, Internet FTP, or even electronic mail (though you must encode the archive with uuencode in order to transport it properly by mail). Both machines do not have to use the same operating system, as long as they both support the tar program.

A magnetic tape can store several files in sequence, but has no names for them, just relative position on the tape. A tar file or something like it is the only way to store several files on one tape and retain their names. Even when the basic transfer mechanism can keep track of names, as FTP can, the nuisance of handling multiple files, directories, and multiple links, may make a tar file a much easier method.

Archive files are also used for long-term storage, which you can think of as transportation from one time to another.

Piping one tar to another is an easy way to copy a directory's contents from one disk to another, while preserving the dates, modes, owners and link-structure of all the files therein.

The GNU version of tar has special features that allow it to be used to make incremental and full dumps of all the files in a filesystem.

Using tar to Perform Full Dumps

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

Full dumps should only be made when no other people or programs are modifying files in the filesystem. If files are modified while tar is making the backup, they may not be stored properly in the archive, in which case you won't be able to restore them if you have to.

You will want to use the -V option to give the archive a volume label, so you can tell what this archive is even if the label falls off the tape, or anything like that.

Unless the filesystem you are dumping is guaranteed to fit on one volume, you will need to use the -M option. Make sure you have enough tapes on hand to complete the backup.

If you want to dump each filesystem separately you will need to use the -l option to prevent tar from crossing filesystem boundaries when storing (sub)directories.

The -G option is not needed, since this is a complete copy of everything in the filesystem, and a full restore from this backup would only be done onto a completely empty disk.

Unless you are in a hurry, and trust the tar program (and your tapes), it is a good idea to use the -W (verify) option, to make sure your files really made it onto the dump properly. This will also detect cases where the file was modified while (or just after) it was being archived.

Using tar to Perform Incremental Dumps

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

Performing incremental dumps is similar to performing full dumps, although a few more options will usually be needed.

You will need to use the -N DATE option to tell tar to only store files that have been modified since DATE. DATE should be the date and time of the last full/incremental dump.

A standard scheme is to do a monthly (full) dump once a month, a weekly dump once a week of everything since the last monthly and a daily every day of everything since the last (weekly or monthly) dump.

Here is a copy of the script used to dump the filesystems of the machines here at the Free Software Foundation. This script is run (semi-)automatically late at night when people are least likely to be using the machines. This script dumps several filesystems from several machines at once (by using a network-filesystem). The operator is responsible for ensuring that all the machines will be up at the time the dump happens. If a machine is not running, its files will not be dumped, and the next day's incremental dump will not store files that would have gone onto that dump.

#!/bin/csh
# Dump thingie
set now = `date`
set then = `cat date.nfs.dump`
/u/hack/bin/tar -c -G -v\
 -f /dev/rtu20\
 -b 126\
 -N "$then"\
 -V "Dump from $then to $now"\
 /alpha-bits/gp\
 /gnu/hack\
 /hobbes/u\
 /spiff/u\
 /sugar-bombs/u
echo $now > date.nfs.dump
mt -f /dev/rtu20 rew

Output from this script is stored in a file, for the operator to read later.

This script uses the file date.nfs.dump to store the date/time of the last dump.

Since this is a streaming tape drive, no attempt to verify the archive is done. This is also why the high blocking factor (126) is used. The tape drive must also be rewound by the mt command after the dump is made.

Common Problems Using tar

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

Unless you use the -P option, GNU tar will not allow you to create an archive that contains absolute pathnames. (An absolute pathname is one that begins with a /.) If you try, tar will automatically remove the leading / from the file names it stores in the archive. It will also type a warning message telling you what it is doing.

When reading an archive that was created with a different tar program, GNU tar automatically extracts entries in the archive which have absolute pathnames as if the pathnames were not absolute. If the archive contained a file /usr/bin/computoy, GNU tar would extract the file to usr/bin/computoy in the current directory. If you want to extract the files in an archive to the same absolute names that they had when the archive was created, you should do a cd / before extracting the files from the archive, or you should either use the -P option, or use the command tar -C / ....

Some versions of UNIX, (Ultrix 3.1 is know to have this problem) can claim that a short write near the end of a tape succeeded, when it actually failed. This will result in the -M option not working correctly. The best workaround at the moment is to use a significantly larger blocksize than the default 20.

In order to update an archive, tar must be able to backspace the archive in order to re-read or re-write a block that was just read (or written). This is currently possible only on two kinds of files: normal disk files (or any other file that can be backspaced with lseek ()), and industry-standard 9-track magnetic tape (or any other kind of tape that can be backspaced with ioctl (..., MTIOCTOP, ...)).

This means that the -r, -u, -A, and -D commands will not work on any other kind of file. Some media simply cannot be backspaced, which means these commands and options will never be able to work on them. These non-backspacing media include pipes and cartridge tape drives.

Some other media can be backspaced, and tar will work on them once tar is modified to do so.

Archives created with the -M, -V, and -G options may not be readable by other version of tar. In particular, restoring a file that was split over a volume boundary will require some careful work with dd, if it can be done at all. Other versions of tar may also create an empty file whose name is that of the volume header. Some versions of tar may create normal files instead of directories archived with the -G option.

The Remote Tape Server

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

In order to access the tape drive on a remote machine, tar uses the remote tape server written at the University of California at Berkeley. The remote tape server must be installed as /etc/rmt on any machine whose tape drive you want to use. tar calls /etc/rmt by running an rsh or remsh to the remote machine, optionally using a different login name if one is supplied.

A copy of the source for the remote tape server is provided. It is Copyright (C) 1983 by the Regents of the University of California, but can be freely distributed. Instructions for compiling and installing it are included in the Makefile.

The remote tape server may need to be modified in order to run on a non-4.3BSD system.

Calling the GNU Tape Archiver

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

The format of the tar command is approximately:

tar [ option ]... [ file ]...

Options may be specified as individual arguments starting with -. In this case, if the option wants an argument (as does, for example, -f) then the argument should come after the option, separated from it by a space. All options are optional. Some options make sense with any main operation mode (or command), while others are meaningful only with particular commands.

Each of the following subsection regroups some options under a common functionnality.

GNU tar returns only a few exit status. I'm really aiming simplicity in that area, for now. If you are not using tar -d, zero means that everything went well, besides maybe innocuous warnings. Non-zero means that something went wrong. Right now, as of today, non-zero is almost always 2, except in rtapelib.c where it may be 128.

Old Syntax for Options

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

For compatibility with Unix tar, the first argument can contain option letters in addition to the command letter; for example, tar cv specifies the option -v in addition to the command -c. The first argument to GNU tar is always treated as command and option letters even if it doesn't start with -.

Some options need their own arguments; for example, -f is followed by the name of the archive file. When the option is given separately, its argument follows it, as is usual for Unix programs. For example:

tar -c -v -b 20 -f /dev/rmt0

When options that need arguments are given together with the command, all the associated arguments follow, in the same order as the options. Thus, the example above could also be written in the old style as follows:

tar cvbf 20 /dev/rmt0

Here 20 is the argument of -b and /dev/rmt0 is the argument of -f.

The long-named options can be used instead of the single-letter flags. They are meant to be obvious and easy to remember, possibly more so than their corresponding single-letter options. The above example using long-named options would look like this:

tar --create --verbose --block-size --file 20 /dev/rmt0

Main operation mode

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

One program, tar, is used to create an archive, to extract files from an archive, to modify an archive, or to list the contents. Each time you run tar, you must give a command to specify which one of these things you want to do.

The command must always be in the first argument to tar. This argument can also contain options (*Note Options::). For compatibility with Unix tar, the first argument is always treated as containing command and option letters even if it doesn't start with -. Thus, tar c is equivalent to tar -c

: both of them specify the -c command to create an archive.

In addition, a set of long-named options are provided which can be used instead of or inter-mixed with the single-letter flags. The long-named options are meant to be easy to remember and logical, while the single letter flags may not always be. Long-named options are preceded by --.

The remaining arguments to tar are either options, if they start with - or --, or files to operate on.

The file names that you give as arguments are the files that tar will act on --- for example, they are the files to put in the archive, or the files to extract from it. If you don't give any file name arguments, the default depends on which command you used. Some commands use all relevant files; some commands have no default and will report an error if you don't specify files.

If a file name argument actually names a directory, then that directory and all files and subdirectories in it are used.

Here is a list of all the tar commands:

-t --list List the contents of an archive.

This command causes tar to display a list of the files in the archive. If you specify file names, only the files that you specify will be mentioned (but each of them is mentioned only if it appears in the archive).

-x --extract --get Extract files from an archive.

This command causes tar to extract the specified files from the archive. If no file names are given, all the files in the archive will be extracted.

-c --create Create a new archive.

This command tells tar to create a new archive that contains the file(s) specified on the command line. If you don't specify files, all the files in the current directory are used.

If the archive file already exists, it is overwritten; the old contents are lost.

-d --diff --compare Find differences between archive and file system.

This command causes tar to compare the archive with the files in the file system. It will report differences in file size, mode, owner, and contents. If a file exists in the archive, but not in the file system, tar will report this.

If you specify file names, those files are compared with the tape and they must all exist in the archive. If you don't specify files, all the files in the archive are compared.

-r --append Append files to the end of an archive.

This command causes tar to add the specified file(s) to the end of the archive. This assumes that the archive file already exists and is in the proper format (which probably means it was created previously with the tar program). If the archive is not in a format that tar understands, the results will be unpredictable.

You must specify the files to be used; there is no default.

-u --update Only append files newer than copy in archive.

This command causes tar to add the specified files to the end of the archive, like -r, but only when a file doesn't already exist in the archive or is newer than the version in the archive (the last-modification time is compared). Adding files to the end of an archive can be very slow.

You must specify the files to be used; there is no default.

-A --catenate --concatenate Append tar files to an archive.

This command is used for concatenating several archive files into one big archive file. The files to operate on should all be archive files. They are all appended to the end of the archive file which tar works on. (The other files are not changed).

You might be tempted to use cat for this, but it won't ordinarily work. A tar archive contains data which indicates the end of the archive, so more material added to the end with cat would be ignored. This command works because it removes the end-of-archive markers from the middle of the result.

--delete Delete from the archive (not on mag tapes!).

This command causes tar to delete the specified files from the archive. This command is extremely slow. Warning: Use of this command on archives stored on magnetic tape may result in a scrambled archive. There is no safe way (except for completely re-writing the archive) to delete files from a magnetic tape.

Operation mode modificators

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

-W --verify Attempt to verify the archive after writing it.

This option causes tar to verify the archive after writing it. Each volume is checked after it is written, and any discrepancies are recorded on the standard error output.

Verification requires that the archive be on a back-space-able medium. This means pipes, some cartridge tape drives, and some other devices cannot be verified.

--remove-files Remove files after adding them to the archive.

-k --keep-old-files Do not overwrite existing files from archive.

The -k option prevents tar from over-writing existing files with files with the same name from the archive.

The -k option is meaningless with -t.

-S --sparse Handle sparse files efficiently.

This option causes all files to be put in the archive to be tested for sparseness, and handled specially if they are. The -S option is useful when many dbm files, for example, are being backed up, and running out of space on the tape is an issue. Using this option dramatically decreases the amount of space needed to store such a file.

In later versions, this option may be removed, and the testing and treatment of sparse files may be done automatically with any special GNU options. For now, it is an option needing to be specified on the command line with the creation or updating of an archive.

-O --to-stdout Extract files to standard output.

When this option is used, instead of creating the files specified, tar writes the contents of the files extracted to its standard output. This may be useful if you are only extracting the files in order to send them through a pipe.

This option is meaningless with -t.

-G --incremental Handle old GNU-format incremental backup.

This option should only be used when creating an incremental backup of a filesystem. When the -G option is used, tar writes, at the beginning of the archive, an entry for each of the directories that will be operated on. The entry for a directory includes a list of all the files in the directory at the time the dump was done, and a flag for each file indicating whether the file is going to be put in the archive. This information is used when doing a complete incremental restore.

Note that this option causes tar to create a non-standard archive that may not be readable by non-GNU versions of the tar program.

The -G option means the archive is an incremental backup. Its meaning depends on the command that it modifies.

If the -G option is used with -t, tar will list, for each directory in the archive, the list of files in that directory at the time the archive was created. This information is put out in a format that is not easy for humans to read, but which is unambiguous for a program: each filename is preceded by either a Y if the file is present in the archive, an N if the file is not included in the archive, or a D if the file is a directory (and is included in the archive). Each filename is terminated by a null character. The last file is followed by an additional null and a newline to indicate the end of the data.

If the -G option is used with -x, then when the entry for a directory is found, all files that currently exist in that directory but are not listed in the archive are deleted from the directory.

This behavior is convenient when you are restoring a damaged file system from a succession of incremental backups: it restores the entire state of the file system to that which obtained when the backup was made. If you don't use -G, the file system will probably fill up with files that shouldn't exist any more.

-g --listed-incremental Handle new GNU-format incremental backup.

--ignore-failed-read Do not exit with non-zero on unreadable files.

Handling of file attributes

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

--atime-preserve Do not change access times on dumped files.

-m --modification-time Do not extract file modified time.

When this option is used, tar leaves the modification times of the files it extracts as the time when the files were extracted, instead of setting it to the time recorded in the archive.

This option is meaningless with -t.

--same-owner Create extracted files with the same ownership.

-p --same-permissions --preserve-permissions Extract all protection information.

This option causes tar to set the modes (access permissions) of extracted files exactly as recorded in the archive. If this option is not used, the current umask setting limits the permissions on extracted files.

This option is meaningless with -t.

-s --same-order --preserve-order Sort names to extract to match archive.

This option tells tar that the list of filenames to be listed or extracted is sorted in the same order as the files in the archive. This allows a large list of names to be used, even on a small machine that would not otherwise be able to hold all the names in memory at the same time. Such a sorted list can easily be created by running tar -t on the archive and editing its output.

This option is probably never needed on modern computer systems.

--preserve Same as both -p and -s.

The --preserve option has no equivalent short option name. It is equivalent to -p plus -s.

Device selection and switching

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

On *this* particular tar, the defaults are -f /dev/rmt0 and -b 20.

-f [hostname:]file --file=[hostname:]file Use archive file or device file on hostname.

This option is used to specify the file name of the archive tar works on.

If the filename is -, tar reads the archive from standard input (when listing or extracting), or writes it to standard output (when creating). If the - filename is given when updating an archive, tar will read the original archive from its standard input, and will write the entire new archive to its standard output.

If the filename contains :/dev/, it is interpreted as hostname:filename. If the hostname contains an at sign (@), it is treated as user@hostname:filename. In either case, tar will invoke the command rsh (or remsh) to start up an /etc/rmt on the remote machine. If you give an alternate login name, it will be given to the rsh. Naturally, the remote machine must have a copy of /etc/rmt. /etc/rmt is free software from the University of California, and a copy of the source code can be found with the sources for tar. /etc/rmt will have to be modified to run on non-BSD4.3 systems.

If this option is not given, but the environment variable TAPE is set, its value is used; otherwise, a default archive name (which was picked when tar was compiled) is used. The default is normally set up to be the first tape drive or other transportable I/O medium on the system.

Starting with 1.11.5, GNU tar uses standard input and standard output as the default device, and I will not try anymore supporting automatic device detection at installation time. This was failing really in too many cases, it was hopeless. This is now completely left to the installer to override standard input and standard output for default device, if this seems unacceptable to him/her. Further, I think most actual usages of tar are done with pipes or disks, not really tapes, cartridges or diskettes.

This could lead to a nasty surprise on your screen if you forget to specify an output file name -- especially if you are going through a network or terminal server capable of buffering large amounts of output before you can type a ^C...

GNU tar reads and writes archive in blocks, I suspect this is the main reason why block devices are preferred over character devices. Most probably, block devices are more efficient too. The installer could also check for DEFTAPE in .

--force-local Archive file is local even if has a colon.

--rsh-command=command Use remote command instead of rsh. This option exists so that people who use something other than the standard rsh (e.g., a Kerberized rsh) can access a remote device.

When this command is not used, the shell command found when the tar program was installed is used instead. This is the first found of /usr/ucb/rsh, /usr/bin/remsh, /usr/bin/rsh, /usr/bsd/rsh or /usr/bin/nsh. The installer may have overriden this by defining the environment variable RSH at installation time.

-[0-7][lmh] Specify drive and density.

-M --multi-volume Create/list/extract multi-volume archive.

This option causes tar to write a multi-volume archive --- one that may be larger than will fit on the medium used to hold it.

When this option is used, tar will not abort when it cannot read or write any more data. Instead, it will ask you to prepare a new volume. If the archive is on a magnetic tape, you should change tapes now; if the archive is on a floppy disk, you should change disks, etc.

Each volume of a multi-volume archive is an independent tar archive, complete in itself. For example, you can list or extract any volume alone (just don't specify -M). However, if one file in the archive is split across volumes, the only way to extract it successfully is with a multi-volume extract command (-xM) starting on or before the volume where the file begins.

-L num --tape-length=num Change tape after writing num x 1024 bytes.

-F file --info-script=file --new-volume-script=file Run script at end of each tape (implies -M).

Device blocking

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

On *this* particular tar, the defaults are -f /dev/rmt0 and -b 20.

-b blocks --block-size=blocks Block size of blocks x 512 bytes.

This option is used to specify a blocking factor for the archive. When reading or writing the archive, tar, will do reads and writes of the archive in blocks of NUMBER*512 bytes.

The default blocking factor is set when tar is compiled, and is typically 20.

Blocking factors larger than 20 cannot be read by very old versions of tar, or by some newer versions of tar running on old machines with small address spaces.

With a magnetic tape, larger blocks give faster throughput and fit more data on a tape (because there are fewer inter-record gaps). If the archive is in a disk file or a pipe, you may want to specify a smaller blocking factor, since a large one will result in a large number of null bytes at the end of the archive.

When writing cartridge or other streaming tapes, a much larger blocking factor (say 126 or more) will greatly increase performance. However, you must specify the same blocking factor when reading or updating the archive.

With GNU tar the blocking factor is limited only by the maximum block size of the device containing the archive, or by the amount of available virtual memory.

--block-compress Block the output of compression for tapes.

-i --ignore-zeros Ignore blocks of zeros in archive (means EOF).

The -i option causes tar to ignore blocks of zeros in the archive. Normally a block of zeros indicates the end of the archive, but when reading a damaged archive, or one which was created by cat-ing several archives together, this option allows tar to read the entire archive. This option is not on by default because many versions of tar write garbage after the zeroed blocks.

Note that this option causes tar to read to the end of the archive file, which may sometimes avoid problems when multiple files are stored on a single physical tape.

-B --read-full-blocks Reblock as we read (for reading 4.2BSD pipes).

If -B is used, tar will not panic if an attempt to read a block from the archive does not return a full block. Instead, tar will keep reading until it has obtained a full block.

This option is turned on by default when tar is reading an archive from standard input, or from a remote machine. This is because on BSD Unix systems, a read of a pipe will return however much happens to be in the pipe, even if it is less than tar requested. If this option was not used, tar would fail as soon as it read an incomplete block from the pipe.

This option is also useful with the commands for updating an archive.

Archive format selection

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

-V name --label=name Create archive with volume name name.

This option causes tar to write out a volume header at the beginning of the archive. If -M is used, each volume of the archive will have a volume header of NAME Volume N, where N is 1 for the first volume, 2 for the next, and so on.

-o --old-archive --portability Write a V7 format archive (not ANSI).

This option causes tar to write an old format archive, which does not include information about directories, pipes, fifos, contiguous files, or device files, and specifies file ownership by numeric user- and group-ids rather than by user and group names. In most cases, a new format archive can be read by an old tar program without serious trouble, so this option should seldom be needed. When updating an archive, do not use -o unless the archive was created with the -o option.

-z --gzip --ungzip Filter the archive through gzip.

It is not exact to say that GNU tar is to work in concert with gzip in a way similar to zip, say. Surely, it is possible that tar and gzip be done with a single call, like in:

tar cfz archive.tar.gz subdir

to save all of subdir into a gzip'ed archive. Later you can do:

tar xfz archive.tar.gz

to explode and unpack.

The difference is that the whole archive is compressed. With zip, archive members are archived individually. tar method yields better compression. On the other end, one can view the contents of a zip archive without having to decompress it. As for the tar and gzip tandem, you need to decompress the archive to see its contents. However, this may be done without needing disk space, by using pipes internally:

tar tfvz archive.tar.gz

About corrupted compressed archives, gzip'ed files have all redundancy out (for compression). The adaptative nature of the compression scheme as the file goes make all information important for the future of the file, I mean that the compression tables are implicitly spread all over the file. If you loose a few blocks, you loose synchronization with how the compression tables are being dynamically constructed, there is not much hope that you could fall back on your feet again later in the archive.

There are pending suggestions for having a per-volume or per-file compression in GNU tar. This would allow for viewing the contents without decompression, and for resynchronizing decompression at every volume or file, in case of corrupte archives. Doing so, we might loose some compressibility. But this would have make recovering easier. So, there are pros and cons. We'll see!

-Z --compress --uncompress Filter the archive through compress.

The archive should be compressed as it is written, or decompressed as it is read, using the compress program. This option works on physical devices (tape drives, etc.) and remote files as well as on normal files; data to or from such devices or remote files is reblocked by another copy of the tar program to enforce the specified (or default) block size. The default compression parameters are used; if you need to override them, avoid the -z option and run compress explicitly.

If the -z option is given twice, or the --compress-block option is used, tar will pad the archive out to the next block boundry (*Note General Options::). This may be useful with some devices that require that all write operations be a multiple of a certain size.

Note that the -z option will not work with the -M option, or with the -u, -r, -A, or -D commands.

--use-compress-program=prog Filter through prog (must accept -d).

Local file selection

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

-C dir --directory dir Change to directory dir.

This option causes tar to change into the directory DIR before continuing. This option is usually interspersed with the files tar is to work on. For example,

tar -c iggy ziggy -C baz melvin

will place the files iggy and ziggy from the current directory on the tape, followed by the file melvin from the directory baz. This option is especially useful when you have several widely separated files that you want to store in the same directory in the archive.

Note that the file melvin is recorded in the archive under the precise name melvin, not baz/melvin. Thus, the archive will contain three files that all appear to have come from the same directory; if the archive is extracted with plain tar -x

, all three files will be created in the current directory.

Contrast this with the command:

tar -c iggy ziggy bar/melvin

which records the third file in the archive under the name bar/melvin so that, if plain tar -x is used, the third file will be created in a subdirectory named bar.

Suppose that, without changing your current directory, you want to call tar to dump files from /users/ctd/dipp say. Detaring elsewhere will produce the same subdirectory structure, and you do not always want that. Then -C is for you. You could do things like:

tar cfC archive.tar /users/ctd/dipp .

(the period means the current directory, once the -C obeyed).

Some people might want some option to untar everything flat in the current directory. This is so rarely proper that I doubt such an option would be really useful. It would only help getting around improper tar usage, it might even encourage improper usage. In general, -C might be used to produce archives with a cleaner structure.

-T filename --files-from=filename Get names to extract or create from file filename.

Instead of taking the list of files to work on from the command line, the list of files to work on is read from the file filename. If filename is given as -, the list is read from standard input. Note that using both -T - and -f - will not work unless you are using the -c command.

--null This option causes -T to read filenames terminated by a NUL instead of a newline, so files whose names contain newlines can be archived using -T. The --null option is just like the one in GNU xargs and cpio, and is useful with the -print0 predicate of GNU find. In tar, --null also causes -C options to be treated as filenames to archive, in case there are any files out there called -C.

--exclude=file Exclude file file.

-X file --exclude-from=file Exclude files listed in file.

This option causes tar to read a list of filename regular expressions, one per line, from the file file; tar will ignore files with those names. Thus if tar is called as tar -c -X foo . and the file foo contains *.o none of the files whose names end in .o in the current directory (or any subdirectory of the current directory) will be added to the archive. Multiple -X options may be given.

-P --absolute-paths Do not strip leading /s from file names.

By default, GNU tar uses the feature of dropping leading / on input or output. This is an important feature. A few months ago, a visitor here gave a tar tape to an operator to restore; the operator used SUN tar instead of GNU tar, and the result was that it replaced large portions of our /bin and friends with versions from the tape; needless to say, we were unhappy about having to recover the file system from backup tapes.

This option should be used when the absolute pathname of a file should be preserved in the archive. tar normally strips the leading / from the name of the file, thus making /usr/foo/bar/baz into usr/foo/bar/baz. Using the -P option keeps the pathname intact, and is useful in that it is not necessary to change to the root directory when extracting files.

-h --dereference Dump instead the files symlinks point to.

If -h is used, when tar encounters a symbolic link, it will archive the linked-to file, instead of simply recording the presence of a symbolic link. If the linked-to file is archived again, an entire second copy of it will be archived, instead of a link. This could be considered a bug.

-l --one-file-system Stay in local file system when creating archive.

This option causes tar to not cross filesystem boundaries when archiving parts of a directory tree. This option only affects files that are archived because they are in a directory that is archived; files named on the command line are archived regardless, and they can be from various file systems.

This option is useful for making full or incremental archival backups of a file system, as with the Unix dump command.

Files which are skipped due to this option are mentioned on the standard error.

-K name --starting-file=name Begin at file name in the archive.

The -K option causes tar to begin extracting or listing the archive with the file FILENAME, and to consider only the files starting at that point in the archive. This is useful if a previous attempt to extract files failed when it reached FILENAME due to lack of free space. (This assumes, of course, that there is now free space, or that you are now extracting into a different file system.)

-N date --newer=date --after-date=date Only store files newer than date.

This option causes tar to only work on files whose modification or inode-changed times are newer than the date given. The main use is for creating an archive; then only new files are written. If extracting, only newer files are extracted.

Remember that the entire date argument should be quoted if it contains any spaces.

The date is parsed using getdate.

Informative output

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

--help Print this help, then exit.

--version Print tar program version number, then exit.

This option causes tar to print out its version number to the standard output, and do nothing else. It has no equivalent short option name.

-v --verbose Verbosely list files processed.

This option causes tar to be verbose about the actions it is taking.

Normally, the -t command to list an archive prints just the file names (one per line) and the other commands are silent.

-tv prints a full line of information about each file, like the output of ls -l. -v with any other command (aside from -t) prints just the name of each file operated on.

The output from -v appears on the standard output except when creating or updating an archive to the standard output, in which case the output from -v is sent to the standard error.

--checkpoint Print directory names while reading the archive.

--totals Print total bytes written while creating archive.

-R --record-number Show record number within archive with each message.

If -R is used, tar prints, along with every message it would normally produce, the record number within the archive where the message occurred. This option is especially useful when reading damaged archives, since it helps pinpoint the damaged sections.

This can also be useful when making a log of a file-system backup tape, since the results allow you to find the file you want to retrieve on several backup tapes and choose the tape where the file appears earliest (closest to the front of the tape).

-w --interactive --confirmation Ask for confirmation for every action.

This option causes tar to print a message for each action it intends to take, and ask for confirmation on the terminal. To confirm, you must type a line of input. If your input line begins with y, the action is performed, otherwise it is skipped.

The actions which require confirmation include adding a file to the archive, extracting a file from the archive, deleting a file from the archive, and deleting a file from disk.

If tar is reading the archive from the standard input, tar will open the file /dev/tty to ask for confirmation on.

Old classification of options

The following information may be obsolete or inaccurate. Please take it with a grain of salt (or even two :-) for the time being.

The information here is to be revised and merged into the remainder of this document, possibly altering its structure.

Options could be regrouped in three categories:

General Options Options that are always meaningful. Creation Options Options for creating or updating an archive. Extraction Options Options for listing or extracting files.

Here are the options that are always meaningful.

-B NUMBER, --block-size NUMBER -f FILENAME, --file FILENAME -C DIR, --directory DIR -M, --multi-volume -N DATE, --after-date DATE -R, --record-number -T FILENAME, --files-from FILENAME -v, --verbose --version -w, --interactive -X FILE, --exclude FILE -z, -Z, --compress, --uncompress

Here are the options for creating or updating an archive. These options are used to control which files tar puts in an archive, or to control the format the archive is written in (*Note Format::). Except as noted elsewhere, these options are useful with the -c, -r, -u, -A, and -D commands. Also note that the -B option, (*Note Extraction Options::), is also useful with the -r, -u, -A, and -D commands.

-G, --incremental -h, --dereference -l, --one-file-system -o, --old-archive --old, --portability -S, --sparse -V NAME, --volume NAME -W, --verify

Here are the options for listing or extracting files. The options in this section are meaningful with the -x command. Unless otherwise stated, they are also meaningful with the -t command.

-B, --read-full-blocks -G, --incremental -i, --ignore-zeros -k, --keep-old-files -K FILENAME, --starting-file FILENAME -m, --modification-time -O, --to-stdout -p, --same-permissions, --preserve-permissions -P, --absolute-paths -s, --same-order, --preserve-order --preserve

 

 

Email addresses listed on this site may  NOT be used for unsolicited commercial email.

Ready-to-Run Software, Inc Privacy Statement

Portions (c)Copyright, 1996-2005 by Ready-to-Run Software, Inc
(All rights reserved.)
212 Cedar Cove
Lansing, NY 14882
Phone: 607 533 UNIX (8649)
Fax: 607 533 4002