views:

312

answers:

4

Is it a good practice that links should always point to absolute path rather than pointing from current directory?

I am talking this with reference - where i need to maintain software and all its previous versions should always point to latest version.

+1  A: 

Define "good practice". Whether a link points to an absolute path or not depends on the relationship between the files.

If the files are always in the same relative positions, but could be moved around (eg aliases in bin/), they should be relative. If the actual file is in a known location (eg, you want to link a default config file to ~/.config), then use an absolute path.

John Millikin
A: 

Depends on what you want to do. My Linux system has both kinds of symlinks.

find /usr /bin /lib -type l -print0 | xargs -0 ls -ld | less
sigjuice
A: 

I don't think there's a "good practice" for that. There are different use cases.

For example if I store a tree with a program installed locally in /home/.../application, I may want to symlink "default config" to some specific config without an absolute path. That way, when I move the whole tree to /home/.../application-other-instance, the link to the config file stays correct.

On the other hand, if I want to reference some global file in /etc/... in a local dir, I will do it with an absolute path symlink. That guarantees that I'm pointing to the same file anywhere I move.

Just think what do you want to achieve, and the relative / absolute path decision will be either obvious, or irrelevant. Only "never do that" rule is probably: Never link to anything in root dir /xxx, via ../../../../../../../xxx

viraptor
A: 

I don't think I can agree with that as a generalization.

There are definitely cases where a relative link makes more sense. With a directory tree of a project, for example. If the project is backed-up, or moved (even duplicated) into another place, absolute links could be confusing and/or disastrous.

Even if you are talking about system-wide tools, there will be cases where relative links make sense, and other times not. Compare having a link to a very generic tool, like grep , versus something like multiple versions and target flavors of the gnu compiler tools living on the same host. In the latter case, absolute links to the specific tool versions will probably required.

It all comes back to what you really want to do in each case. The general answer is that there is no generalized answer.

digijock