Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 02-13-2008
fpmurphy's Unix or Linux Image
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 24 April 2015, 9:36 PM EDT
Location: /dev/ph
Posts: 4,914
Thanks: 68
Thanked 453 Times in 421 Posts
Yes it is possible
Sponsored Links
    #3  
Old Unix and Linux 09-22-2008
dhinge's Unix or Linux Image
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 Unix and Linux 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 Unix and Linux 09-23-2008
shamrock shamrock is offline Forum Advisor  
Registered User
 
Join Date: Oct 2007
Last Activity: 15 April 2015, 10:26 AM EDT
Location: USA
Posts: 1,556
Thanks: 25
Thanked 150 Times in 142 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 Unix and Linux 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 Unix or Linux Image
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 03:15 PM
symbolic link tonijel Shell Programming and Scripting 2 10-01-2009 06:23 AM
Bash: return target of symbolic link mglenney Shell Programming and Scripting 2 07-22-2009 03:15 AM
ZIP a soft / symbolic link target galz UNIX for Dummies Questions & Answers 1 06-10-2008 04:36 AM
need some info about symbolic link and hard link detective linux UNIX for Dummies Questions & Answers 2 01-08-2008 06:36 AM



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