1 .\" $NetBSD: symlink.7,v 1.7 1998/02/06 05:39:47 perry Exp $
3 .\" Copyright (c) 1992, 1993, 1994
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)symlink.7 8.3 (Berkeley) 3/31/94
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 filesystem
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 four system calls that do not follow links, and which operate
111 on the symbolic link itself.
122 it also does not follow symbolic links.
126 system differs from historical
128 systems in that the system call
130 has been changed to follow symbolic links.
131 .Ss Commands not traversing a file tree.
132 The second area is symbolic links, specified as command line file
133 name arguments, to commands which are not traversing a file tree.
135 Except as noted below, commands follow symbolic links named as command
137 For example, if there were a symbolic link
139 which pointed to a file named
143 would display the contents of the file
146 It is important to realize that this rule includes commands which may
147 optionally traverse file trees, e.g. the command
149 is included in this rule, while the command
150 .Dq Li "chown -R file"
152 (The latter is described in the third area, below.)
154 If it is explicitly intended that the command operate on the symbolic
155 link instead of following the symbolic link, e.g., it is desired that
157 display the type of file that
159 is, whether it is a symbolic link or not, the
161 option should be used.
162 In the above example,
164 would report the type of the file referenced by
167 .Dq Li "file -h slink"
172 There are three exceptions to this rule.
177 commands do not follow symbolic links named as arguments,
178 but respectively attempt to rename and delete them.
179 (Note, if the symbolic link references a file via a relative path,
180 moving it to another directory may very well cause it to stop working,
181 since the path may no longer be correct.)
185 command is also an exception to this rule.
186 For compatibility with historic systems (when
188 is not doing a tree walk, i.e. the
190 option is not specified),
193 command follows symbolic links named as arguments if the
201 options are not specified.
206 always follows symbolic links.
208 is the only command where the
210 option affects its behavior even though it is not doing a walk of
215 system differs from historical
222 commands follow symbolic links specified on the command line.
223 .Ss Commands traversing a file tree.
224 The following commands either optionally or always traverse file trees:
238 It is important to realize that the following rules apply equally to
239 symbolic links encountered during the file tree traversal and symbolic
240 links listed as command line arguments.
242 The first rule applies to symbolic links that reference files that are
243 not of type directory.
244 Operations that apply to symbolic links are performed on the links
245 themselves, but otherwise the links are ignored.
247 For example, the command
248 .Dq Li "chown -R user slink directory"
251 because symbolic links in this system do not have owners.
252 Any symbolic links encountered during the tree traversal will also be
255 .Dq Li "rm -r slink directory"
258 as well as any symbolic links encountered in the tree traversal of
260 because symbolic links may be removed.
261 In no case will either
265 affect the file which
267 references in any way.
269 The second rule applies to symbolic links that reference files of type
271 Symbolic links which reference files of type directory are never
274 This is often referred to as a
276 walk, as opposed to a
278 walk (where symbolic links referencing directories are followed).
280 As consistently as possible, you can make commands doing a file tree
281 walk follow any symbolic links named on the command line, regardless
282 of the type of file they reference, by specifying the
287 This flag is intended to make the command line name space look
288 like the logical name space.
289 (Note, for commands that do not always do file tree traversals, the
291 flag will be ignored if the
293 flag is not also specified.)
295 For example, the command
296 .Dq Li "chown -HR user slink"
297 will traverse the file hierarchy rooted in the file pointed to by
301 is not the same as the previously discussed
306 flag causes symbolic links specified on the command line to be
307 dereferenced both for the purposes of the action to be performed
308 and the tree walk, and it is as if the user had specified the
309 name of the file to which the symbolic link pointed.
311 As consistently as possible, you can make commands doing a file tree
312 walk follow any symbolic links named on the command line, as well as
313 any symbolic links encountered during the traversal, regardless of
314 the type of file they reference, by specifying the
319 This flag is intended to make the entire name space look like
320 the logical name space.
321 (Note, for commands that do not always do file tree traversals, the
323 flag will be ignored if the
325 flag is not also specified.)
327 For example, the command
328 .Dq Li "chown -LR user slink"
329 will change the owner of the file referenced by
333 references a directory,
335 will traverse the file hierarchy rooted in the directory that it
337 In addition, if any symbolic links are encountered in any file tree that
339 traverses, they will be treated in the same fashion as
342 As consistently as possible, you can specify the default behavior by
348 This flag is intended to make the entire name space look like the
351 For commands that do not by default do file tree traversals, the
356 flags are ignored if the
358 flag is not also specified.
359 In addition, you may specify the
364 options more than once; the last one specified determines the
366 This is intended to permit you to alias commands to behave one way
367 or the other, and then override that behavior on the command line.
373 commands have exceptions to these rules.
376 command operates on the symbolic link, and not the file it references,
377 and therefore never follows a symbolic link.
380 command does not support the
387 To maintain compatibility with historic systems,
390 command never follows symbolic links unless the
397 follows all symbolic links,
398 regardless of their type,
399 whether specified on the command line or encountered in the tree walk.
402 command does not support the