Symlink/ link question... can someone explain please! ta
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
Symlink/ link question... can someone explain please! ta
Hi
I am trying to learn linux in a bit more depth, and i'm a bit baffled by this. So if someone could answer i'd be very grateful!
On my Fedora 12 box, in a terminal, if i cd to /etc/rc3.d and list items, it lists a load of links (symlinks?) to files within /etc/init.d. If I cd to /etc/rc.d/rc3.d and list items, a load of apparently identical links (symlinks?) are listed, pointing to the same files in /etc/init.d.
OK fine, so there are two sets of links pointing to the same files.
BUT
If I cd to /etc and longlist (ls-la) the contents, then the /etc/rc3.d directory is shown as a link (symlink?) to /etc/rc.d/rc3.d.
So what is /etc/rc3.d? Is it a file full of links, or is it a link itself? Or both??
On my Fedora 12 box, in a terminal, if i cd to /etc/rc3.d and list items, it lists a load of links (symlinks?) to files within /etc/init.d. If I cd to /etc/rc.d/rc3.d and list items, a load of apparently identical links (symlinks?) are listed, pointing to the same files in /etc/init.d.
OK fine, so there are two sets of links pointing to the same files.
BUT
If I cd to /etc and longlist (ls-la) the contents, then the /etc/rc3.d directory is shown as a link (symlink?) to /etc/rc.d/rc3.d.
Depending of the way your runlevel are managed you can have a two way of structure. In generel there are two ways linux handles the starting of process after init is run. One is SysV and the other is init.d (Not sure about if init.d is the right name). As LInux developed there was a change from one of the startup logics to the other. But to remain portable the transfer was done by using both kinds of structure and just help out with symlinks.
Now to your question.
Quote:
Originally Posted by spoovy
So what is /etc/rc3.d? Is it a file full of links, or is it a link itself? Or both??
/etc/rc3.d is the directory that gets scanned by init when you change the runlevel to runlevel 3.
On linux you normaly have one directory (/etc/init.d) which holds all the scripts that are used to start/stop process. The directories for the runlevel, rc3.d in your case, hold symlinks to the scripts that one wants for this certain runlevel.
And as your distribution is in the transid state it just symlinks this to the old style of startup.
Hm Hope it made some things clearer. Maybe check out this link and do a google for "linux startup" to get some further information
If the links are shown by ls -l, then they are symbolic links, not hard links.
When /etc/rc3.d is symbolically linked to /etc/rc.d/rc3.d, then the real directory is /etc/rc.d/rc3.d. It in turn contains a load of links. So when you cd to /etc/rc3.d, you are looking at the same links as when you cd to /etc/rc.d/rc3.d. There are only a single set of links. It is just a way to make the same files appear in multiple path locations.
Last edited by neonsignal; 03-02-2010 at 06:49 AM.
Thanks guys, I think i get it. A problem with my mental model i think.
So when i cd to /etc/rc3.d, I was expecting to be actually transported to /etc/rc.d/rc3.d, when really its more like a window, so cd'ing into it I am just peering through the link to the target dir. Hence my being able to see the contents of the target directory while not actually being 'in' it.
You are never actually **in** a directory---all you are doing with "cd" is changing the value of the PWD env. variable, so that it can be used as part of a relative path. For example in your home directory, you want to read a file. When you do "cd ~" is sets PWD=/home/yourusername. Then --eg--the command "more" uses PWD to help set the path.
Thus "more filename" is really "more $PWD/filename".
If you specify an absolute path, then PWD is not used, eg:
"more /home/yourusername/filename"
Finally, when you issue "cd <something>" you will change PWD, regardless of whether <something> had a soft link in it.
BUT--if there is a soft link, then PWD becomes the link path. Therefore something like "cd .." works as expected.
Example (linktotextfiles is a soft link in ~ that points to play/textfiles):
Code:
[mherring@Ath ~]$ cd linktotextfiles
[mherring@Ath linktotextfiles]$ ls
a b c ca.gz newdir this.gz
[mherring@Ath linktotextfiles]$ pwd
/home/mherring/linktotextfiles
[mherring@Ath linktotextfiles]$ cd ..
[mherring@Ath ~]$ cd play/textfiles
[mherring@Ath textfiles]$ ls
a b c ca.gz newdir this.gz
[mherring@Ath textfiles]$ pwd
/home/mherring/play/textfiles
[mherring@Ath textfiles]$ cd ..
[mherring@Ath play]$
So---being "in" ~/linktotestfiles is the same as being "in" play/textfiles, but PWD is different and therefore "cd .." gives a different result
Presumably you will get the equivalent behavior in a GUI file browser. (But MS Windows does NOT work this way)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.