In computing, a symbolic link (often shortened to symlink and also known as a soft link) consists of a special type of file that serves as a reference to another file or directory. Unix-like operating systems in particular often feature symbolic links. Unlike a hard link, which points directly to data and represents another name for the same file, a symbolic link contains a path which identifies the target of the symbolic link. Thus, when a user removes a symbolic link, the file to which it pointed remains unaffected. Symbolic links may refer to files even on other mounted file systems. The term orphan refers to a symbolic link whose target does not exist. Symbolic links operate transparently—programs which read or write to files named by a symbolic link will behave as if operating directly on the target file. However, programs that need to handle symbolic links specially (e.g. backup utilities) may identify and manipulate them directly. Users should pay careful attention to the maintenance of symbolic links. If the target of a symbolic link is moved or removed, all symbolic links to it become orphans.
Contents |
Example
To create a symbolic link in Unix, at the shell prompt, enter the following command: ln -s target_filename symlink_filename Replace target_filename with the relative or absolute path which the symlink will point to. Usually the target will exist, although you can create a symlink to a target which does not exist. Replace symlink_filename with the desired name of the symbolic link. The ln command then creates the symbolic link. After you've made the symbolic link, you can then treat symlink_filename as an alias for the target file. You can use normal file management commands (e.g., cp, rm) on the symbolic link. Commands which read or write the file contents will access the contents of the target file. user@userbox:~/one$ cd two
user@userbox:~/one/two$ ls
a b
user@userbox:~/one/two$ cd
user@userbox:~$ ln -s ~/one/two three
user@userbox:~$ cd three
user@userbox:~/three$ ls
a b
user@userbox:~/three$ cd
user@userbox:~$ cat ./one/two/a
a
user@userbox:~$ echo "c" > ./one/two/a
user@userbox:~$ cat ./three/a
c
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 contained the textual reference to the link’s target, and an indicator denoting it as a symbolic link. This arrangement proved somewhat slow, and could waste disk-space on small systems. An innovation called fast symlinks allowed storage of the link-text within the standard data structures used for storing file information on disk (inodes). This space generally serves to store the chain of disk blocks composing a file (60 bytes on the Unix File System). This simply means that users can reference shorter symbolic links quickly. Systems with fast symlinks often fall back to using the older method if the path and filename stored in symlink exceeds the available space in the inode, or for disk compatibility with other or older versions of the operating system. The original style has become retroactively termed slow symlinks. Although storing the link value inside the inode saves a disk block and a disk read, the operating system still needs to parse the pathname information in the link, which always requires reading an additional inode and generally requires reading other — potentially many — directories, processing both the list of files and the inodes of each of them until it finds a match with the link pathname components. Only when a link points to a file inside the same directory do fast symlinks provide significant gains in performance. The POSIX standard does not require very many struct stat values to have meaning for symlinks. This allows implementations to avoid symlink inodes entirely by storing the symlink data in directories. However, the vast majority of POSIX implementations (including all implementations currently in widespread use) do use symlink inodes. The file-system permissions on the symbolic (or soft) link have no relevance: the permissions set on the file to which the symlink points control the access rights. The size of a slow symlink exactly equals the number of characters in the path it points to. The size of a fast symlink is 0.
Similar concepts
In addition to the symbolic link described above, Mac OS can employ aliases, which have the added feature of working even if the target file moves to another location on a different disk. A similar functionality also exists in some Linux distributions. Note that some operating systems may recreate the target file in the original location if it has been moved, leaving the user with two seemingly-identical files (though this type of behavior should not be relied on to undelete a file). Microsoft Windows Vista supports symbolic links for both files and directories with the command line utility mklink by what is called an NTFS junction point. However only 31 symlinks are allowed in a directory, relative symlinks cannot cross volumes and users must manually be aware whether a symlink is a file or directory for both creation and removal. Earlier versions of Microsoft Windows do not support symbolic links on files, but do offer a bare bones directory symlink support for directories with similar (and worse) limitations as those in Vista symlinks. In Windows XP, the Windows Resource Kit includes a file called linkd that creates these directory-based symlinks. Junction, written by Mark Russinovich of SysInternals, is a free command line utility for creating directory symbolic links on NTFS 5 filesystems. Contrary to popular belief, symbolic links are not application shortcuts, which are supported by most operating systems. Symbolic links also resemble shadows in the graphical Workplace Shell of the OS/2 operating system.
Variant symlinks
A variant symlink is a symbolic link that has a variable name embedded in it. This can allow some clever tricks to be performed that are not possible with a standard symlink. Variables embedded in the symlinks can include user and or environment specific information among other things. Operating systems that make use of variant symlinks include Domain/OS and DragonFly BSD.
See also
- Hard link
- ln (Unix), the ln command, used with the -s option to create new symbolic links on Unix-like systems
- Symlink race, a security-vulnerability caused by symbolic links
- NTFS junction point, a similar functionality for folders on newer NTFS filesystems
External links
- Q & A: The difference between hard and soft links Detailed and easy to understand
References
This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.


