Symbolic link

from Wikipedia, the free encyclopedia

A symbolic link , also called a symbolic link , symlink or softlink , is a link in a file system ( files and directories ) that refers to another file or another directory. It is only a reference to the target file or the target directory. Deleting or moving the actual file usually leads to the reference “pointing nowhere”. Unlike a hard link , this reference is not equivalent to the actual file system entry of the referenced file.

Unixoid systems

In a Unix-like system (e.g. Unix , Linux or Mac OS ) you can create a symbolic link with the following command

ln -s /Zieldatei /Referenz

or more understandable

ln -s /Pfad_1/echte_Datei /Pfad_2/Symlink

You can also create a link called "/ home / wiki / nullink" that points to / dev / null :

ln -s /dev/null /home/wiki/nullink

You can find out whether the file "/ home / wiki / nullink" is a symbolic link with one of these commands:

file /home/wiki/nullink
ls -l /home/wiki/nullink

The difference between a symbolic link and a hard link is that a symbolic link points to a path; H. technically it is a text file with a path like /usr/lib/anton.tar as content and a mark that it is a symbolic link. A hard link, on the other hand, points to the file (or the directory, which is just a special type of file) itself, technically usually represented by an inode , which means that a hard link still works if the target file is renamed or on the same partition (or on the same "volume") (the inode is retained). However, if a symbolic link points to it, it does not notice anything if the target file is moved or renamed, which means that the symbolic link then points to nothing. The same applies if a symbolic link with a relative destination itself is moved, since it describes the path (path) to the destination starting from its old location.

The advantage of symbolic links is that they cross partitions and file systems and can also refer to directories without any problems, which is not the case with hard links. Hard links to directories are possible in principle, but should be avoided and generally only allowed to be created by the system administrator. Symbolic links can confuse users because at first glance it appears that the linked file is in multiple directories at the same time; however, deleting the original file means that all symbolic links that refer to it go to nothing and the file is therefore lost (the remaining links that point to nothing are also called broken symlinks ). With hard links, this is only the case if the last name, i.e. H. the last reference to this file was deleted.

Symbolic links to directories can be problematic if users or programs are ignorant of directory trees. An endless loop can easily arise and the directory path buffer overflows , which can lead to crashes or dangerous malfunctions. Deleting a directory tree can also result in the contents of the symbolically linked directory being deleted as well.

Unix tries to prevent this to a certain extent by forbidding the deletion of a symbolic link to a directory using the system command "rmdir", so that programs that do not know about symbolic links receive an error message and fail if they try to remove such a link. The command " rm -r", however, removes the symbolic link, but not its target.

Desktop shortcuts

Desktop environments such as KDE Plasma Workspaces or Gnome offer the possibility of creating and using so-called shortcuts ( en : "spatial abbreviation") on Unixoid systems, which normally have the ending *.desktop. These are file links that consist of a text file and have a structure similar to INI files . This configuration file can define a path or command, labels, help texts, symbols and various other attributes that the desktop can interpret and execute. In contrast to symbolic links, these shortcuts are not transparent for applications and users. Therefore they can be compared with the Windows shortcuts or MacOS alias , but offer more functions than these.

MacOS

As a Unix system, Mac OS can also handle hard and symbolic links. The former are usually not used, except in Apple's own file backup Time Machine . As usual in Unix, symbolic links are created via the command line.

In addition, MacOS inherited so-called aliases from its predecessor, Mac OS Classic , special files with hidden properties that refer to another file or folder. They are much more powerful than the Windows shortcuts or desktop shortcuts, as the support for these aliases is deeply anchored in the operating system (in classic MacOS in the Alias ​​Manager ). An alias can also follow a file that has been moved on the same file system (“volume”). For this purpose, not only the path to the target file, but also its inode number and the volume ID are stored in the hidden information (in the resource fork ).

Windows

Since Windows Vista and Windows Server 2008 (both internally Windows NT 6.0), real symbolic links are available via the Win32 API, which are transparently present in the file system and can refer to files and directories on your own computer. Symbolic links can contain a relative target specification. In contrast to Unix systems, the use of symbolic links is rather uncommon under Windows.

The Create Symbolic Link right is required to create this symbolic link . By default, this is only available to users with administrator rights, but not to the system user 'SYSTEM' . Furthermore, when creating the link it must be known whether the target is a file or a directory. For these reasons, the Windows symbolic links are not fully compatible with POSIX .

Creating symbolic links from Windows Vista:

 c:\>mklink "C:\EinLink.pdf" "D:\EinDokument.pdf"
 c:\>mklink /d "D:\Pfad1\Neues Verzeichnis" "..\Pfad2\Reales Verzeichnis"
 c:\>mklink /d "C:\Netzwerkfreigabe" "\\meinserver\meinefreigabe"

The second line shows that the target specification can also be a relative path, which is only resolved when the symbolic link is called, i.e. H. should z. B. D:\Pfad1and D:\Pfad2moved elsewhere, e.g. B. from D:\to D:\Archiv\, the resolution of the symbolic link would still work in contrast to the use of an absolute specification. On the other hand, if D:\Pfad1\, and D:\Pfad2\would no longer share a common parent path, the relative symbolic link then meadow on a no longer existing path.

Show where a symbolic link refers to - the parameter /alfilters the output to symbolic link -:

 c:\>dir /al
 Datenträger in Laufwerk C: ist abc
 Verzeichnis von C:\
 07.12.2010  10:28    <SYMLINK>   EinLink.pdf [D:\EinDokument.pdf]

Deleting symbolic links:

 c:\>del "C:\EinLink.pdf"
 c:\>rmdir "D:\Pfad1\Neues Verzeichnis"
 c:\>rmdir "C:\Netzwerkfreigabe"

Other uses

Since the link target is usually a path to another file, and this is a relatively short character string, symbolic links are stored in a particularly efficient way in many modern file systems, so that no data block has to be allocated for the link target and thus also access to this data can be done very quickly.

The link target can, however, be any character string (not necessarily a path to another file).

Some programs take advantage of these two properties by not storing short data in regular files, but in the link target of a symbolic link (e.g. Mozilla Firefox and Thunderbird to indicate which process is currently using a profile).

Individual evidence

  1. ln man page , found under ln - make links between files. Retrieved May 22, 2014 .
  2. Joe: Anatomy of a Desktop File. In: The Linux Critic. April 7, 2010, accessed February 20, 2014 .
  3. Link - Alias , maceinsteiger.de