|
NAMEsymlink —
symbolic link handling
SYMBOLIC LINK HANDLINGSymbolic links are files that act as pointers to other files. To understand their behavior, you must first understand how hard links work. A hard link to a file is indistinguishable from the original file because it is a reference to the object underlying the original file name. Changes to a file are independent of the name used to reference the file. Hard links may not refer to directories and may not reference files on different file systems. A symbolic link contains the name of the file to which it is linked, i.e., it is a pointer to another name, and not to an underlying object. For this reason, symbolic links may reference directories and may span file systems.Because a symbolic link and its referenced object coexist in the file system name space, confusion can arise in distinguishing between the link itself and the referenced object. Historically, commands and system calls have adopted their own link following conventions in a somewhat ad-hoc fashion. Rules for more a uniform approach, as they are implemented in this system, are outlined here. It is important that local applications conform to these rules, too, so that the user interface can be as consistent as possible. Symbolic links are handled either by operating on the link itself, or by operating on the object referenced by the link. In the latter case, an application or system call is said to “follow” the link. Symbolic links may reference other symbolic links, in which case the links are dereferenced until an object that is not a symbolic link is found, a symbolic link which references 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.) There are three separate areas that need to be discussed. They are as follows:
System calls.The first area is symbolic links used as file name arguments for system calls.Except as noted below, all system calls follow symbolic links. For
example, if there were a symbolic link
“ There are thirteen system calls that do not follow links, and
which operate on the symbolic link itself. They are:
lchflags(2),
lchmod(2),
lchown(2),
lpathconf(2),
lstat(2),
lutimes(2),
readlink(2),
readlinkat(2),
rename(2),
renameat(2),
rmdir(2),
unlink(2),
and
unlinkat(2).
Because
remove(3)
is an alias for
unlink(2),
it also does not follow symbolic links. When
rmdir(2)
or
unlinkat(2)
with the The
linkat(2)
system call does not follow symbolic links unless given the
The following system calls follow symbolic links unless given the
The owner and group of an existing symbolic link can be changed by means of the lchown(2) system call. The flags, access permissions, owner/group and modification time of an existing symbolic link can be changed by means of the lchflags(2), lchmod(2), lchown(2), and lutimes(2) system calls, respectively. Of these, only the flags and ownership are used by the system; the access permissions are ignored. The 4.4BSD system differs from historical 4BSD systems in that the system call chown(2) has been changed to follow symbolic links. The lchown(2) system call was added later when the limitations of the new chown(2) became apparent. Commands not traversing a file tree.The second area is symbolic links, specified as command line file name arguments, to commands which are not traversing a file tree.Except as noted below, commands follow symbolic links named as
command line arguments. For example, if there were a symbolic link
“ It is important to realize that this rule includes commands which
may optionally traverse file trees, e.g. the command
“ If it is explicitly intended that the command operate on the
symbolic link instead of following the symbolic link, e.g., it is desired
that “ There are five exceptions to this rule. 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 The
file(1)
and
stat(1)
commands are also exceptions to this rule. These commands do not follow
symbolic links named as argument by default, but do follow symbolic links
named as argument if the The 4.4BSD system differs from historical
4BSD systems in that the
Commands traversing a file tree.The following commands either optionally or always traverse file trees: chflags(1), chgrp(1), chmod(1), cp(1), du(1), find(1), ls(1), pax(1), rm(1), tar(1) and chown(8).It is important to realize that the following rules apply equally to symbolic links encountered during the file tree traversal and symbolic links listed as command line arguments. The first rule applies to symbolic links that reference files that are not of type directory. Operations that apply to symbolic links are performed on the links themselves, but otherwise the links are ignored. The command “ The second rule applies to symbolic links that reference files of type directory. Symbolic links which reference files of type directory are never “followed” by default. This is often referred to as a “physical” walk, as opposed to a “logical” walk (where symbolic links referencing directories are followed). As consistently as possible, you can make commands doing a file
tree walk follow any symbolic links named on the command line, regardless of
the type of file they reference, by specifying the
For example, the command “ As consistently as possible, you can make commands doing a file
tree walk 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 For example, the command “ As consistently as possible, you can specify the default behavior
by specifying the For commands that do not by default do file tree traversals, the
The
ls(1) and
rm(1)
commands have exceptions to these rules. The To maintain compatibility with historic systems, the
SEE ALSOchflags(1), chgrp(1), chmod(1), cp(1), du(1), find(1), ln(1), ls(1), mv(1), pax(1), rm(1), tar(1), lchflags(2), lchmod(2), lchown(2), lstat(2), lutimes(2), readlink(2), rename(2), symlink(2), unlink(2), fts(3), remove(3), chown(8)
Visit the GSP FreeBSD Man Page Interface. |