|
A symbolic link (often symlink, especially in verb form, or soft link) is a special type of file in a Unix (or Unix-like) filesystem that allows a file entry to refer to another directory entry.
Usage
Symbolic links are created with the ln -s command. For example:
ln -s name_of_real_file name_of_link
Most operations (open, read, write) on the symbolic link automatically dereference it and operate on its target (the real file). Some operations (e.g. removing) work on the link itself.
Using the 'ls' command, which is standard on these systems, a symbolically linked file might look something like this:
lrwxrwxrwx 1 jbailey jbailey 4 2003-02-07 16:49 link -> file
The 'l' in the first column is a hint that this file is a symbolic link. The information at the furthest right indicates that this file is called 'link', and that when you access it, you will see the contents of 'file'.
In contrast with hard links, there are no restrictions on where a symbolic link can point, it can refer to a file on another file system, to itself or to a file which does not even exist (e.g. when the target of the symlink is removed). Such problems will only be detected when the link is accessed.
Storage of symbolic links
Early implementations of symbolic links would store the symbolic link information in standard disk blocks, much like regular files. The file merely contained the text string of the filename the link pointed to, and had a special attribute set indicating that it was a symbolic link rather than just a regular file. However, this arrangement proved to be somewhat slow and could waste disk space on small systems. An alternative called fast symlinks was created where the link text could be stored within extra space in the standard data structures used for storing filenames on disk. This simply means that short symbolic links can be referenced quickly. Systems with fast symlinks often fall back to using the older method if the path and filename stored in symlink is larger than a certain size (generally a few dozen bytes). The original style has been retroactively termed slow symlinks.
Other operating systems
For people familiar with the Microsoft Windows operating system, a symbolic link is similar to a "shortcut", or an "alias" in the Mac OS operating system, or a "shadow" in the OS/2 operating system.
Another option under Windows are Junction Points (this requires NTFS 5.0), which are more similar to symbolic links than windows shortcuts.
|