1994-05-26 06:18:55 +00:00
|
|
|
.\" Copyright (c) 1992, 1993, 1994
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" @(#)symlink.7 8.3 (Berkeley) 3/31/94
|
1999-08-27 23:15:48 +00:00
|
|
|
.\" $FreeBSD$
|
1994-05-26 06:18:55 +00:00
|
|
|
.\"
|
|
|
|
.Dd March 31, 1994
|
|
|
|
.Dt SYMLINK 7
|
2001-07-10 10:04:09 +00:00
|
|
|
.Os
|
1994-05-26 06:18:55 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm symlink
|
|
|
|
.Nd symbolic link handling
|
|
|
|
.Sh SYMBOLIC 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.
|
|
|
|
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
|
2002-05-16 01:57:20 +00:00
|
|
|
on different filesystems.
|
1994-05-26 06:18:55 +00:00
|
|
|
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
|
2002-05-16 01:57:20 +00:00
|
|
|
filesystems.
|
1994-05-26 06:18:55 +00:00
|
|
|
.Pp
|
|
|
|
Because a symbolic link and its referenced object coexist in the filesystem
|
|
|
|
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.
|
|
|
|
.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
|
|
|
|
.Dq 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 doesn't 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.)
|
|
|
|
.Pp
|
|
|
|
There are three separate areas that need to be discussed.
|
|
|
|
They are as follows:
|
2000-11-10 17:46:15 +00:00
|
|
|
.Pp
|
1994-05-26 06:18:55 +00:00
|
|
|
.Bl -enum -compact -offset indent
|
|
|
|
.It
|
|
|
|
Symbolic links used as file name arguments for system calls.
|
|
|
|
.It
|
|
|
|
Symbolic links specified as command line arguments to utilities that
|
|
|
|
are not traversing a file tree.
|
|
|
|
.It
|
|
|
|
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).
|
|
|
|
.El
|
|
|
|
.Ss System calls.
|
|
|
|
The first area is symbolic links used as file name arguments for
|
|
|
|
system calls.
|
|
|
|
.Pp
|
|
|
|
Except as noted below, all system calls follow symbolic links.
|
|
|
|
For example, if there were a symbolic link
|
|
|
|
.Dq Li slink
|
|
|
|
which pointed to a file named
|
|
|
|
.Dq Li afile ,
|
|
|
|
the system call
|
2000-12-15 17:37:31 +00:00
|
|
|
.Dq Li open("slink" ...\&)
|
1994-05-26 06:18:55 +00:00
|
|
|
would return a file descriptor to the file
|
|
|
|
.Dq afile .
|
|
|
|
.Pp
|
2001-01-24 23:49:59 +00:00
|
|
|
There are six system calls that do not follow links, and which operate
|
1994-05-26 06:18:55 +00:00
|
|
|
on the symbolic link itself.
|
|
|
|
They are:
|
1997-06-03 06:27:44 +00:00
|
|
|
.Xr lchown 2 ,
|
1994-05-26 06:18:55 +00:00
|
|
|
.Xr lstat 2 ,
|
|
|
|
.Xr readlink 2 ,
|
|
|
|
.Xr rename 2 ,
|
2001-01-24 23:49:59 +00:00
|
|
|
.Xr rmdir 2 ,
|
1994-05-26 06:18:55 +00:00
|
|
|
and
|
|
|
|
.Xr unlink 2 .
|
|
|
|
Because
|
|
|
|
.Xr remove 3
|
|
|
|
is an alias for
|
|
|
|
.Xr unlink 2 ,
|
|
|
|
it also does not follow symbolic links.
|
2001-01-24 23:49:59 +00:00
|
|
|
When
|
|
|
|
.Xr rmdir 2
|
|
|
|
is applied to a symbolic link, it fails with the error
|
|
|
|
.Er ENOTDIR .
|
1994-05-26 06:18:55 +00:00
|
|
|
.Pp
|
1997-06-19 01:07:05 +00:00
|
|
|
The owner and group of an existing symbolic link can be changed by
|
|
|
|
means of the
|
|
|
|
.Xr lchown 2
|
|
|
|
system call.
|
|
|
|
The other file attributes, such as the modification time and access
|
|
|
|
permissions, are not used by the system and cannot be changed.
|
1994-05-26 06:18:55 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Bx 4.4
|
2001-08-14 10:01:54 +00:00
|
|
|
system differs from historical
|
|
|
|
.Bx 4
|
|
|
|
systems in that the system call
|
1994-05-26 06:18:55 +00:00
|
|
|
.Xr chown 2
|
2000-03-01 11:34:08 +00:00
|
|
|
has been changed to follow symbolic links.
|
|
|
|
The
|
1997-06-03 06:27:44 +00:00
|
|
|
.Xr lchown 2
|
|
|
|
system call was added later when the limitations of the new
|
|
|
|
.Xr chown 2
|
|
|
|
became apparent.
|
1994-05-26 06:18:55 +00:00
|
|
|
.Ss 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.
|
|
|
|
.Pp
|
|
|
|
Except as noted below, commands follow symbolic links named as command
|
|
|
|
line arguments.
|
2001-07-15 07:53:42 +00:00
|
|
|
For example, if there were a symbolic link
|
1994-05-26 06:18:55 +00:00
|
|
|
.Dq Li slink
|
|
|
|
which pointed to a file named
|
|
|
|
.Dq Li afile ,
|
|
|
|
the command
|
|
|
|
.Dq Li cat slink
|
|
|
|
would display the contents of the file
|
|
|
|
.Dq Li afile .
|
|
|
|
.Pp
|
|
|
|
It is important to realize that this rule includes commands which may
|
|
|
|
optionally traverse file trees, e.g. the command
|
|
|
|
.Dq Li "chown file"
|
|
|
|
is included in this rule, while the command
|
|
|
|
.Dq Li "chown -R file"
|
|
|
|
is not.
|
|
|
|
(The latter is described in the third area, below.)
|
|
|
|
.Pp
|
1999-04-24 10:08:09 +00:00
|
|
|
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
|
|
|
|
.Dq Li "chown slink"
|
|
|
|
change the ownership of the file that
|
|
|
|
.Dq Li slink
|
|
|
|
is, whether it is a symbolic link or not, the
|
|
|
|
.Fl h
|
|
|
|
option should be used.
|
|
|
|
In the above example,
|
|
|
|
.Dq Li "chown root slink"
|
|
|
|
would change the ownership of the file referenced by
|
|
|
|
.Dq Li slink ,
|
|
|
|
while
|
|
|
|
.Dq Li "chown -h root slink"
|
|
|
|
would change the ownership of
|
|
|
|
.Dq Li slink
|
|
|
|
itself.
|
|
|
|
.Pp
|
1999-04-14 18:45:07 +00:00
|
|
|
There are four exceptions to this rule.
|
1994-05-26 06:18:55 +00:00
|
|
|
The
|
|
|
|
.Xr mv 1
|
|
|
|
and
|
|
|
|
.Xr 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.)
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Xr ls 1
|
|
|
|
command is also an exception to this rule.
|
|
|
|
For compatibility with historic systems (when
|
|
|
|
.Nm ls
|
|
|
|
is not doing a tree walk, i.e. the
|
|
|
|
.Fl R
|
|
|
|
option is not specified),
|
|
|
|
the
|
|
|
|
.Nm ls
|
|
|
|
command follows symbolic links named as arguments if the
|
1998-04-24 12:38:18 +00:00
|
|
|
.Fl H
|
|
|
|
or
|
1994-05-26 06:18:55 +00:00
|
|
|
.Fl L
|
|
|
|
option is specified,
|
|
|
|
or if the
|
|
|
|
.Fl F ,
|
|
|
|
.Fl d
|
|
|
|
or
|
|
|
|
.Fl l
|
1998-04-24 12:38:18 +00:00
|
|
|
options are not specified. (The
|
1994-05-26 06:18:55 +00:00
|
|
|
.Nm ls
|
1998-04-24 12:38:18 +00:00
|
|
|
command is the only command where the
|
|
|
|
.Fl H
|
|
|
|
and
|
1994-05-26 06:18:55 +00:00
|
|
|
.Fl L
|
1998-04-24 12:38:18 +00:00
|
|
|
options affect its behavior even though it is not doing a walk of
|
1994-05-26 06:18:55 +00:00
|
|
|
a file tree.)
|
|
|
|
.Pp
|
|
|
|
The
|
1999-04-14 18:45:07 +00:00
|
|
|
.Xr file 1
|
|
|
|
command is also an exception to this rule.
|
|
|
|
The
|
|
|
|
.Xr file 1
|
|
|
|
command does not follow symbolic links named as argument by default.
|
2001-07-15 07:53:42 +00:00
|
|
|
The
|
1999-04-14 18:45:07 +00:00
|
|
|
.Xr file 1
|
|
|
|
command does follow symbolic links named as argument if
|
|
|
|
.Fl L
|
|
|
|
option is specified.
|
|
|
|
.Pp
|
|
|
|
The
|
1994-05-26 06:18:55 +00:00
|
|
|
.Bx 4.4
|
2001-08-14 10:01:54 +00:00
|
|
|
system differs from historical
|
|
|
|
.Bx 4
|
|
|
|
systems in that the
|
1999-04-14 18:45:07 +00:00
|
|
|
.Nm chown
|
1994-05-26 06:18:55 +00:00
|
|
|
and
|
1999-04-14 18:45:07 +00:00
|
|
|
.Nm chgrp
|
1994-05-26 06:18:55 +00:00
|
|
|
commands follow symbolic links specified on the command line.
|
|
|
|
.Ss Commands traversing a file tree.
|
|
|
|
The following commands either optionally or always traverse file trees:
|
|
|
|
.Xr chflags 1 ,
|
|
|
|
.Xr chgrp 1 ,
|
|
|
|
.Xr chmod 1 ,
|
|
|
|
.Xr cp 1 ,
|
|
|
|
.Xr du 1 ,
|
|
|
|
.Xr find 1 ,
|
|
|
|
.Xr ls 1 ,
|
|
|
|
.Xr pax 1 ,
|
|
|
|
.Xr rm 1 ,
|
|
|
|
.Xr tar 1
|
|
|
|
and
|
|
|
|
.Xr chown 8 .
|
|
|
|
.Pp
|
|
|
|
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.
|
|
|
|
.Pp
|
|
|
|
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.
|
|
|
|
.Pp
|
|
|
|
For example, the command
|
|
|
|
.Dq Li "chown -R user slink directory"
|
|
|
|
will ignore
|
|
|
|
.Dq Li slink ,
|
|
|
|
because symbolic links in this system do not have owners.
|
|
|
|
Any symbolic links encountered during the tree traversal will also be
|
|
|
|
ignored.
|
|
|
|
The command
|
|
|
|
.Dq Li "rm -r slink directory"
|
|
|
|
will remove
|
|
|
|
.Dq Li slink ,
|
|
|
|
as well as any symbolic links encountered in the tree traversal of
|
|
|
|
.Dq Li directory ,
|
|
|
|
because symbolic links may be removed.
|
|
|
|
In no case will either
|
|
|
|
.Nm chown
|
|
|
|
or
|
|
|
|
.Nm rm
|
|
|
|
affect the file which
|
|
|
|
.Dq Li slink
|
|
|
|
references in any way.
|
|
|
|
.Pp
|
|
|
|
The second rule applies to symbolic links that reference files of type
|
|
|
|
directory.
|
|
|
|
Symbolic links which reference files of type directory are never
|
|
|
|
.Dq followed
|
|
|
|
by default.
|
|
|
|
This is often referred to as a
|
|
|
|
.Dq physical
|
|
|
|
walk, as opposed to a
|
|
|
|
.Dq logical
|
|
|
|
walk (where symbolic links referencing directories are followed).
|
|
|
|
.Pp
|
|
|
|
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
|
2001-07-15 07:53:42 +00:00
|
|
|
.Fl H
|
1994-05-26 06:18:55 +00:00
|
|
|
(for
|
|
|
|
.Dq 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
|
|
|
|
.Fl H
|
|
|
|
flag will be ignored if the
|
|
|
|
.Fl R
|
|
|
|
flag is not also specified.)
|
|
|
|
.Pp
|
|
|
|
For example, the command
|
|
|
|
.Dq Li "chown -HR user slink"
|
|
|
|
will traverse the file hierarchy rooted in the file pointed to by
|
|
|
|
.Dq Li slink .
|
1999-04-25 11:58:25 +00:00
|
|
|
Note, the
|
|
|
|
.Fl H
|
|
|
|
is not the same as the previously discussed
|
|
|
|
.Fl h
|
|
|
|
flag.
|
1994-05-26 06:18:55 +00:00
|
|
|
The
|
|
|
|
.Fl H
|
|
|
|
flag causes symbolic links specified on the command line to be
|
|
|
|
dereferenced both for the purposes of 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.
|
|
|
|
.Pp
|
|
|
|
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
|
|
|
|
.Fl L
|
|
|
|
(for
|
|
|
|
.Dq 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
|
|
|
|
.Fl L
|
|
|
|
flag will be ignored if the
|
|
|
|
.Fl R
|
|
|
|
flag is not also specified.)
|
|
|
|
.Pp
|
|
|
|
For example, the command
|
|
|
|
.Dq Li "chown -LR user slink"
|
|
|
|
will change the owner of the file referenced by
|
|
|
|
.Dq Li slink .
|
|
|
|
If
|
|
|
|
.Dq Li slink
|
|
|
|
references a directory,
|
|
|
|
.Nm 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
|
|
|
|
.Nm chown
|
|
|
|
traverses, they will be treated in the same fashion as
|
|
|
|
.Dq Li slink .
|
|
|
|
.Pp
|
|
|
|
As consistently as possible, you can specify the default behavior by
|
|
|
|
specifying the
|
|
|
|
.Fl P
|
|
|
|
(for
|
|
|
|
.Dq physical )
|
|
|
|
flag.
|
|
|
|
This flag is intended to make the entire name space look like the
|
|
|
|
physical name space.
|
|
|
|
.Pp
|
|
|
|
For commands that do not by default do file tree traversals, the
|
|
|
|
.Fl H ,
|
|
|
|
.Fl L
|
|
|
|
and
|
|
|
|
.Fl P
|
|
|
|
flags are ignored if the
|
|
|
|
.Fl R
|
|
|
|
flag is not also specified.
|
|
|
|
In addition, you may specify the
|
|
|
|
.Fl H ,
|
|
|
|
.Fl L
|
|
|
|
and
|
|
|
|
.Fl P
|
|
|
|
options more than once; the last one specified determines the
|
|
|
|
command's behavior.
|
|
|
|
This is intended to permit you to alias commands to behave one way
|
|
|
|
or the other, and then override that behavior on the command line.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Xr ls 1
|
|
|
|
and
|
|
|
|
.Xr rm 1
|
|
|
|
commands have exceptions to these rules.
|
|
|
|
The
|
|
|
|
.Nm rm
|
|
|
|
command operates on the symbolic link, and not the file it references,
|
|
|
|
and therefore never follows a symbolic link.
|
|
|
|
The
|
|
|
|
.Nm rm
|
|
|
|
command does not support the
|
|
|
|
.Fl H ,
|
|
|
|
.Fl L
|
|
|
|
or
|
|
|
|
.Fl P
|
|
|
|
options.
|
|
|
|
.Pp
|
|
|
|
To maintain compatibility with historic systems,
|
|
|
|
the
|
|
|
|
.Nm ls
|
1998-04-24 12:38:18 +00:00
|
|
|
command acts a little differently. If you do not specify the
|
|
|
|
.Fl F ,
|
2000-09-06 20:09:39 +00:00
|
|
|
.Fl d
|
|
|
|
or
|
1998-04-24 12:38:18 +00:00
|
|
|
.Fl l
|
|
|
|
options,
|
|
|
|
.Nm ls
|
|
|
|
will follow symbolic links specified on the command line. If the
|
1994-05-26 06:18:55 +00:00
|
|
|
.Fl L
|
|
|
|
flag is specified,
|
|
|
|
.Nm ls
|
|
|
|
follows all symbolic links,
|
|
|
|
regardless of their type,
|
|
|
|
whether specified on the command line or encountered in the tree walk.
|
|
|
|
.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 pax 1 ,
|
|
|
|
.Xr rm 1 ,
|
|
|
|
.Xr tar 1 ,
|
1997-06-03 06:27:44 +00:00
|
|
|
.Xr lchown 2 ,
|
1994-05-26 06:18:55 +00:00
|
|
|
.Xr lstat 2 ,
|
|
|
|
.Xr readlink 2 ,
|
|
|
|
.Xr rename 2 ,
|
1997-06-03 06:27:44 +00:00
|
|
|
.Xr symlink 2 ,
|
1994-05-26 06:18:55 +00:00
|
|
|
.Xr unlink 2 ,
|
|
|
|
.Xr fts 3 ,
|
|
|
|
.Xr remove 3 ,
|
|
|
|
.Xr chown 8
|