1symlink(7) Miscellaneous Information Manual symlink(7)
2
3
4
6 symlink - symbolic link handling
7
9 Symbolic links are files that act as pointers to other files. To un‐
10 derstand their behavior, you must first understand how hard links work.
11
12 A hard link to a file is indistinguishable from the original file be‐
13 cause it is a reference to the object underlying the original filename.
14 (To be precise: each of the hard links to a file is a reference to the
15 same inode number, where an inode number is an index into the inode ta‐
16 ble, which contains metadata about all files on a filesystem. See
17 stat(2).) Changes to a file are independent of the name used to refer‐
18 ence the file. Hard links may not refer to directories (to prevent the
19 possibility of loops within the filesystem tree, which would confuse
20 many programs) and may not refer to files on different filesystems (be‐
21 cause inode numbers are not unique across filesystems).
22
23 A symbolic link is a special type of file whose contents are a string
24 that is the pathname of another file, the file to which the link
25 refers. (The contents of a symbolic link can be read using read‐
26 link(2).) In other words, a symbolic link is a pointer to another
27 name, and not to an underlying object. For this reason, symbolic links
28 may refer to directories and may cross filesystem boundaries.
29
30 There is no requirement that the pathname referred to by a symbolic
31 link should exist. A symbolic link that refers to a pathname that does
32 not exist is said to be a dangling link.
33
34 Because a symbolic link and its referenced object coexist in the
35 filesystem name space, confusion can arise in distinguishing between
36 the link itself and the referenced object. On historical systems, com‐
37 mands and system calls adopted their own link-following conventions in
38 a somewhat ad-hoc fashion. Rules for a more uniform approach, as they
39 are implemented on Linux and other systems, are outlined here. It is
40 important that site-local applications also conform to these rules, so
41 that the user interface can be as consistent as possible.
42
43 Magic links
44 There is a special class of symbolic-link-like objects known as "magic
45 links", which can be found in certain pseudofilesystems such as proc(5)
46 (examples include /proc/pid/exe and /proc/pid/fd/*). Unlike normal
47 symbolic links, magic links are not resolved through pathname-expan‐
48 sion, but instead act as direct references to the kernel's own repre‐
49 sentation of a file handle. As such, these magic links allow users to
50 access files which cannot be referenced with normal paths (such as un‐
51 linked files still referenced by a running program ).
52
53 Because they can bypass ordinary mount_namespaces(7)-based restric‐
54 tions, magic links have been used as attack vectors in various ex‐
55 ploits.
56