change target of a symbolic link | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

change target of a symbolic link

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-13-2008
dandyrandy dandyrandy is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 13 February 2008, 1:54 PM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
change target of a symbolic link

Hi,

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?


Thanks
Sponsored Links
    #2  
Old 02-13-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 20 December 2014, 7:46 AM EST
Location: /dev/ph
Posts: 4,842
Thanks: 64
Thanked 434 Times in 402 Posts
Yes it is possible
Sponsored Links
    #3  
Old 09-22-2008
dhinge's Avatar
dhinge dhinge is offline
Registered User
 
Join Date: Nov 2006
Last Activity: 20 November 2008, 2:42 PM EST
Location: Salt Lake City, UT
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
So how do you change the target of a symlink?
    #4  
Old 09-23-2008
fimblo fimblo is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 7 May 2009, 12:03 PM EDT
Location: stockholm sweden
Posts: 31
Thanks: 0
Thanked 1 Time in 1 Post
Very interested to hear fpmurphy's explanation on how to change target of symlink without deleting the symlink first.

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...
Sponsored Links
    #5  
Old 09-23-2008
shamrock shamrock is offline Forum Advisor  
Registered User
 
Join Date: Oct 2007
Last Activity: 15 December 2014, 12:20 PM EST
Location: USA
Posts: 1,547
Thanks: 25
Thanked 149 Times in 141 Posts
fpmurphy is absolutely correct...yes you can change the target of a soft link without deleting the old one by forcing ln to do so.

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

Sponsored Links
    #6  
Old 09-23-2008
fimblo fimblo is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 7 May 2009, 12:03 PM EDT
Location: stockholm sweden
Posts: 31
Thanks: 0
Thanked 1 Time in 1 Post
wow, thanx
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Symbolic Link Help LAVco Shell Programming and Scripting 2 06-07-2010 04:15 PM
symbolic link tonijel Shell Programming and Scripting 2 10-01-2009 07:23 AM
Bash: return target of symbolic link mglenney Shell Programming and Scripting 2 07-22-2009 04:15 AM
ZIP a soft / symbolic link target galz UNIX for Dummies Questions & Answers 1 06-10-2008 05:36 AM
need some info about symbolic link and hard link detective linux UNIX for Dummies Questions & Answers 2 01-08-2008 07:36 AM



All times are GMT -4. The time now is 04:06 PM.