Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

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.

share|improve this answer
14  
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
2  
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
    
Instead of going down a directory and the up again, you can also just do ln -s ./file linkname since . refers to the current directory. –  pduersteler Mar 12 '13 at 13:36

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
share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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