Symbolic link

Symbolic link

In computing, a symbolic link (also "symlink" or "soft link") is a special type of file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution. [ [http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 Pathname resolution] , POSIX.] Symbolic links first appeared in the 4.2BSD release of Berkeley Unix (1983). Today they are supported by the POSIX operating-system standard, most Unix-like operating systems, Windows Vista, and to some degree in Windows 2000 and Windows XP.

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.

Unix and Linux

In POSIX-compliant operating systems, symbolic links are created with the symlink() system call. When using the "ln" shell command, this system call is used, instead of link(), when the -s command flag is specified.

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.

torage of symbolic links

Early implementations of symbolic links stored the symbolic link information much like data in 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 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.

Mac OS

Aliases

In addition to the usual Unix symbolic links, Mac OS can employ aliases, which have the added feature of working even if the target file moves to another location on the same volume. A similar functionality also exists in some Linux distributions.

Windows

NTFS Junction points

The Windows 2000 version of NTFS introduced reparse points, which enabled, among other things, the use of Volume Mount Points and junction points. Junction points are for directories only, and moreover, local directories only; junction points to remote shares are unsupported. [ [http://www.microsoft.com/technet/sysinternals/FileAndDisk/Junction.mspx Sysinternals Junction documentation] ] The Windows 2000 and XP Resource Kits include a program called linkd to create junction points; a more powerful one named Junction was distributed by Sysinternals' Mark Russinovich.

Windows Vista symbolic link

Windows Vista supports symbolic links for both files and directories with the command line utility mklink. Unlike junction points, a symbolic link can also point to a file or remote SMB network path. Additionally, the NTFS symbolic link implementation provides full support for cross-filesystem links. However, the functionality enabling cross-host symbolic links requires that the remote system also support them, which effectively limits their support to Windows Vista and later Windows operating systems.

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" [ [http://msdn2.microsoft.com/en-us/library/aa365680.aspx Symbolic Links] , MSDN Library, Win32 and COM Development, 2008-01-18] . 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, [ [http://msdn2.microsoft.com/en-us/library/aa363866.aspx CreateSymbolicLink Function] , MSDN Library, Win32 and COM Development] and there is a limit of 31 symlinks in a given path. [ [http://msdn.microsoft.com/en-us/library/aa365460(VS.85).aspx Symbolic Link Programming Considerations] , MSDN] . Additionally, only users with the new Create Symbolic Link privilege, which only administrators have by default, can create symbolic links; [Mark Russinovich: [http://www.microsoft.com/technet/technetmag/issues/2007/02/VistaKernel/default.aspx Inside the Windows Vista Kernel: Part 1] – File-based symbolic links, Microsoft Technet, February 2007.] if this is not the desired behavior, it must be changed in the Local Security Policy management console.

hortcuts

Symbolic links resemble shortcuts, which are supported by the graphical file browsers of some operating systems, but differ in a number of important ways. One difference is what type of software is able to follow them:
* Symbolic links are automatically resolved by the file system. Any software programs, upon accessing a symbolic link, will see the target instead, whether the program is aware of symbolic links or not.
* Shortcuts are treated like ordinary files by the files system and by software programs that are not aware of them. Only software programs that understand shortcuts (such as the Windows shell and file browsers) treat them as references to other files.

Another difference are the capabilities of the mechanism:
* Microsoft Windows shortcuts can only refer to a destination by an absolute path (starting from the root directory), whereas POSIX symbolic links can refer to destinations via either an absolute or a relative path. The latter is useful if both the location and destination of the symbolic link share a common path prefix, but that prefix is not yet known when the symbolic link is created (e.g., in an archive file that can be unpacked anywhere).
* Microsoft Windows application shortcuts contain additional metadata that can be associated with the destination, whereas POSIX symbolic links are just strings that will be interpreted as absolute or relative pathnames.

Cygwin symlinks

Cygwin simulates POSIX-compliant symbolic links in the Microsoft Windows file system. It uses identical programming and user utility interfaces as Unix (see above), but creates Windows shortcuts (.lnk files) with additional information used by Cygwin at the time of symlink resolution. Cygwin symlinks are compliant with both Windows and POSIX standards.

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 [ [http://www.cygwin.com/cygwin-ug-net/using-effectively.html#id325160] Microsoft .lnk files in Cygwin]

The Cygwin User's Guide [ [http://www.cygwin.com/cygwin-ug-net/using.html] Cygwin User's Guide, Cygwin.] has more information on this topic.

Others

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 NetBSD, DragonFly BSD and Domain/OS.

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

References

External links

* [http://linuxgazette.net/105/pitcher.html Q & A: The difference between hard and soft links] Detailed and easy to understand


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Symbolic Link — SYLK, pour SYmbolic LinK, est un format d échange de données créée par la société Microsoft. Destiné à l origine aux échanges entre tableurs il permet aussi l échange avec d autres type de logiciels : traitements de texte, base de données.… …   Wikipédia en Français

  • symbolic link — virtualusis katalogas statusas T sritis informatika apibrėžtis Naujai sukurtas katalogo vardas, susietas su jau egzistuojančiu realiu katalogu, kurį galima toliau vartoti vietoj realaus katalogo vardo. Virtualusis katalogas faktiškai yra… …   Enciklopedinis kompiuterijos žodynas

  • SYmbolic LinK (SYLK) — is a Microsoft file format typically used to exchange data between applications, specifically spreadsheets. SYLK files conventionally have a .slk suffix. From within a spreadsheet data can be exported in the SYLK format. Composed of only… …   Wikipedia

  • Symbolic link — Eine symbolische Verknüpfung, auch symbolischer Link, Symlink oder Softlink genannt, ist eine Verknüpfung in einem Dateisystem (Datei oder Verzeichnis), die auf eine andere Datei oder ein anderes Verzeichnis verweist. Es ist also lediglich eine… …   Deutsch Wikipedia

  • symbolic link — noun A file that contains a reference to another file or directory and serves as a shortcut to it. Syn: shortcut, symlink …   Wiktionary

  • NTFS symbolic link — A NTFS symbolic link (symlink) is a filesystem object in the NTFS filesystem that points to another filesystem object. The object being pointed to is called the target. Symbolic links should be transparent to users; the links appear as normal… …   Wikipedia

  • Link — may refer to:ComputingInternet* Links (web browser), a web browser for Unix like systems * Reciprocal link, two way links to and from websites, also known as link swaps , link exchanges and link partners * Hyperlink, a reference in a hypertext… …   Wikipedia

  • Link (The Matrix) — Link, played by actor Harold Perrineau, serves as the ship s Operator for the crew of the Zion hovercraft Nebuchadnezzar in the movies The Matrix Reloaded and The Matrix Revolutions .Like other character names in the saga, the name Link has… …   Wikipedia

  • NTFS symbolic link — …   Википедия

  • Symbolic (Death album) — Infobox Album | Name = Symbolic Type = studio Artist = Death Released = March 21, 1995 Recorded = Genre = Death metal, progressive metal, technical death metal Length = 50:38 Label = Roadrunner Producer = Jim Morris Reviews = * Allmusic… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”