Does the target in ln -s have to be a full path?

1409
fangzhzh

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.

4
почему вы хотите делать жесткие ссылки? Они почти никогда не являются хорошей идеей. bmargulies 12 лет назад 0
Вы спрашиваете о `ln -s`, но ваш пример использует просто` ln`; с чем ты имеешь дело? Jonathan Leffler 12 лет назад 0
Я хочу сделать символическую ссылку, опечатка там. 12 лет назад 0
@bmargulies Это не правда. У них просто разные цели. glglgl 12 лет назад 1

2 ответа на вопрос

5
MPi

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.
2
sarnold

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.

извини, опечатка. Я просто хочу сделать символическую ссылку. Я сталкиваюсь с этой проблемой при создании символической ссылки. 12 лет назад 0
Ах, тогда [MPI имеет ваш ответ] (http://stackoverflow.com/a/10427564/377270). Пожалуйста, используйте это как возможность для обучения копировать и вставлять то, что вы на самом деле пытались, а не только то, что вы думали, что пытались. :) sarnold 12 лет назад 1
эта возможность обучения более ценна, чем «знание». 12 лет назад 0
Хе-хе, я рад, что ты так думаешь :) sarnold 12 лет назад 0

Похожие вопросы