I need a symlink that resolves relative to the directory it is placed in. What command is used to create such a thing?

link|improve this question
feedback

2 Answers

I've worked it out:

  1. Go to the directory you want the link to reside in
  2. run the command ln -s ../some/other/file linkname

To help in understanding: The path you provide is stored with the file. When you access the file the stored path is looked up and expanded relative to the file. It does not know what directory you were in when you created the link.

link|improve this answer
12  
No you don't. You just have to make sure that you specify the location relative to the link name instead of your current directory. – Ignacio Vazquez-Abrams May 28 '10 at 8:26
1  
To help in understanding: The path you provide is stored with the file. When you access the file the stored path is looked up and expanded relative to the file. It does not know what directory you were in when you created the link. – Marian May 30 '10 at 14:27
exactly equivalent: ln -s ../some/other/file /some/dir/linkname – sehe Dec 22 '11 at 12:07
feedback

Relative links were tricky for me on OS X, i.e.

~/Dropbox/git/dave-bot $ ln -s ../codyhess/bin ~/bin
~/Dropbox/git/dave-bot $ ln -s ../codyhess/bin/ ~/bin

both did not work (something was created but it wasn't a directory). I created the desired link by using absolute paths.

~/Dropbox/git/dave-bot $ ln -s ~/Dropbox/git/codyhess/bin/ ~/bin
link|improve this answer
It's a viable solution, so doesn't need to be a comment. This can stay as a separate answer. – slhck Oct 5 '11 at 20:43
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.