Replace symbolic link which linked to directory target
Solution 1
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/
Solution 2
While replacing symbolic links to directories we should use -n
option.
Example: ln -sfn /path/to/directory /target/directory
Solution 3
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.
Related videos on Youtube
LiuYan 刘研
// unsigned char *p; // Map<String,Object> map; -- SELECT Name FROM ab -- INNER JOIN cdr ON ab.PhoneNumber=cdr.PhoneNumber /* pre {font-family: 'Ubuntu Mono';} */ <!-- <pre>&copy; right?</pre> --> // function f() {} # echo -e "your message:\n$(fortune)" | \ # gpg -e --clearsign -o - -r [email protected] REM if ""%1"" == """" goto default ; exten => 911,1,Answer() svn commit -m "to be continue"
Updated on September 18, 2022Comments
-
LiuYan 刘研 almost 2 years
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 linktomcat7
to new target using the following commandln -s --force apache-tomcat-7.0.21 tomcat7
, but it does not worked as what I expected: it created a symbolic linktomcat7/apache-tomcat-7.0.21
instead of replace existingtomcat7
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 thinkln -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? -
LiuYan 刘研 almost 13 yearsThanks! 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 刘研 almost 13 yearsThanks, 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.
-
untill over 7 yearsThis should be the accepted answer. Solves the question and one-liner/ compact.
-
ArtOfWarfare over 6 yearsThe accepted answer also solves the question and is a one liner... unless I'm mistaken, it can be equally compact. I don't think it's necessary to have a separate
-
and space before every flag like they have.