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.

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.

share|improve this question
add comment

migrated from stackoverflow.com Nov 2 '11 at 5:53

This question came from our site for professional and enthusiast programmers.

2 Answers

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.

share|improve this answer
add comment

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 next 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
share|improve this answer
    
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
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.