Linux – How to create a symlink which points to another symlink

linuxsshsymbolic-link

Is there any way to create a symbolic link which points to another symbolic link?

I have link A (pointing to address1 = /home/data/username/var) in /home/data directory
and I need to create link B in /home directory which is points to link A.

If I do ln -nfs /home/B /home/data/A, it doesn't work.

Best Answer

The argument order is

ln -s link-target new-link

So you'd want

ln -s /home/data/A /home/B
       ^--existing  ^----new link
          file/link

Update: I'd forgotten the -s flag in my sample, so it was trying to create hard links, which WILL traverse symlinks to try and point at whatever the link is pointing at. With symlinks, you can nest them as deep as you want:

marc@panic:~/b$ touch z
marc@panic:~/b$ ls -l
total 0
-rw-r--r-- 1 marc marc 0 2011-10-31 13:36 z
marc@panic:~/b$ ln -s z y
marc@panic:~/b$ ln -s y x
marc@panic:~/b$ ln -s x w
marc@panic:~/b$ ls -l
total 0
lrwxrwxrwx 1 marc marc 1 2011-10-31 13:36 w -> x
lrwxrwxrwx 1 marc marc 1 2011-10-31 13:36 x -> y
lrwxrwxrwx 1 marc marc 1 2011-10-31 13:36 y -> z
-rw-r--r-- 1 marc marc 0 2011-10-31 13:36 z
Related Question