Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Previous: directory, Up: one


6.8.2 Absolute File Names

--absolute-names
-P
Do not strip leading slashes from file names, and permit file names containing a .. file name component.

By default, GNU tar drops a leading ‘/’ on input or output, and complains about file names containing a .. component. This option turns off this behavior.

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.1

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 files. Preserves leading slash when 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:

     $ (cd / && tar -c -f archive.tar home)
     $ tar -c -f archive.tar -C  / home

Footnotes

[1] 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.


 
 
  Published under the terms of the GNU General Public License Design by Interspire