Problem with simbolic link

Submitted by Anonymous
on December 25, 2007 - 4:03am

I am facing a strange behavior when I create the same symbolic twice. The followins is what the situation ..

[root@bglr1 tmp]# mkdir -p /tmp/tmp/{1,2}
[root@bglr1 tmp]# ln -s /tmp/tmp/2 /tmp/tmp/1/2
[root@bglr1 tmp]# ls -lR /tmp/tmp
.:
total 8
drwxr-xr-x 2 root root 4096 Dec 24 20:34 1
drwxr-xr-x 2 root root 4096 Dec 24 20:33 2

./1:
total 0
lrwxrwxrwx 1 root root 10 Dec 24 20:34 2 -> /tmp/tmp/2

./2:
total 0
[root@bglr1 tmp]# ln -s /tmp/tmp/2 /tmp/tmp/1/2
[root@bglr1 tmp]# ls -lR /tmp/tmp
.:
total 8
drwxr-xr-x 2 root root 4096 Dec 24 20:34 1
drwxr-xr-x 2 root root 4096 Dec 24 20:34 2

./1:
total 0
lrwxrwxrwx 1 root root 10 Dec 24 20:34 2 -> /tmp/tmp/2

./2:
total 0
lrwxrwxrwx 1 root root 10 Dec 24 20:34 2 -> /tmp/tmp/2
[root@bglr1 tmp]#

here what happens is, when I execute link command once, every thing is fine. but when I execute once again. It creats a link in wrong place. Now I can see two links as follows

/tmp/tmp/1/2->/tmp/tmp/2
/tmp/tmp/2/2->/tmp/tmp/2

It may be a correct behavior. But I am not able to related the concepts to this :-)

When you do this: ln -s

Anonymous (not verified)
on
December 25, 2007 - 4:35am

When you do this:
ln -s /tmp/tmp/2 /tmp/tmp/1/2
ln -s /tmp/tmp/2 /tmp/tmp/1/2

The first time, /tmp/tmp/1/2 does not exist, so it is created. The second time, /tmp/tmp/1/2 is a symbolic link pointing to the directory /tmp/tmp/2.

When you supply a directory (or in this case, a symlink to one) as the last argument to ln, it will put into that directory, symbolic links to all the other arguments.

See: http://linux.die.net/man/1/ln (3rd form)

Thanks a lot for the reply.

Anonymous (not verified)
on
December 25, 2007 - 11:41pm

Thanks a lot for the reply.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.