Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
I've created a utility that symbolically links dir to any of the dir-[x] directories. So, if I say, switchdir b, it would unlink dir to whatever it's linked to and symbolically link it to dir-b. If I'm in in dir-b when I call the switchdir command to dir-a, for example, the link gets undone and reconnected to dir-a. From a separate linux window I can run ls and see that dir has the contents of dir-a. However, relative to the linux window from which I ran the switchdir a command, it still shows the contents of dir-b. I have to cd out of dir, then back in to see that a switch has taken place.
My question is, how is that possible? Obviously, there's something deeper going on if it somehow caches the information of dir, which still displays information in dir-b from the window I ran the command, instead of the now current dir-a which it displays from a window external to the event that took place. My theory is, it writes the state of the link somewhere and gets the information from that "checkpoint", instead of resolving the link each time it's referenced. Is it possible to have it resolve the new link in real time?
Last edited by linuxcoder; 08-07-2012 at 05:07 AM.
You are changing the contents of the link, so only when you follow the link will you end up in the directory it points to.
Yes, but from a low level, how does it store the link? Each session (theoretically), can point the link to a different directory. Is that information accessible? I'm trying to understand how the link resolves itself, so I can overcome that and realize the link in real time, from a shell script. Changing directories inside a shell script has no effect external to the script, so I cannot refresh the link that way.
I've looked for documentation, but haven't found any information as of yet. Everything I've found so far is written from a very topical perspective.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
First of all, where are you calling ls from? If you're calling:
Code:
ls dir/
and seeing the contents of dir-a even when you changed the link to dir-b then that's a quirk I was not aware of and, yes, a problem. If, however, you are cd'ing into dir, running ls, changing the link to dir-b, then running ls again you are still in dir-a so will still see its contents -- this is normal behaviour and does not need working around.
ln -s just makes a symbolic link. When you "cd dir", the link tells the command "actually, you should go to dir-a", so that's where cd goes. Updating the link after this point will have no effect, because you're already sitting in dir-a, which is not being changed. It sounds like what you want is to create a REAL directory "dir", the contents of which will be either symlinks to the applicable files in dir-a, or symlinks to the applicable files in dir-b.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.