Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to change the destination of an existing symbolic link, without removing the link or the old destination.

I have previously created a symbolic link to a directory such as follows :

$ cd /usr/lib/jvm/

$ ls -lh
drwxr-xr-x 8 uucp  143 4.0K Sep 10 20:22  jdk1.7.0_04
drwxr-xr-x 8 uucp  143 4.0K Aug 29 05:42  jdk1.7.0_07

$ sudo ln -s jdk1.7.0_04 oracle-jdk-7

$ ls -lh
drwxr-xr-x 8 uucp  143 4.0K Sep 10 20:22  jdk1.7.0_04
drwxr-xr-x 8 uucp  143 4.0K Aug 29 05:42  jdk1.7.0_07
lrwxrwxrwx 1 root root   12 May 11 11:27  oracle-jdk-7 -> jdk1.7.0_04/

Now I want to change this, to link to the other directory :

$ sudo ln --force -s jdk1.7.0_07 oracle-jdk-7

But it doesn't work without any errors :

$ ls -lh
drwxr-xr-x 8 uucp  143 4.0K Sep 10 20:36  jdk1.7.0_04
drwxr-xr-x 8 uucp  143 4.0K Aug 29 05:42  jdk1.7.0_07
lrwxrwxrwx 1 root root   12 May 11 11:27  oracle-jdk-7 -> jdk1.7.0_04/

Any help ?

share|improve this question

1 Answer 1

up vote 12 down vote accepted

I haven't actually tried this, but I believe the command for a directory is:

ln -sfn DESTINATION_DIRECTORY LINK_NAME

The 'f' parameter replaces the existing link.

To change a link to a file rather than a directory, you'd omit the 'n', using:

ln -sf DESTINATION_FILE LINK_NAME
share|improve this answer
1  
Thanks! The -n option did the job :) –  Seyed Mohammad Sep 10 '12 at 16:30
    
The command is great!!!!!!!!!! –  ubuntico Dec 29 '13 at 20:32

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.