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.


The argument order is

ln -s link-target new-link

So you'd want

ln -s /home/data/A /home/B
       ^--existing  ^----new 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
  • thanks! but doesn't work too, seems like symlink to another symlink cannot be created, I have a error 'Could not resolve symlink “httpdocuments”. file not found' – Dmitry T Oct 31 '11 at 19:35
  • see the edit. forgot the -s flag. – Marc B Oct 31 '11 at 19:38
  • It's working on my local but it doesn't on the server... – Dmitry T Oct 31 '11 at 19:51
  • What's the OS on the server, and what filesystem type is it running on? – Marc B Oct 31 '11 at 19:54
  • Its a DV on Media Temple running Red Hat Linus Enterprise. From the command line : Linux version 2.6.9-023stab048.6-enterprise (root@rhel4-32) (gcc version 3.4.5 20051201 (Red Hat 3.4.5-2)) #1 SMP Mon Nov 17 19:09:18 MSK 2008 – Dmitry T Oct 31 '11 at 20:01

The OP wants a symlink, ln does a hardlink. But other than that, you can make a symlink that points to anywhere, the target doesn't even have to exist. man ln is your friend :) I usually do ln -s tgt src, so src points to tgt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy