Replace symbolic link which linked to directory target

directorysymlink

I want to upgrade tomcat server from 7.0.19 to 7.0.20.

I've already ln -s apache-tomcat-7.0.19 tomcat7 before, so now I need to link tomcat7 to new target using the following command ln -s --force apache-tomcat-7.0.21 tomcat7, but it does not worked as what I expected: it created a symbolic link tomcat7/apache-tomcat-7.0.21 instead of replace existing tomcat7 symbolic link with new target.

Example

# mkdir v1 v2
# ln -s v1 v
# ln -s v2 v
# ll v*
lrwxrwxrwx. 1 root root    2 Sep  5 16:02 v -> v1

v1:
total 0
lrwxrwxrwx. 1 root root 2 Sep  5 16:02 v2 -> v2

v2:
total 0

I checked the manual of ln, I think ln -s --force apache-tomcat-7.0.21 tomcat7 use the 3rd form instead of 1st form to explain the parameters. That's so ambiguous between the 1st and 3rd form. So how to replace symbolic link in this case?

Best Answer

You want the -T option:

$ mkdir v1
$ ln -s v1 foo
$ ls -FlA | grep foo
lrwxrwxrwx 1 phil phil     2 2011-09-05 01:58 foo -> v1/
$ mkdir v2
$ ln -s -T -f v2 foo
$ ls -FlA | grep foo
lrwxrwxrwx 1 phil phil     2 2011-09-05 01:59 foo -> v2/
Related Question