Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.