I got an error when I append > /dev/null to tar command, anyone know what's going on in second example?
good:
tar -cvf $kname /var/www bad:
tar -cvf $kname /var/www > /dev/null error:tar: Removing leading `/' from member names 64 Answers
The "good" version is also displaying the same message you've just missed it.
If you don't like the behaviour, search for "leading", in manual. First hit:
-P, --absolute-names don't strip leading '/'s from file names 6This is because your file ($kname) has leading /.
To fix that, you may specify -C to change the directory, instead of specifying full path of the archive file.
It might be best to leave your files without the '/' in the backup and just ignore the error message. Tar does this as a safety precaution, because if you untar the file, it will automatically place the files back in the original directory. This can be dangerous and most people want to avoid this. Personally, I would be happy with the fact that it removed the '/' and then your restore will be relative and not absolute directory path. Then you can manually move the files into the right place, or a different place. Just posting this so people are aware and don't inadvertently replace their original files.
1my version of tar does not extract an archive created with -P (--absolute-names) to the original location. this is only true for untar with argument -P