LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-10-2008, 10:09 AM   #1
sfjoe
Member
 
Registered: Jun 2007
Location: San Francisco
Distribution: Centos 4, Debian
Posts: 55

Rep: Reputation: 16
Why doesn't `ln -sf` work?


The man page for ln says that the `-f` switch can be used to, "remove existing destination files". So, if ./foo exists and is a directory, then `ln -sf ./bar ./foo` is the same as `rm ./foo; ln -s ./bar ./foo`.
But it doesn't work like that. Why is that?
 
Old 06-10-2008, 10:28 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
It seems to work for me.. What exactly is not happening when you try to do this?

NOTE: in the context that you have written your example above, bar is the link being made, while foo is the folder you are linking to. So, by doing `ln -sf ./bar ./foo` it would delete ./bar if it exists (not foo) and recreate bar as the link.
 
Old 06-10-2008, 11:48 AM   #3
sfjoe
Member
 
Registered: Jun 2007
Location: San Francisco
Distribution: Centos 4, Debian
Posts: 55

Original Poster
Rep: Reputation: 16
better examples of what's happening

I wasn't very clear at all in my examples so I'll try again.
I have a web application in php. In order to upgrade new versions, I create /MyApplication-V1/ , /MyApplication-V2/ and so forth. The actual application directory (/MyApplication) is a symbolic link pointing to one of those versions, making it easy to roll back code or upgrade as needed.
To start with, I create the folder pointing to version 1:
ln -s /MyApplication-V1/ /MyApplication
All is well. Now, when I'm ready to upgrade, I put new code in /MyApplication-V2 and change the symbolic link, thus:
ln -sf /MyApplication-V2 /MyApplication
This is where it fails for me. The link doesn't change and so I have to first remove the old link with `rm` then create a new link. if you'd like to try a test on your own, do this:
mkdir v1
mkdir v2
ln -s v1/ v
ln -sf v2/ v
after which v is still pointing to v1 even though you 'forced' it to point to v2.
 
Old 06-10-2008, 12:39 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
OK, check out the first form of the use of ln.

try this:

ln -sf -T v1 v

then to redo it and point to v2:

ln -sf -T v2 v

you can also add the -v switch for a tiny bit of verbosity.

When we were doing it the other way, the symlink was appearing INSIDE the v2 or v2 folder () lol..
I just tried this new method (see the man page) and it DOES work for folders. I guess the behavior is slightly different for FILES vs FOLDERS.

Last edited by GrapefruiTgirl; 06-10-2008 at 12:41 PM.
 
Old 06-10-2008, 12:52 PM   #5
smoked kipper
Member
 
Registered: May 2008
Location: UK
Distribution: Slackware,Slamd64
Posts: 81

Rep: Reputation: 15
sfjoe, it's not working because it is a link to a directory, you need to use the -n option to prevent it derefencing the link.

Code:
ln -snf  /MyApplication-V2 /MyApplication
 
Old 06-10-2008, 03:27 PM   #6
sfjoe
Member
 
Registered: Jun 2007
Location: San Francisco
Distribution: Centos 4, Debian
Posts: 55

Original Poster
Rep: Reputation: 16
ahhhh

Thanks all. Like so many things, it's simple once you know how.
 
  


Reply



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
Need help getting a WLAN NIC to work (or help chosing a new card that will work) stromdal Linux - Wireless Networking 3 04-27-2008 12:17 AM
I have AD authentication work, how do i make SSH PAM work in RHEL4? epmd Red Hat 0 09-19-2007 06:04 PM
NFS doesn't work work well with mounted NTFS volumes? StevenO Linux - Networking 6 02-13-2006 10:54 AM
Does the mounting of a *BSD partition on linux work work well when rw ? kloss *BSD 3 10-08-2005 02:21 PM
FALCONS EYE (nethack) FAILS ON STARTUP, use to work, wont work even after reinstall roorings Linux - Software 0 10-08-2003 10:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:08 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
Open Source Consulting | Domain Registration