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've tried to invoke ln in directory ~/download as this:

ln -s ./abc ~/abc [EDITED]

but it does't work.
I do ls -al in my home and get wrong link of abc.

ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)

So my question here is: Does ln need full path of the target? I didn't find any document or hint in the man page. If so, where can I get further information.

share|improve this question

migrated from stackoverflow.com May 16 '12 at 9:01

This question came from our site for professional and enthusiast programmers.

    
why do you want to make hardlinks? They're nearly never a good idea. –  bmargulies May 3 '12 at 1:21
    
You ask about ln -s but your example uses just ln; which are you dealing with? –  Jonathan Leffler May 3 '12 at 3:36
    
I want to make a symbolic link, typo there. –  fangzhzh May 3 '12 at 8:09
1  
@bmargulies That's not true. They just have different purposes. –  glglgl May 3 '12 at 8:33

2 Answers 2

up vote 3 down vote accepted

It’s quite simple: You create a symbolic link in ~ that points to ./abc in that directory. The pathname of a symbolic link must be valid in the context of the directory it is in¹. If you indeed want to point to the file that is in your now current directory, you must use the full path.


  1. The link must be valid if you want to use it. It can point into nothingness or to a file that does not exist. That can be a good thing, as the file might have been there before and can reappear any time, and the symbolic link will then point to it again.
share|improve this answer

ln can take either absolute or relative pathnames; the difference matters for symbolic links, but since you asked to make a hard link, it will resolve to the same file either way.

Check the ls -li output on ~/abc and ~/download/abc -- you'll see that the link count is 2 and the inode number is the same for both files.

share|improve this answer
    
sorry, typo. I just want make a symbolic link. I encounter this problem when creating symbolic link. –  fangzhzh May 3 '12 at 8:10
1  
Ah, then MPI has your answer. Please take this as a learning opportunity to copy and paste what you actually tried, not just what you think you tried. :) –  sarnold May 3 '12 at 22:03
    
this learning opportunity is more precious than "ln" knowledge. –  fangzhzh May 4 '12 at 1:26
    
Hehe, I'm glad you think so :) –  sarnold May 4 '12 at 1:27

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.