Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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/
share|improve this answer
    
Thanks, that's exactly what I needed. What a shame, I see this optional option in help, but I don't know what it exactly does. –  LiuYan 刘研 Sep 6 '11 at 4:11

Why not just

rm tomcat7
ln -s apache-tomcat-7.0.21 tomcat7

?

This will not touch the old directory apache-tomcat-7.0.19 but just delete the old link. Then ln can create the new one.

share|improve this answer
    
Thanks! I did this currently in my script, but I think it's unlike cp -f/mv -f which use single command to do overwrite operation, so I'm looking for the single command solution. –  LiuYan 刘研 Sep 6 '11 at 4:05

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.