Go to the previous, next section.
(This message will disappear, once this node revised.)
When the names of files or members specify directories, the operation of
tar
is more complex. Generally, when a directory is named,
tar
also operates on all the contents of the directory,
recursively. Thus, to tar
, the file name `/' names the
entire file system.
To archive the entire contents of a directory, use `--create' (`-c') or `--append' (`-r') as usual, and specify the name of the directory. For example, to archive all the contents of the current directory, use `tar --create --file=archive-name .'. Doing this will give the archive members names starting with `./'. To archive the contents of a directory named `foodir', use `tar --create --file=archive-name foodir'. In this case, the member names will all start with `foodir/'.
If you give tar
a command such as `tar --create
--file=foo.tar .', it will report `tar: foo.tar is the archive; not
dumped'. This happens because the archive `foo.tar' is created
before putting any files into it. Then, when tar
attempts to add
all the files in the directory `.' to the archive, it notices that
the file `foo.tar' is the same as the archive, and skips it. (It
makes no sense to put an archive into itself.) GNU tar
will
continue in this case, and create the archive as normal, except for the
exclusion of that one file. Other versions of tar
, however, are
not so clever, and will enter an infinite loop when this happens, so you
should not depend on this behavior. In general, make sure that the
archive is not inside a directory being dumped.
When extracting files, you can also name directory archive members on
the command line. In this case, tar
extracts all the archive
members whose names begin with the name of the directory. As usual,
tar
is not particularly clever about interpreting member names.
The command `tar --extract --file=archive-name .' will not
extract all the contents of the archive, but only those members whose
member names begin with `./'.
Go to the previous, next section.