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 ?
To create a symbolic link to a directory, use the 'n' option:
DESTINATION_DIRECTORY
is the name of the link target;LINK_NAME
is the name of the link.f
option means to replace the existing link (ie, delete it first).The
n
option is a bit complicated. I believe your command may have created a link tojdk1.7.0_07
inside the directoryjdk1.7.0_04
, via the linkoracle-jdk-7
rather than replacing the link. If so, you should delete the link to avoid confusion.