table of contents
other versions
- wheezy 3.44-1
- jessie 3.74-1
- jessie-backports 4.10-2~bpo8+1
- testing 4.10-2
- unstable 4.10-2
other sections
| SYMLINK(7) | Linux Programmer's Manual | SYMLINK(7) |
NAME¶
symlink - symbolic link handlingSYMBOLIC LINK HANDLING¶
Symbolic links are files that act as pointers to other files. To understand their behavior, you must first understand how hard links work.Symbolic link ownership, permissions, and timestamps¶
The owner and group of an existing symbolic link can be changed using lchown(2). The only time that the ownership of a symbolic link matters is when the link is being removed or renamed in a directory that has the sticky bit set (see stat(2)).Handling of symbolic links by system calls and commands¶
Symbolic links are handled either by operating on the link itself, or by operating on the object referred to by the link. In the latter case, an application or system call is said to follow the link. Symbolic links may refer to other symbolic links, in which case the links are dereferenced until an object that is not a symbolic link is found, a symbolic link that refers to a file which does not exist is found, or a loop is detected. (Loop detection is done by placing an upper limit on the number of links that may be followed, and an error results if this limit is exceeded.)- 1.
- Symbolic links used as filename arguments for system calls.
- 2.
- Symbolic links specified as command-line arguments to utilities that are not traversing a file tree.
- 3.
- Symbolic links encountered by utilities that are traversing a file tree (either specified on the command line or encountered as part of the file hierarchy walk).
System calls¶
The first area is symbolic links used as filename arguments for system calls.Commands not traversing a file tree¶
The second area is symbolic links, specified as command-line filename arguments, to commands which are not traversing a file tree.- *
- The mv(1) and rm(1) commands do not follow symbolic links named as arguments, but respectively attempt to rename and delete them. (Note, if the symbolic link references a file via a relative path, moving it to another directory may very well cause it to stop working, since the path may no longer be correct.)
- *
- 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, i.e., the -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.)
- *
- The file(1) command is also an exception to this rule. The file(1) command does not follow symbolic links named as argument by default. The file(1) command does follow symbolic links named as argument if the -L option is specified.
Commands traversing a file tree¶
The following commands either optionally or always traverse file trees: chgrp(1), chmod(1), chown(1), cp(1), du(1), find(1), ls(1), pax(1), rm(1), and tar(1).- *
- A command can be made to follow any symbolic links named on
the command line, regardless of the type of file they reference, by
specifying the -H (for "half-logical") flag. This flag is
intended to make the command-line name space look like the logical name
space. (Note, for commands that do not always do file tree traversals, the
-H flag will be ignored if the -R flag is not also
specified.)
For example, the command chown -HR user slink will traverse the file hierarchy rooted in the file pointed to by slink. Note, the -H is not the same as the previously discussed -h flag. The -H flag causes symbolic links specified on the command line to be dereferenced for the purposes of both the action to be performed and the tree walk, and it is as if the user had specified the name of the file to which the symbolic link pointed.
- *
- A command can be made to follow any symbolic links named on
the command line, as well as any symbolic links encountered during the
traversal, regardless of the type of file they reference, by specifying
the -L (for "logical") flag. This flag is intended to
make the entire name space look like the logical name space. (Note, for
commands that do not always do file tree traversals, the -L flag
will be ignored if the -R flag is not also specified.)
For example, the command chown -LR user slink will change the owner of the file referred to by slink. If slink refers to a directory, chown will traverse the file hierarchy rooted in the directory that it references. In addition, if any symbolic links are encountered in any file tree that chown traverses, they will be treated in the same fashion as slink.
- *
- A command can be made to provide the default behavior by specifying the -P (for "physical") flag. This flag is intended to make the entire name space look like the physical name space.
- *
- The rm(1) command operates on the symbolic link, and not the file it references, and therefore never follows a symbolic link. The rm(1) command does not support the -H, -L, or -P options.
- *
- To maintain compatibility with historic systems, the ls(1) command acts a little differently. If you do not specify the -F, -d or -l options, ls(1) will follow symbolic links specified on the command line. If the -L flag is specified, ls(1) follows all symbolic links, regardless of their type, whether specified on the command line or encountered in the tree walk.
SEE ALSO¶
chgrp(1), chmod(1), find(1), ln(1), ls(1), mv(1), rm(1), lchown(2), link(2), lstat(2), readlink(2), rename(2), symlink(2), unlink(2), utimensat(2), lutimes(3), path_resolution(7)COLOPHON¶
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.| 2008-06-18 | Linux |