Thursday, December 10, 2009

How to change target of a symbolic link ?

dandyrandy


Is it possible to change the target of a symbolic link?

What I currently have is:
/home/Data1
/home/Data2
/home/Stores

In the Stores directory, I did: ln -s /home/Data1 /home/Stores/abc
$ pwd
/home/Stores
$ ls -latr
lrwxrwxrwx 1 dandy dandy 46 Feb 12 16:38 abc -> /home/Data1

I want to now change that target to:
abc -> /home/Data2

BUT, I don't want to do have to delete the link and re-create it to the new target. I just want to rename/change/modify the target. Is it possible?


fimblo

I normally delete the symlink and re-create it on one line, minimizing the time the link does not exist:

rm mysymlink ; ln -s mytargetfile mysymlink

I suppose you could write a little hack which does it in one go, but I've never heard of one which is included in standard POSIX systems...

shamrock

ln -s /home/Data1 /home/Stores/abc
ln -f -s /home/Data2 /home/Stores/abc


see:- http://en.wikibooks.org/wiki/LPI_Linux_Certification/Create_&_Change_Hard_&_Symbolic_Links

No comments:

Post a Comment