symlink(7) Miscellaneous Information Manual symlink(7) symlink - -- , . , . , , ( : -- inode, inode -- inode, ; stat(2)). . ( , ) ( inode ). -- , , -- , ( readlink(2)). , -- , . , . , , . , , (dangling link). , , , , . , , . , Linux . , , . Magic links There is a special class of symbolic-link-like objects known as "magic links", which can be found in certain pseudofilesystems such as proc(5) (examples include /proc/pid/exe and /proc/pid/fd/*). Unlike normal symbolic links, magic links are not resolved through pathname-expansion, but instead act as direct references to the kernel's own representation of a file handle. As such, these magic links allow users to access files which cannot be referenced with normal paths (such as unlinked files still referenced by a running program ). Because they can bypass ordinary mount_namespaces(7)-based restrictions, magic links have been used as attack vectors in various exploits. , The owner and group of an existing symbolic link can be changed using lchown(2). The ownership of a symbolic link matters when the link is being removed or renamed in a directory that has the sticky bit set (see inode(7)), and when the fs.protected_symlinks sysctl is set (see proc(5)). utimensat(2) lutimes(3). On Linux, the permissions of an ordinary symbolic link are not used in any operations; the permissions are always 0777 (read, write, and execute for all user categories), and can't be changed. However, magic links do not follow this rule. They can have a non-0777 mode, though this mode is not currently used in any permission checks. , ( , ) O_PATH O_NOFOLLOW open(2) , dirfd fstatat(2), fchownat(2), fchmodat(2), linkat(2) readlinkat(2). (. ., AT_SYMLINK_FOLLOW), name_to_handle_at(2) , ( , ). ( , ), O_PATH open_by_handle_at(2). . , . , (follow) . ; , , , , ( , ). , : o . o , , . o , ( ). Before describing the treatment of symbolic links by system calls and commands, we require some terminology. Given a pathname of the form a/b/c, the part preceding the final slash (i.e., a/b) is called the dirname component, and the part following the final slash (i.e., c) is called the basename component. Treatment of symbolic links in system calls . The treatment of symbolic links within a pathname passed to a system call is as follows: (1) Within the dirname component of a pathname, symbolic links are always followed in nearly every system call. (This is also true for commands.) The one exception is openat2(2), which provides flags that can be used to explicitly prevent following of symbolic links in the dirname component. (2) Except as noted below, all system calls follow symbolic links in the basename component of a pathname. For example, if there were a symbolic link slink which pointed to a file named afile, the system call open("slink" ...) would return a file descriptor referring to the file afile. Various system calls do not follow links in the basename component of a pathname, and operate on the symbolic link itself. They are: lchown(2), lgetxattr(2), llistxattr(2), lremovexattr(2), lsetxattr(2), lstat(2), readlink(2), rename(2), rmdir(2), and unlink(2). Certain other system calls optionally follow symbolic links in the basename component of a pathname. They are: faccessat(2), fchownat(2), fstatat(2), linkat(2), name_to_handle_at(2), open(2), openat(2), open_by_handle_at(2), and utimensat(2); see their manual pages for details. Because remove(3) is an alias for unlink(2), that library function also does not follow symbolic links. When rmdir(2) is applied to a symbolic link, it fails with the error ENOTDIR. link(2) . POSIX.1-2001 , link(2) oldpath, . Linux ( Solaris , POSIX.1-2001 ). POSIX.1-2008 , . , , , . , , , . , slink -- , afile, cat slink afile. , , ; , chown file , chown -R file, , ( ). If it is explicitly intended that the command operate on the symbolic link instead of following the symbolic link--for example, it is desired that chown slink change the ownership of the file that slink is, whether it is a symbolic link or not--then the -h option should be used. In the above example, chown root slink would change the ownership of the file referred to by slink, while chown -h root slink would change the ownership of slink itself. : o mv(1) rm(1) , , (, , , ). o The ls(1) command is also an exception to this rule. For compatibility with historic systems (when ls(1) is not doing a tree walk--that is, -R option is not specified), the ls(1) command follows symbolic links named as arguments if the -H or -L option is specified, or if the -F, -d, or -l options are not specified. (The ls(1) command is the only command where the -H and -L options affect its behavior even though it is not doing a walk of a file tree.) o file(1) . file(1) , . file(1) , , -L. , : chgrp(1), chmod(1), chown(1), cp(1), du(1), find(1), ls(1), pax(1), rm(1) tar(1). , , , , . , , . , , , . rm -r slink slink, , , . rm(1) , slink. , . . <<>> , <<>> ( , ). () , : o , , , , -H ( <>). (, , , -H, -R). , chown -HR user slink , slink. , -H , -h, . -H , , , . o , , , , , , -H ( <>). (, , , -L, -R). , chown -LR user slink , slink. slink , chown . , , chown, slink. o , -P ( <>). . , , -H, -L -P, -R. -H, -L -P ; . , . ls(1) rm(1) : o rm(1) , , , . rm(1) -H, -L -P. o ls(1) . -F, -d -l, ls(1) , . -L, ls(1) -- . . chgrp(1), chmod(1), find(1), ln(1), ls(1), mv(1), namei(1), rm(1), lchown(2), link(2), lstat(2), readlink(2), rename(2), symlink(2), unlink(2), utimensat(2), lutimes(3), path_resolution(7) Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . symlink(7)