5

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.

slhck
  • 235,242
fangzhzh
  • 151

2 Answers2

6

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.
onionjake
  • 353
MPi
  • 303
2

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.

sarnold
  • 3,828