1 .\" Copyright (c) 1992, 1993, 1994
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)symlink.7 8.3 (Berkeley) 3/31/94
33 .\" $FreeBSD: src/bin/ln/symlink.7,v 1.13.2.7 2003/03/03 19:04:46 trhodes Exp $
34 .\" $DragonFly: src/bin/ln/symlink.7,v 1.2 2003/06/17 04:22:50 dillon Exp $
41 .Nd symbolic link handling
42 .Sh SYMBOLIC LINK HANDLING
43 Symbolic links are files that act as pointers to other files.
44 To understand their behavior, you must first understand how hard links
46 A hard link to a file is indistinguishable from the original file because
47 it is a reference to the object underlying the original file name.
48 Changes to a file are independent of the name used to reference the
50 Hard links may not refer to directories and may not reference files
51 on different file systems.
52 A symbolic link contains the name of the file to which it is linked,
53 i.e. it is a pointer to another name, and not to an underlying object.
54 For this reason, symbolic links may reference directories and may span
57 Because a symbolic link and its referenced object coexist in the file system
58 name space, confusion can arise in distinguishing between the link itself
59 and the referenced object.
60 Historically, commands and system calls have adopted their own link
61 following conventions in a somewhat ad-hoc fashion.
62 Rules for more a uniform approach, as they are implemented in this system,
64 It is important that local applications conform to these rules, too,
65 so that the user interface can be as consistent as possible.
67 Symbolic links are handled either by operating on the link itself,
68 or by operating on the object referenced by the link.
70 an application or system call is said to
73 Symbolic links may reference other symbolic links,
74 in which case the links are dereferenced until an object that is
75 not a symbolic link is found,
76 a symbolic link which references a file which doesn't exist is found,
77 or a loop is detected.
78 (Loop detection is done by placing an upper limit on the number of
79 links that may be followed, and an error results if this limit is
82 There are three separate areas that need to be discussed.
85 .Bl -enum -compact -offset indent
87 Symbolic links used as file name arguments for system calls.
89 Symbolic links specified as command line arguments to utilities that
90 are not traversing a file tree.
92 Symbolic links encountered by utilities that are traversing a file tree
93 (either specified on the command line or encountered as part of the
97 The first area is symbolic links used as file name arguments for
100 Except as noted below, all system calls follow symbolic links.
101 For example, if there were a symbolic link
103 which pointed to a file named
106 .Dq Li open("slink" ...\&)
107 would return a file descriptor to the file
110 There are six system calls that do not follow links, and which operate
111 on the symbolic link itself.
124 it also does not follow symbolic links.
127 is applied to a symbolic link, it fails with the error
130 The owner and group of an existing symbolic link can be changed by
134 The other file attributes, such as the modification time and access
135 permissions, are not used by the system and cannot be changed.
139 system differs from historical
141 systems in that the system call
143 has been changed to follow symbolic links.
146 system call was added later when the limitations of the new
149 .Ss Commands not traversing a file tree.
150 The second area is symbolic links, specified as command line file
151 name arguments, to commands which are not traversing a file tree.
153 Except as noted below, commands follow symbolic links named as command
155 For example, if there were a symbolic link
157 which pointed to a file named
161 would display the contents of the file
164 It is important to realize that this rule includes commands which may
165 optionally traverse file trees, e.g. the command
167 is included in this rule, while the command
168 .Dq Li "chown -R file"
170 (The latter is described in the third area, below.)
172 If it is explicitly intended that the command operate on the symbolic
173 link instead of following the symbolic link, e.g., it is desired that
175 change the ownership of the file that
177 is, whether it is a symbolic link or not, the
179 option should be used.
180 In the above example,
181 .Dq Li "chown root slink"
182 would change the ownership of the file referenced by
185 .Dq Li "chown -h root slink"
186 would change the ownership of
190 There are four exceptions to this rule.
195 commands do not follow symbolic links named as arguments,
196 but respectively attempt to rename and delete them.
197 (Note, if the symbolic link references a file via a relative path,
198 moving it to another directory may very well cause it to stop working,
199 since the path may no longer be correct.)
203 command is also an exception to this rule.
204 For compatibility with historic systems (when
206 is not doing a tree walk, i.e. the
208 option is not specified),
211 command follows symbolic links named as arguments if the
221 options are not specified. (The
223 command is the only command where the
227 options affect its behavior even though it is not doing a walk of
232 command is also an exception to this rule.
235 command does not follow symbolic links named as argument by default.
238 command does follow symbolic links named as argument if
244 system differs from historical
250 commands follow symbolic links specified on the command line.
251 .Ss Commands traversing a file tree.
252 The following commands either optionally or always traverse file trees:
266 It is important to realize that the following rules apply equally to
267 symbolic links encountered during the file tree traversal and symbolic
268 links listed as command line arguments.
270 The first rule applies to symbolic links that reference files that are
271 not of type directory.
272 Operations that apply to symbolic links are performed on the links
273 themselves, but otherwise the links are ignored.
275 For example, the command
276 .Dq Li "chown -R user slink directory"
279 because symbolic links in this system do not have owners.
280 Any symbolic links encountered during the tree traversal will also be
283 .Dq Li "rm -r slink directory"
286 as well as any symbolic links encountered in the tree traversal of
288 because symbolic links may be removed.
289 In no case will either
293 affect the file which
295 references in any way.
297 The second rule applies to symbolic links that reference files of type
299 Symbolic links which reference files of type directory are never
302 This is often referred to as a
304 walk, as opposed to a
306 walk (where symbolic links referencing directories are followed).
308 As consistently as possible, you can make commands doing a file tree
309 walk follow any symbolic links named on the command line, regardless
310 of the type of file they reference, by specifying the
315 This flag is intended to make the command line name space look
316 like the logical name space.
317 (Note, for commands that do not always do file tree traversals, the
319 flag will be ignored if the
321 flag is not also specified.)
323 For example, the command
324 .Dq Li "chown -HR user slink"
325 will traverse the file hierarchy rooted in the file pointed to by
329 is not the same as the previously discussed
334 flag causes symbolic links specified on the command line to be
335 dereferenced both for the purposes of the action to be performed
336 and the tree walk, and it is as if the user had specified the
337 name of the file to which the symbolic link pointed.
339 As consistently as possible, you can make commands doing a file tree
340 walk follow any symbolic links named on the command line, as well as
341 any symbolic links encountered during the traversal, regardless of
342 the type of file they reference, by specifying the
347 This flag is intended to make the entire name space look like
348 the logical name space.
349 (Note, for commands that do not always do file tree traversals, the
351 flag will be ignored if the
353 flag is not also specified.)
355 For example, the command
356 .Dq Li "chown -LR user slink"
357 will change the owner of the file referenced by
361 references a directory,
363 will traverse the file hierarchy rooted in the directory that it
365 In addition, if any symbolic links are encountered in any file tree that
367 traverses, they will be treated in the same fashion as
370 As consistently as possible, you can specify the default behavior by
376 This flag is intended to make the entire name space look like the
379 For commands that do not by default do file tree traversals, the
384 flags are ignored if the
386 flag is not also specified.
387 In addition, you may specify the
392 options more than once; the last one specified determines the
394 This is intended to permit you to alias commands to behave one way
395 or the other, and then override that behavior on the command line.
401 commands have exceptions to these rules.
404 command operates on the symbolic link, and not the file it references,
405 and therefore never follows a symbolic link.
408 command does not support the
415 To maintain compatibility with historic systems,
418 command acts a little differently. If you do not specify the
425 will follow symbolic links specified on the command line. If the
429 follows all symbolic links,
430 regardless of their type,
431 whether specified on the command line or encountered in the tree walk.