Go to the previous, next section.
(This message will disappear, once this node revised.)
While the `--append' (`-r') option is useful for updating files in an
archive, to keep an archive current with `--append' (`-r') you must
first use the `--compare' (`-d') or `--list' (`-t') options to determine
what files have been changed (or be willing to waste space by adding
identical copies of archived files to the ends of archives). It is
simpler to use the `--update' (`-u') operation, and let tar
do
the work for you.
The `--update' (`-u') option causes tar
to add files to the end of
an archive, just like the `--append' (`-r') option. When you invoke
tar
with the `--update' (`-u') option specified you must specify
file name arguments. Unlike `--append' (`-r'), the `--update' (`-u') option
causes tar
to check the archive to be updated to see if the
specified file is already stored. If the file (or one with the same
name) is already in the archive, tar
checks the modification
date of the file in the archive and compares it to the file of the
same name in the file system. The file is only appended to the
archive if it is new or if its modification date has changed to a
later one.
FIXME: xref After-Date
To see the `--update' (`-u') option at work, create a new file,
`classical', in your practice directory, and add a line to the
file `blues', using any text editor. Then invoke tar
with
the `--update' (`-u') operation and the `--verbose' (`-v') option specified,
using the names of all the files in the practice directory as file name
arguments:
% tar --update --verbose --file=records blues folk rock classical blues classical %
Because we have specified verbose mode, tar
prints out the
names of the files it is working on, which in this case are the names
of the files that needed to be updated. If you now invoke tar
with the `--list' (`-t') operation specified, to generate a listing of
the files in the archive, you will see that `blues' and
`classical' have been added to its end.
[The reason tar
does not overwrite the older file when updating
it is because writing to the middle of a section of tape is a difficult
process. Tapes are not designed to go backward. Even if they were,
imagine what would happen if the newer version were longer than the
older one.]
To keep archive members up to date with their counterparts of the
same name in the file system, use the `--update' (`-u') option.
This adds a specified file to an archive if no file of that
name is already stored in the archive. If there is already an archive
member with the same name, tar
checks the modification date of the
archive member, and adds the file only if its modification date is
later. If a file is stored in the archive but no longer exists under
the same name in the active file system, tar
reports an error.
You could use the `--append' (`-r') option to keep an archive current, but do so you would either have to use the `--compare' (`-d') and `--list' (`-t') options to determine what files needed to be re-archived (which could waste a lot of time), or you would have to be willing to add identical copies of already archived files to the archive (which could waste a lot of space).
You must use file name arguments with the `--update' (`-u') operation--if
you don't specify any files, tar
won't act on any files.
To see the `--update' (`-u') option at work, create a new file,
`~/practice/classical', and modify the file `~/practice/blues' (you can
use a text editor, such as Emacs, to do both these things). Then, with
`practice' as your working directory, invoke tar
with the
`--update' (`-u') option, using the
names of all the files in the practice directory as file name
arguments, and specifying the `--verbose' (`-v') option:
% tar --update --verbose --file=records blues folk rock classical blues classical %
Because you specified verbose mode, tar
printed out the names of the
files it acted on. If you now list the archive members of the archive,
(`tar --list --file=records'), you will see that the file `classical' and
another version of the file `blues' have been added to `records'.
Note: When you update an archive, tar
does not overwrite old
archive members when it stores newer versions of a file. This is
because archive members appear in an archive in the order in which they
are stored, and some archive devices do not allow writing in the middle
of an archive.
Go to the previous, next section.