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 ?
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
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: