1 .\" $NetBSD: symlink.7,v 1.16 2009/03/11 13:52:19 joerg 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. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)symlink.7 8.3 (Berkeley) 3/31/94
37 .Nd symbolic link handling
39 Symbolic links are files that act as pointers to other files.
40 To understand their behavior, you must first understand how hard links
43 A hard link to a file is indistinguishable from the original file because
44 it is a reference to the object underlying the original file name.
45 Changes to a file are independent of the name used to reference the
47 Hard links may not refer to directories and may not reference files
48 on different file systems.
50 A symbolic link contains the name of the file to which it is linked,
52 it is a pointer to another name, and not to an underlying object.
53 For this reason, symbolic links may reference directories and may span
56 Because a symbolic link and its referenced object coexist in the filesystem
57 name space, confusion can arise in distinguishing between the link itself
58 and the referenced object.
59 Historically, commands and system calls have adopted their own link
60 following conventions in a somewhat ad-hoc fashion.
61 Rules for more a uniform approach, as they are implemented in this system,
63 It is important that local applications conform to these rules, too,
64 so that the user interface can be as consistent as possible.
66 Symbolic links are handled either by operating on the link itself,
67 or by operating on the object referenced by the link.
69 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 .Qq Li open("slink" ...)
107 would return a file descriptor to the file
110 There are eight system calls that do not follow links, and which operate
111 on the symbolic link itself.
126 it also does not follow symbolic links.
130 system differs from historical
132 systems in that the system call
134 has been changed to follow symbolic links.
136 If the filesystem is mounted with the
139 option, the symbolic link file permission bits have the following effects:
143 system call requires read permissions on the symbolic link.
145 System calls that follow symbolic links will fail without execute/search
146 permissions on all the symbolic links followed.
148 The write, sticky, set-user-ID-on-execution and set-group-ID-on-execution
149 symbolic link mode bits have no effect on any system calls
154 .Ss Commands not traversing a file tree
155 The second area is symbolic links, specified as command line file
156 name arguments, to commands which are not traversing a file tree.
158 Except as noted below, commands follow symbolic links named as command
160 For example, if there were a symbolic link
162 which pointed to a file named
166 would display the contents of the file
169 It is important to realize that this rule includes commands which may
170 optionally traverse file trees, e.g.
173 is included in this rule, while the command
174 .Qq Li "chown -R file"
176 (The latter is described in the third area, below).
178 If it is explicitly intended that the command operate on the symbolic
179 link instead of following the symbolic link, e.g., it is desired that
181 display the type of file that
183 is, whether it is a symbolic link or not, the
185 option should be used.
186 In the above example,
188 would report the type of the file referenced by
191 .Qq Li "file -h slink"
196 There are three exceptions to this rule.
201 commands do not follow symbolic links named as arguments,
202 but respectively attempt to rename and delete them.
203 (Note, if the symbolic link references a file via a relative path,
204 moving it to another directory may very well cause it to stop working,
205 since the path may no longer be correct).
209 command is also an exception to this rule.
210 For compatibility with historic systems (when
212 is not doing a tree walk, i.e.
215 option is not specified),
218 command follows symbolic links named as arguments if the
226 options are not specified.
231 always follows symbolic links.
233 is the only command where the
235 option affects its behavior even though it is not doing a walk of
240 system differs from historical
247 commands follow symbolic links specified on the command line.
248 .Ss Commands traversing a file tree
249 The following commands either optionally or always traverse file trees:
263 It is important to realize that the following rules apply equally to
264 symbolic links encountered during the file tree traversal and symbolic
265 links listed as command line arguments.
267 The first rule applies to symbolic links that reference files that are
268 not of type directory.
269 Operations that apply to symbolic links are performed on the links
270 themselves, but otherwise the links are ignored.
272 For example, the command
273 .Qq Li "chown -R user slink directory"
278 flag must be used to change owners of symbolic links.
279 Any symbolic links encountered during the tree traversal will also be
282 .Qq Li "rm -r slink directory"
285 as well as any symbolic links encountered in the tree traversal of
287 because symbolic links may be removed.
288 In no case will either
292 affect the file which
294 references in any way.
296 The second rule applies to symbolic links that reference files of type
298 Symbolic links which reference files of type directory are never
301 This is often referred to as a
303 walk, as opposed to a
305 walk (where symbolic links referencing directories are followed).
307 As consistently as possible, you can make commands doing a file tree
308 walk follow any symbolic links named on the command line, regardless
309 of the type of file they reference, by specifying the
314 This flag is intended to make the command line name space look
315 like the logical name space.
316 (Note, for commands that do not always do file tree traversals, the
318 flag will be ignored if the
320 flag is not also specified).
322 For example, the command
323 .Qq Li "chown -HR user slink"
324 will traverse the file hierarchy rooted in the file pointed to by
328 is not the same as the previously discussed
333 flag causes symbolic links specified on the command line to be
334 dereferenced both for the purposes of the action to be performed
335 and the tree walk, and it is as if the user had specified the
336 name of the file to which the symbolic link pointed.
338 As consistently as possible, you can make commands doing a file tree
339 walk follow any symbolic links named on the command line, as well as
340 any symbolic links encountered during the traversal, regardless of
341 the type of file they reference, by specifying the
346 This flag is intended to make the entire name space look like
347 the logical name space.
348 (Note, for commands that do not always do file tree traversals, the
350 flag will be ignored if the
352 flag is not also specified).
354 For example, the command
355 .Qq Li "chown -LR user slink"
356 will change the owner of the file referenced by
360 references a directory,
362 will traverse the file hierarchy rooted in the directory that it
364 In addition, if any symbolic links are encountered in any file tree that
366 traverses, they will be treated in the same fashion as
369 As consistently as possible, you can specify the default behavior by
375 This flag is intended to make the entire name space look like the
378 For commands that do not by default do file tree traversals, the
383 flags are ignored if the
385 flag is not also specified.
386 In addition, you may specify the
391 options more than once; the last one specified determines the
393 This is intended to permit you to alias commands to behave one way
394 or the other, and then override that behavior on the command line.
400 commands have exceptions to these rules.
403 command operates on the symbolic link, and not the file it references,
404 and therefore never follows a symbolic link.
407 command does not support the
414 To maintain compatibility with historic systems,
417 command never follows symbolic links unless the
424 follows all symbolic links,
425 regardless of their type,
426 whether specified on the command line or encountered in the tree walk.
429 command does not support the
435 Magic symlinks can be enabled by setting
436 .Dq vfs.generic.magiclinks
439 When magic symlinks are enabled
441 patterns in symlinks are expanded.
442 Those patterns begin with
445 and end at the end of the pathname component
449 or at the end of the symbolic link if there are no more slashes
452 To illustrate the pattern matching rules, assume that
454 is a valid magic string:
456 .Bl -tag -width @foo/barxxxxx -offset indent -compact
467 Magic strings may also be delimited with
471 characters, allowing for more complex patterns in symbolic links such as:
472 .Bd -literal -offset indent
473 @{var1}-@{var2}.@{var3}
476 The following patterns are supported:
477 .Bl -tag -width @machine_arch
479 Expands to the machine's domain name, as set by
480 .Xr setdomainname 3 .
482 Expands to the machine's host name, as set by
485 Expands to the name of the current process's emulation.
487 Expands to the name of the
489 file used to generate the running kernel.
491 Expands to the value of
495 equivalent to the output of
499 Expands to the value of
503 equivalent to the output of
507 Expands to the operating system release of the running kernel
509 equivalent to the output of
513 Expands to the operating system type of the running kernel
515 equivalent to the output of
524 Expands to the real user-id of the process.
526 Expands to the effective user-id of the process.
528 Expands to the real group-id of the process.
530 Expands to the effective group-id of the process.
563 Magic symlinks appeared in