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.
touch a
ln -s a b

The above command creates a symbolic link which originates from "b" and points to "a":

lrwxrwxrwx  1 root root     1 Dec 20 23:41 b -> a

The question is that how to say that correctly? If it is correct, then why is the reverse direction i.e "b" is the source and "a" is the target. And which entity is the symbolic link itself?

share|improve this question

3 Answers 3

up vote 6 down vote accepted

The syntax of ln is parallel to that of cp and mv.

cp a b

creates a file called b containing the content of file a.

ln –s a b

creates a symbolic link called b that points to a (i.e., provides access to the content of a).  Similarly,

ln a b

creates a hard link (a new directory entry) called b that refers to the file a (which must already exist, unlike the case of the symbolic link).  In all cases, the first argument is the source (of the data) and the second argument is the thing that the command creates.

share|improve this answer
    
Thank you. I originally thought not about the contents, but where it points: ln -s a<-b. That is why I called it "reversed". But now I understand. –  dash17291 Dec 20 '12 at 23:14
    
Id be careful with the talk about hard links. A symlink is a special filetype, so there is a source and a destination. A hardlink is just a second name for a file. The two hard links are equivalent. The second hard link does not refer to a, but to the same data that a refers to. a refers to the data, b refers to the data. There is no direction. –  Rich Homolka Dec 20 '12 at 23:23
2  
@Rich: OK, I should have said, “creates a hard link (a new directory entry) called b that refers to the file also referenced by the name (directory entry) a”. –  Scott Dec 20 '12 at 23:35
    
For the life of me, I could never remember which order the files go in. It never occurred to me to think of it like cp or mv. –  Pak Aug 17 at 18:47
    
GNU cp even has -s to create symlinks instead of copying (and likewise -l for hard links). –  deltab Oct 31 at 3:16

dash, you're interpreting the output wrong.

In the output of ls, think of the arrow, and its direction, as "points to".

Read b points at a. Makes b the symbolic link. Easy, really.

share|improve this answer
    
OK. According to man ln the first parameter is the target and the second is the link name which is to be created. I interpreted the target as the "source" like when using cp <source> <dest>, because I think of it that it is the one (in cp's or rsync's notation for example) which must exist before the operation and we specify that first. –  dash17291 Dec 20 '12 at 23:10
    
It is the source, similar to a copy operation, I assume it's called a "target" because the link will point at it. Makes sense to me, anyway. I still think you're just interpreting the output of ls wrong. –  tink Dec 20 '12 at 23:25

Just remember that ls -l displays the link in reverse mode.

To know where a link point to, you can do :

$ file b
b: symbolic link to `a'
share|improve this answer

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.