Previous: Changing the Working Directory, Up: Crossing File System Boundaries [Contents][Index]
By default, GNU tar drops a leading ‘/’ on
input or output, and complains about file names containing a ‘..’
component. There is an option that turns off this behavior:
Do not strip leading slashes from file names, and permit file names containing a ‘..’ file name component, or that escape the extraction directory.
When tar extracts archive members from an archive, it strips any
leading slashes (‘/’) from the member name. This causes absolute
member names in the archive to be treated as relative file names. This
allows you to have such members extracted wherever you want, instead of
being restricted to extracting the member in the exact directory named
in the archive. For example, if the archive member has the name
/etc/passwd, tar will extract it as if the name were
really etc/passwd.
File names containing ‘..’ can cause problems when extracting, so
tar normally warns you about such files when creating an
archive, and prevents attempts to extract such files if that would
affect files outside the working directory.
Other tar programs do not do this. As a result, if you
create an archive whose member names start with a slash, they will be
difficult for other people with a non-GNU tar
program to use. Therefore, GNU tar also strips
leading slashes from member names when putting members into the
archive. For example, if you ask tar to add the file
/bin/ls to an archive, it will do so, but the member name will
be bin/ls21.
If you use the --absolute-names (-P) option,
tar will do none of these transformations.
By default tar prints out a message about removing the ‘/’ from
file names. This message appears once per GNU tar
invocation. It represents something which ought to be told; ignoring
what it means can cause very serious surprises, later.
However, to suppress this message change to
the / directory first, and then avoid absolute notation.
For example:
$ tar -c -f archive.tar -C / home
If you use the dangerous options --absolute-names
(-P) or --dereference (-h),
symbolic links containing ‘..’ or leading ‘/’ can cause
problems when extracting, so tar extracts them last;
it may create empty files as placeholders during extraction.
Although these placeholders prevent problems if you are extracting
into an empty directory, they do not suffice for nonempty directories.
See Integrity, for some of the security-related implications
of using these dangerous options.
A side effect of this is that when --create is used with --verbose the resulting output is not, generally speaking, the same as the one you’d get running tar --list command. This may be important if you use some scripts for comparing both outputs. See listing member and file names, for the information on how to handle this case.
Previous: Changing the Working Directory, Up: Crossing File System Boundaries [Contents][Index]