minor wordsmithing
[unix-history] / usr / src / bin / ln / symlink.7
.\" Copyright (c) 1992 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" %sccs.include.redist.roff%
.\"
.\" @(#)symlink.7 5.2 (Berkeley) %G%
.\"
.Dd
.Dt SYMLINK 7
.Os BSD 4
.Sh NAME
.Nm symlink
.Nd symbolic link handling
.Sh SYMBOLIC LINK HANDLING
Due to the fact that 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. Traditionally, utilities and system calls
have adopted their own link following conventions in an ad-hoc fashion.
Rules for more a uniform approach are outlined here.
.Pp
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 links are
dereferenced until an object which is not a symbolic link is found.
Cycles are avoided by
placing an upper limit on the number of links that may be followed.
An error results if this limit is exceeded.
.Pp
There are three domains for which symbolic link policy is established:
system calls that take file name arguments,
utilities that take file name arguments, and
utilities that traverse file hierarchies.
.Pp
The system calls that do not follow symbolic links are
.Xr lstat 2 ,
.Xr readlink 2 ,
.Xr rename 2 ,
and
.Xr unlink 2 .
All other system calls follow the symbolic link.
.Pp
The utilities that do not follow symbolic links named as arguments
are
.Xr mv 1
and
.Xr rm 1 .
For compatibility with historic systems, the
.Xr ls 1
utility follows symbolic links listed on the command line, unless the
.Fl F ,
.Fl d
or
.Fl l
options are specified.
However, if the
.Fl L
option is specified,
.Xr ls 1
always follows symbolic links.
All other utilities follow symbolic links listed on the command line.
.Pp
The third issue in symbolic link handling is traversal of a file
hierarchy.
File hierarchies can be traversed either ``logically'', by following
symbolic links that point to directories, or ``physically'', by not
following such links.
.Pp
The following utilities can perform traversals:
.Xr chflags 1 ,
.Xr chgrp 1 ,
.Xr chmod 1 ,
.Xr chown 8 ,
.Xr cp 1 ,
.Xr du 1 ,
.Xr find 1 ,
.Xr ls 1 ,
.Xr rm 1
and
.Xr tar 1 .
All of these utilities, except for
.Xr cp ,
.Xr ls
and
.Xr rm ,
operate according to the following rules.
.Pp
By default, these utilities do a physical traversal, never following any
symbolic links.
If the
.Fl H
option is specified, the utility will follow symbolic links specified
on the command line.
If the
.Fl h
option is specified, the utilities do a logical traversal, following all
symbolic links whether specified on the command line or encountered while
descending the file hierarchy.
The
.Fl H
flag is intended to make the command line name space look like the logical
name space and the
.Fl h
flag is intended to make the entire hierarchy look like the logical name
space.
.Pp
The utilities
.Xr cp ,
.Xr ls
and
.Xr rm
are exceptions to these rules.
.Pp
To maintain compatibility with historic systems,
.Xr cp
always follows symbolic links on the command line.
The
.Fl H
and
.Fl h
options have the effects described above only when the
.Fl R
flag is specified.
.Pp
.Xr Rm
operates on the name, not the object it points to, and therefore never
follows a symbolic link.
The
.Xr rm
utility does not support the
.Fl H
or
.Fl h
options.
.Pp
To maintain compatibility with historic systems, the
.Xr ls
utility follows all symbolic links in the file hierarchy, including ones
listed on the command line, only when the
.Fl L
option is specified.
The
.Xr ls
utility does not support the
.Fl H
or
.Fl h
options.
.Sh SEE ALSO
.Xr chflags 1 ,
.Xr chgrp 1 ,
.Xr chmod 1 ,
.Xr cp 1 ,
.Xr du 1 ,
.Xr find 1 ,
.Xr ln 1 ,
.Xr ls 1 ,
.Xr mv 1 ,
.Xr rm 1 ,
.Xr tar 1 ,
.Xr lstat 2 ,
.Xr readlink 2 ,
.Xr rename 2 ,
.Xr unlink 2 ,
.Xr chown 8