Symbolic link

From Wikipedia, the free encyclopedia

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. Unix-like operating systems in particular often feature symbolic links.

Unlike a hard link, a symbolic link does not point directly to data, but merely contains a symbolic path which an operating system uses to identify a hard link (or another symbolic link). Thus, when a user removes a symbolic link, the file to which it pointed remains unaffected. (In contrast, the removal of a hard link will result in the removal of the file if that file has no other hard links.) Systems can use symbolic links to 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, which means that their implementation remains invisible to applications. When a program opens, reads, or writes a symbolic link, the operating system will automatically redirect the relevant action to the target of the symlink. Functions do, however, exist to detect symbolic links, so that applications may find and manipulate them.

Users should pay careful attention to the maintenance of symbolic links. Unlike hard links, if the target of a symbolic link is removed, the data vanishes and all links to it become orphans. Conversely, removing a symbolic link has no effect on its target.

Contents

[edit] 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.

Note that the size of a symbolic link exactly equals the number of characters in the path to which it points.

[edit] Similar concepts

For people familiar with the Microsoft Windows operating system, a symbolic link resembles a shortcut. Windows versions previous to Windows Vista, however, do not build links into the filesystem; instead, they use a standardized shortcut file format (*.lnk) which many programs recognize at application-level. Thus, a program accessing a shortcut with the standard Windows API will end up reading, writing and querying information for the actual shortcut-file (.lnk), before it accesses the file the shortcut points to. So, unlike symbolic links, Windows shortcuts lack transparency for I/O functions.

Another option under Windows, junction points (which require NTFS 5.0 / Windows 2000), resemble symbolic links more closely than do Windows shortcuts.

Windows Vista includes support for true symbolic links.

The Mac OS equivalent of a symbolic link, the alias, has the added feature of working even if the target file moves to another location on the same disk.

Symbolic links also resemble shadows in the graphical Workplace Shell of the OS/2 operating system.

[edit] Trivia

The operating system Plan 9, designed as a research successor to Unix, does not support symbolic links.

[edit] 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

[edit] External Links

Wikibooks
Wikibooks has a book on the topic of

This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.