EXPLAIN: What is a Symbolic Link?
This is one of those subjects that can get really ugly, really fast. I’m going to forgo the ugly part and look at a symbolic link from a functional level.
A symbolic link is a file that points to another file somewhere else on the system. A good example of a typical symbolic link are the startup scripts on a GNU/Linux system. For example, in a Debian system there are directories for each runlevel that contain the scripts to run when the system enters that runlevel.
/etc/rc1.d
/etc/rc2.d
/etc/rc3.d
/etc/rc4.d
/etc/rc5.d
/etc/rc6.d
The scripts in each of these directory don’t actually reside in all those directories, rather they are symbolic links that point to a single instance of the script. For instance, if we look at the files in my runlevel 1 directory (/etc/rc1.d) using ls -all we see:
lrwxrwxrwx 1 root root 13 Oct 23 12:40 K01kdm -> ../init.d/kdm
lrwxrwxrwx 1 root root 13 Oct 23 12:40 K01xdm -> ../init.d/xdm
… and more
The K01kdm script is actually just a symbolic link to the /etc/init.d/kdm script.
There is an advantage of using symbolic links for files that have to reside in multiple locations. Ease of administration and management.
I wrote a script called loadlan1 to configure my wifi card at system boot. That script resides in /etc/init.d/loadlan1 but I have copied symbolic links to the runlevels 3 and 5 directories. Now if I need to change my WEP password or something, I can just change it in the /etc/init.d/loadlan1 script. Since the links in the runlevel directories point to that script, the change takes place without me having to muck around with more than one file.
How to make a symbolic link.
The syntax is ln -s target link_name as in:
ln -s /etc/init.d/loadlan1 /etc/rc3.d/S10loadlan1
For more information on usage, use your system’s man ln command. For a more technical overview of symbolic and hard links, visit this page from the Linux Gazette.
Related Stories
POSTED IN: Explanation
1 opinion for EXPLAIN: What is a Symbolic Link?
New Linux User » HOWTO: Remove a Symbolic Link
Oct 31, 2005 at 11:24 am
[…] When you create a symbolic link, link file you’ve created just points to the target file. Therefore, the link file has no other purpose in life than that. So, when you want to get rid of it, just delete the link file. […]
Have an opinion? Leave a comment: