Symbolic links operate transparently for most operations: 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.
A symbolic link merely contains a text string that is interpreted and followed by the operating system as a path to another file or directory. It is a file on its own and can exist independently of its target. If a symbolic link is deleted, its target remains unaffected. If the target is moved, renamed or deleted, any symbolic link that used to point to it continues to exist but now points to a non-existing file. Symbolic links pointing to non-existing files are sometimes called orphaned or dangling.
Unlike hard links, symbolic links can also point to directories and cross volumes.
To create a symbolic link in Unix-like systems using the command-line interface (shell), enter the following command:
ln -s target link_name
target is the relative or absolute path which the symlink will point to. Usually the target will exist, although one can create a symlink to a target which does not exist. link_name is the desired name of the symbolic link. After creating the symbolic link, it can be treated as an alias for the target. Any file system management commands (e.g., cp, rm) may be used on the symbolic link. Commands which read or write file contents will access the contents of the target file.
$ mkdir -p /tmp/one/two
$ echo "test_a" >/tmp/one/two/a
$ echo "test_b" >/tmp/one/two/b
$ cd /tmp/one/two
$ ls
a b
$ cd /tmp
$ ln -s /tmp/one/two three
$ cd three
$ ls
a b
$ cat a
test_a
$ cat /tmp/one/two/a
test_a
$ echo "test_c" >/tmp/one/two/a
$ cat /tmp/one/two/a
test_c
$ cat /tmp/three/a
test_c
Some Unix, as well as Linux (notably GoboLinux), distributions use symlinks extensively in an effort to reorder the file system hierarchy. This offers the opportunity to create a more intuitive directory tree and to reorganize without having to redesign the core set of system functions and utilities themselves.
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 all struct stat values common to regular files 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 of symbolic links usually have no relevance: the permissions set on the file to which the symlink points control the access rights to the file data.
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.
Symbolic links are designed to aid in migration and application compatibility with POSIX operating systems -- Microsoft aimed for Vista's symbolic links to "function just like UNIX links. However, the implementation varies from Unix symlinks in several ways; for example, Vista users must manually indicate when creating a symbolic link whether it is a file or directory, and there is a limit of 31 symlinks in a given path.. Additionally, only users with the new Create Symbolic Link privilege, which only administrators have by default, can create symbolic links; if this is not the desired behavior, it must be changed in the Local Security Policy management console.
Another difference are the capabilities of the mechanism:
Some differences exist, however. Cygwin has no way to specify shortcut-related information - such as working directory or icon - as there is no place for such parameters in ln -s command. To create standard Microsoft .lnk files Cygwin provides the mkshortcut utility
The Cygwin User's Guide has more information on this topic.
Operating systems that make use of variant symlinks include NetBSD, DragonFly BSD and Domain/OS.