[tar] Removing leading '/' from member names

If you invoke tar in this form:

tar cjf /backup/etc.tar.bz2 /etc

STDERR will warn with message saying "Removing leading `/' from member names". Although, you can redirect STDERR to /dev/null, doing so can result in missed errors. To eliminate this warning you could use:


1) -C DIR switch for tar. It is used to implicitly change to DIR directory and eliminates the warning. Example:

tar cjf /backup/etc.tar.bz2 -C / etc

If you want to tar multiple directories (for example /var/log /etc /boot) use the following construction:

tar cjf /backup/backup.tar.bz2 -C / var/log etc boot

2) Another solution, is use tar with the -P or –absolute-names switch. They do the same thing: leave the leading / in the archived files:

tar cjPf /backup/backup.tar.bz2 /etc /boot /var/log

When you untar the archive without -P, the leading / will still equate to your current working directory