[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.10.2 Absolute File Names

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:

--absolute-names
-P

Do not strip leading slashes from file names, and permit file names containing a ‘..’ file name component.

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 rejects attempts to extracts such files.

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/ls(16).

Symbolic links containing ‘..’ or leading ‘/’ can also cause problems when extracting, so tar normally extracts them last; it may create empty files as placeholders during extraction.

If you use the ‘--absolute-names’ (‘-P’) option, tar will do none of these transformations.

To archive or extract files relative to the root directory, specify the ‘--absolute-names’ (‘-P’) option.

Normally, tar acts on files relative to the working directory—ignoring superior directory names when archiving, and ignoring leading slashes when extracting.

When you specify ‘--absolute-names’ (‘-P’), tar stores file names including all superior directory names, and preserves leading slashes. If you only invoked tar from the root directory you would never need the ‘--absolute-names’ option, but using this option may be more convenient than switching to root.

--absolute-names

Preserves full file names (including superior directory names) when archiving and extracting files.

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.

Some people, nevertheless, do not want to see this message. Wanting to play really dangerously, one may of course redirect tar standard error to the sink. For example, under sh:

 
$ tar -c -f archive.tar /home 2> /dev/null

Another solution, both nicer and simpler, would be to change to the ‘/’ directory first, and then avoid absolute notation. For example:

 
$ tar -c -f archive.tar -C / home

See section Integrity, for some of the security-related implications of using this option.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Sergey Poznyakoff on October, 20 2013 using texi2html 1.78.