LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2008, 06:39 PM   #1
tieuphongvan
LQ Newbie
 
Registered: Apr 2008
Posts: 14

Rep: Reputation: 0
Question 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
 
Old 04-17-2008, 07:22 PM   #2
bsdunix
Senior Member
 
Registered: May 2006
Distribution: Caldera, CTOS, Debian, FreeBSD, Mac OS X, Mandrake, Minix, OpenBSD, Slackware, SuSE
Posts: 1,757

Rep: Reputation: 80
Code:
# ln -sf /path/to/target /path/to/link
http://linux.die.net/man/1/ln
 
Old 04-18-2008, 01:22 AM   #3
tieuphongvan
LQ Newbie
 
Registered: Apr 2008
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 04-18-2008, 03:42 AM   #4
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
How about stopping the program during this "maintenance" thing?
 
Old 04-18-2008, 04:08 AM   #5
marquardl
Member
 
Registered: Apr 2008
Posts: 100

Rep: Reputation: 15
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

Last edited by marquardl; 05-01-2008 at 03:49 AM.
 
Old 04-19-2008, 01:54 AM   #6
tieuphongvan
LQ Newbie
 
Registered: Apr 2008
Posts: 14

Original Poster
Rep: Reputation: 0
@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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
removing a soft link quietguy47 Linux - General 3 12-31-2011 09:34 PM
Removing a symbolic Link michshelly Linux - Newbie 8 05-13-2006 08:26 AM
Removing a symbolic link lolipop Linux - Newbie 2 03-23-2005 11:53 AM
problems removing a symoblic link SerfurJ Linux - Software 3 12-12-2003 02:01 PM
Help removing a symbolic link jamesmwlv Linux - Newbie 3 04-25-2003 11:51 AM


All times are GMT -5. The time now is 01:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration