21
6
How do I change where a symlink points to, without deleting and creating a new one (with ln -s "/path/to/point/to" "/path/where/symlink/is"
)?
When I tried doing that to Java's "Current" symlink, Java wouldn't even work (from the command line, at least, said 'Segmentation Fault') but it was back to normal when I restored the old "Current" symlink with Time Machine (but later I found out I should use /Applications/Utilities/Java Preferences.app
anyway to change current java version).
wouldn't the mv command just rename it..? – mk12 – 2009-09-06T19:17:54.080
.. I tried that, it justs moves the new symlink into the folder that the old one points to. – mk12 – 2009-09-06T19:26:37.570
The first command makes the symlink that points where you want, and the second command replaces the existing pointer to the old place with the pointer to the new place. The mv is atomic so the symlink will always exist. – mark4o – 2009-09-07T00:00:55.660
.. But it still doesn't work.. it moves the new pointer into the folder that the old one points to. – mk12 – 2009-09-07T02:08:07.227
/path/where/symlink/is
is the symlink that you are changing. Using these commands will change it to point to/path/to/point/to
. The folder that the original symlink points to is not touched at all. – mark4o – 2009-09-07T07:20:43.283The mv command doesn't make it replace the old one with the new one, it moves the new one into the old one (into the folder it points to). I tried several times. – mk12 – 2009-10-16T12:47:25.897
@Mk12: You're supposed to give the new one the same name as the old one. So it should overwrite it. – Sasha Chedygov – 2009-10-19T21:19:04.890
I did, but it doesn't. It moves it into the directory it points to. – mk12 – 2009-10-25T13:28:56.977
@Mk12: Sorry, you are right. I have fixed my answer to handle this, although it is now 4 commands instead of 2... :-( – mark4o – 2009-10-26T07:45:38.853
Those instructions are very hard to follow. – mk12 – 2009-10-28T20:07:27.537
It is just moving a new link over the old one. The mkdir/rmdir is just there because "mv x y" renames x to y/x instead of just y if y is a directory or a link to a directory. If mv had an option to suppress this behavior then it would be simpler. – mark4o – 2009-10-31T22:36:27.160