LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 08-07-2012, 05:03 AM   #1
linuxcoder
LQ Newbie
 
Registered: Jul 2012
Posts: 9

Rep: Reputation: Disabled
ln -s : What dark magic is this?


I have the following directory setup:

dir-a
dir-b
dir-c
[etc]

dir -> dir-b

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.
 
Old 08-07-2012, 05:09 AM   #2
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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.
 
Old 08-07-2012, 05:59 AM   #3
linuxcoder
LQ Newbie
 
Registered: Jul 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by 273 View Post
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.
 
Old 08-07-2012, 06:17 AM   #4
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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.
 
Old 08-07-2012, 11:29 AM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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.
 
1 members found this post helpful.
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
man page text color is too dark ....(color is too dark) chxooi Linux - Software 8 08-10-2010 12:52 PM
Python: Dark Magic CoderMan Programming 1 03-11-2010 07:29 PM
Using Partition Magic and Boot Magic to install Linux zathrus MEPIS 4 01-14-2006 08:24 PM
Partition Magic/Boot magic and Slackware. adam1835 Linux - Newbie 5 01-11-2006 11:46 AM
I can't see linux! It's very dark in here, please help me. BooDaH Linux - Hardware 2 08-16-2004 10:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:59 AM.

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