I have a folder and within it there are many links.

I make those links absolute, so that I can move them about within the folder and they still point to the same data. Relative links would break if I moved them within the folder.

But the problem arises when i move the folder to another system, say an external hard drive or server. Then all the absolute links have the wrong base in their address.

If it were possible to have the links have a variable within their address pointing, then that would solve this problem.

Is that possible?

  • Could hardlinks (also note the answer linked in the comment) help in this situation?
    – sr_
    Jul 24, 2012 at 13:01
  • I don't see how.
    – john-jones
    Jul 24, 2012 at 13:12

3 Answers 3


I guess the answer to your problem are variant symbolic links, though they only exist on DragonFlyBSD to the best of my knowledge (see that previous question: Dynamic Symlinks )


The command

symlinks -cr folder

will convert all absolute symlinks under folder to relative. So you can then move the entire folder with the links pointing to their correct relative location (assuming they all point to other files within folder)

Then something like...

find folder -type l -exec echo 'LNK=$(readlink -f "{}");rm -fv "{}";ln -sv "$LNK" "{}"' ';' > xlinks
chmod +x xlinks

... will convert all the links from relative to absolute.

(Note: I gave up trying to execute the command directly from find. Anyway, it gives you a chance to check what it's going to do!)


You can't have your cake and eat it. Relative links are generally better, because you can move them around and copy all or part of the tree to another location.

If you move a file within the hierarchy, it's not clear what should happen: if there are links a -> b and c -> d, and you run mv b d, should a now point to d? It's up to you to decide. Symbolic links point to a location; if you want to point to a file, use a hard link (this is not possible for directories).

If you move a file but still want to find it under its old location, add a symbolic link from the old location to the new location.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .