Symbolic link

A symbolic link (often symlink, especially in verb form, or soft link) is a special type of directory entry in modern Unix (or Unix-like) filesystems that allows to almost transparently refer to another directory entry, typically a file or a directory.

Usage

Symbolic links are created with the ln -s command. For example:

ln -s name_of_real_file name_of_link

Although this syntax is identical to the one of the cp command, it is significantly counter-intuitive, often leading to surprising results with symlinks to directories (the link gets created inside the directory and points to itself).

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.

Symbolic links can be dangerous in the hands of novice computer users. Although at first glance links to files create the illusion of the file being present in several locations at once, just as hard links, these locations are not equivalent and deleting the wrong pathname destroys the file completely.

Symbolic links to directories can be lethal with unaware programs working with directory trees. At best they can cause endless looping as well as pathname buffer overflows leading to crashes or dangerous malfunctions. At worst, deleting a directory tree will lead to the content of the symlinked directories being deleted as well. Unix tries to protect against this behavior to some extent by disallowing to destroy a directory symlink using the remove-directory (rmdir) system call, hence symlink-unaware programs will generally fail after trying to delete the first such link.

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.

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 the standard data structures used for storing file information on disk and called the inode. This space is generally the one otherwise used for storing the chain of disk blocks composing a file (60 bytes on the standard UFS filesystem). 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 the available inode space, or for disk compatibility with other or older versions of the operating system. The original style has been retroactively termed slow symlinks.

Although storing the link value inside the inode allows to save a disk block and a disk read, it is still necessary to parse the pathname information in the link, which always requires reading an additional inode and generally requires reading other, potentially many directories, both the list of files and the inodes of each of them until matches are found with link pathname components. Only when a link points to a file inside the same directory are the performance gains really dramatic.

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 joints (this requires NTFS 5.0), which are more similar to symbolic links than Windows shortcuts.

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

ja:ソフトリンク pl:Dowiązanie symboliczne

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools