LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to replace a symolic link with another one without removing it first? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-replace-a-symolic-link-with-another-one-without-removing-it-first-636103/)

tieuphongvan 04-17-2008 06:39 PM

How to replace a symolic link with another one without removing it first?
 
Hi,

For example, I am having a symbolic link of /local/bin linked to /opt/db2test/bin. Now I want to link the /local/bin to /opt/db2/bin instead. Normally, what I would do is to:

Unlink it first
# unlink /local/bin

And re-establish the new link
# ln -s /opt/db2/bin /local/bin

However, I am in a situation that I cannot remove the old link even just for a second because the running application needs the bin directory. Is there any way that I can establish the new link without going through the step of unlinking the old one? Please help, thanks!

ps: either the /opt/db2test/bin or /opt/db2/bin will keep the application running

bsdunix 04-17-2008 07:22 PM

Code:

# ln -sf /path/to/target /path/to/link
http://linux.die.net/man/1/ln

tieuphongvan 04-18-2008 01:22 AM

I thought I would try the force option before, but it didn't work. It still showed the old link, and didn't establish the new link :(

b0uncer 04-18-2008 03:42 AM

How about stopping the program during this "maintenance" thing?

marquardl 04-18-2008 04:08 AM

mv newlink oldlink
 
Create a new link with a different name (like bin2) next to the old one, then move the new one and overwrite the old:

Code:

# ln -s /opt/db2/bin /local/bin2
# cd /local
# mv bin2 bin

Here is the test case:
Code:

$ echo "BIN" > x1
# ln -s x1 xbin
# echo "BIN2" > x2
# ln -s x2 xbin2
# ls -l x*
-rw-rw-r-- 1 user user        4 2008-04-18 10:59 x1
-rw-rw-r-- 1 user user        5 2008-04-18 11:00 x2
lrwxrwxrwx 1 user user        2 2008-04-18 11:00 xbin -> x1
lrwxrwxrwx 1 user user        2 2008-04-18 11:00 xbin2 -> x2
# mv xbin2 xbin
# ls -l x*
-rw-rw-r-- 1 user user        4 2008-04-18 10:59 x1
-rw-rw-r-- 1 user user        5 2008-04-18 11:00 x2
lrwxrwxrwx 1 user user        2 2008-04-18 11:00 xbin -> x2

Fedora HP webcam drivers

tieuphongvan 04-19-2008 01:54 AM

@b0uncer

The application is being used by many users, so I don't want to stop it if I can avoid it.

@marquardl

That would work. Thanks a lot!


All times are GMT -5. The time now is 06:53 AM.