How to dereference symlinks on tar file extraction.

Well the title pretty much says it all. A guy at work wants to tar a directory containing soft links, and when he wants to dereference the links when the tar is extracted and not when it is created. The file that is being linked to is in the directory so everything you need to dereference the link is there and the computer isn’t going to try to copy a file it doesn’t have.

Since he wants the copy to be made when the file is extracted and not when it is created, a -h option won’t do what he wants.

Google is only coming back with several copies of the tar man page. The only idea I can think of is just to write a script that converts soft links to actual copies of the file and run it after you extract the tar, but I’d rather not do that if I don’t have to.

You can’t extract a file that isn’t inside the tar file, it must be done when created.

What do you mean by “dereference”?

A symbolic link is indeed a reference to another file (it in fact being a file wich has as contents the name, including an explicit or implicit path, of another file). The fact that it is of the type Symbolic Link (the l in the first column of an ls -l listing shows that) makes that that reference is understood as it should. When you dereference, it means simply that you delete that symbolic link file: no more reference from a to b! Mostly that is simply called “remove” or “delete” of the symlink.

When that is what you want, I guess I would read* man find *to find all symbolic links from a certain point in the directory tree downwards and then let find rm them.

Your terminology is causing you confusion. There is no dereferencing on extraction, only on use.

What matters is whether the symbolic link is archived as is. By default, without -h, it is.

Then one of two cases applies. The target of the link is in the archive. In that case everything is ok. Otherwise you have a dangling symlink.

So if as you say the target is also in the archive, you don’t need to do anything special.