Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
root@server # tar fcz bkup.tar.gz /home/foo/
tar: Removing leading `/' from member names

How can I solve this problem and keep the / on file names ?

share|improve this question
What exactly is not working as expected? – Joachim Isaksson Dec 23 '12 at 12:48
5  
It is not a problem. You do not want leading slashes in a tar archive. Seriously. If you want to extract an archive to your system root, specify -C / when extracting it. – ThiefMaster Dec 23 '12 at 15:31

migrated from stackoverflow.com Dec 23 '12 at 15:32

4 Answers

up vote 2 down vote accepted

Use the --absolute-names or -P option to disable this feature.

share|improve this answer

I think it’s because tar takes relative paths. Try with the -P switch.

share|improve this answer

That's actually a feature, not a problem. Archives with absolute locations are a security risk. Attackers could use such archives to trick users into installing files in critical system locations.

Yes, you could use -P. But what's wrong with allowing tar to remove the forward slash, and simply requiring the user of the archive to explicitly do the extraction in the root directory? Then they're consciously impacting critical system locations, and can't do it by accident.

share|improve this answer

If you want to get rid of "Removing leading `/' from member names" being printed to STDERR, but still want to leave off those leading slashes as tar wisely does by default, I saw an excellent solution here by commenter timsoft.

The solution involves using -C option to change directory to the root (/), then specifying the file tree to archive without a leading slash, because now you only need a relative path. This does the same thing as a normal tar create command, but no stripping is needed:

tar fcz bkup.tar.gz -C / home/foo/
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.