2 .\" Copyright (c) 1992, 1993, 1994
3 .\" The Regents of the University of California. All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 4. Neither the name of the University nor the names of its contributors
14 .\" may be used to endorse or promote products derived from this software
15 .\" without specific prior written permission.
17 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 .\" @(#)symlink.7 8.3 (Berkeley) 3/31/94
30 .\" $FreeBSD: src/bin/ln/symlink.7,v 1.30 2005/02/13 22:25:09 ru Exp $
32 .\" 2008-06-11, mtk, Taken from FreeBSD 6.2 and heavily edited for
33 .\" specific Linux details, improved readability, and man-pages style.
35 .TH SYMLINK 7 2008-06-18 "Linux" "Linux Programmer's Manual"
37 symlink \- symbolic link handling
38 .SH 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 filename.
45 (To be precise: each of the hard links to a file is a reference to
48 where an i-node number is an index into the i-node table,
49 which contains metadata about all files on a file system.
52 Changes to a file are independent of the name used to reference the file.
53 Hard links may not refer to directories
54 (to prevent the possibility of loops within the file system tree,
55 which would confuse many programs)
56 and may not refer to files on different file systems
57 (because i-node numbers are not unique across file systems).
59 A symbolic link is a special type of file whose contents are a string
60 that is the pathname another file, the file to which the link refers.
61 In other words, a symbolic link is a pointer to another name,
62 and not to an underlying object.
63 For this reason, symbolic links may refer to directories and may cross
64 file system boundaries.
66 There is no requirement that the pathname referred to by a symbolic link
68 A symbolic link that refers to a pathname that does not exist is said
72 Because a symbolic link and its referenced object coexist in the file system
73 name space, confusion can arise in distinguishing between the link itself
74 and the referenced object.
75 On historical systems,
76 commands and system calls adopted their own link-following
77 conventions in a somewhat ad-hoc fashion.
78 Rules for a more uniform approach,
79 as they are implemented on Linux and other systems,
81 It is important that site-local applications also conform to these rules,
82 so that the user interface can be as consistent as possible.
83 .SS Symbolic link ownership, permissions, and timestamps
84 The owner and group of an existing symbolic link can be changed
87 The only time that the ownership of a symbolic link matters is
88 when the link is being removed or renamed in a directory that
89 has the sticky bit set (see
92 The last access and last modification timestamps
93 of a symbolic link can be changed using
98 On Linux, the permissions of a symbolic link are not used
99 in any operations; the permissions are always
100 0777 (read, write, and execute for all user categories),
101 .\" Linux does not currently implement an lchmod(2).
102 and can't be changed.
106 .\" system differs from historical
108 .\" systems in that the system call
110 .\" has been changed to follow symbolic links.
113 .\" system call was added later when the limitations of the new
116 .SS Handling of symbolic links by system calls and commands
117 Symbolic links are handled either by operating on the link itself,
118 or by operating on the object referred to by the link.
120 an application or system call is said to
123 Symbolic links may refer to other symbolic links,
124 in which case the links are dereferenced until an object that is
125 not a symbolic link is found,
126 a symbolic link that refers to a file which does not exist is found,
127 or a loop is detected.
128 (Loop detection is done by placing an upper limit on the number of
129 links that may be followed, and an error results if this limit is
132 There are three separate areas that need to be discussed.
135 Symbolic links used as filename arguments for system calls.
137 Symbolic links specified as command-line arguments to utilities that
138 are not traversing a file tree.
140 Symbolic links encountered by utilities that are traversing a file tree
141 (either specified on the command line or encountered as part of the
142 file hierarchy walk).
144 The first area is symbolic links used as filename arguments for
147 Except as noted below, all system calls follow symbolic links.
148 For example, if there were a symbolic link
150 which pointed to a file named
153 .I "open(""slink"" ...\&)"
154 would return a file descriptor referring to the file
157 Various system calls do not follow links, and operate
158 on the symbolic link itself.
163 .BR lremovexattr (2),
171 Certain other system calls optionally follow symbolic links.
174 .\" Maybe one day: .BR fchownat (2)
182 see their manual pages for details.
187 that library function also does not follow symbolic links.
190 is applied to a symbolic link, it fails with the error
194 warrants special discussion.
195 POSIX.1-2001 specifies that
199 if it is a symbolic link.
200 However, Linux does not do this.
201 (By default Solaris is the same,
202 but the POSIX.1-2001 specified behavior can be obtained with
203 suitable compiler options.)
204 The upcoming POSIX.1 revision changes the specification to allow
205 either behavior in an implementation.
206 .SS Commands not traversing a file tree
207 The second area is symbolic links, specified as command-line
208 filename arguments, to commands which are not traversing a file tree.
210 Except as noted below, commands follow symbolic links named as
211 command-line arguments.
212 For example, if there were a symbolic link
214 which pointed to a file named
218 would display the contents of the file
221 It is important to realize that this rule includes commands which may
222 optionally traverse file trees, e.g., the command
224 is included in this rule, while the command
225 .IR "chown\ \-R file" ,
226 which performs a tree traversal, is not.
227 (The latter is described in the third area, below.)
229 If it is explicitly intended that the command operate on the symbolic
230 link instead of following the symbolic link, e.g., it is desired that
232 change the ownership of the file that
234 is, whether it is a symbolic link or not, the
236 option should be used.
237 In the above example,
238 .I "chown root slink"
239 would change the ownership of the file referred to by
242 .I "chown\ \-h root slink"
243 would change the ownership of
247 There are some exceptions to this rule:
253 commands do not follow symbolic links named as arguments,
254 but respectively attempt to rename and delete them.
255 (Note, if the symbolic link references a file via a relative path,
256 moving it to another directory may very well cause it to stop working,
257 since the path may no longer be correct.)
261 command is also an exception to this rule.
262 For compatibility with historic systems (when
264 is not doing a tree walk, i.e., the
266 option is not specified),
269 command follows symbolic links named as arguments if the
279 options are not specified.
282 command is the only command where the
286 options affect its behavior even though it is not doing a walk of
291 command is also an exception to this rule.
294 command does not follow symbolic links named as argument by default.
297 command does follow symbolic links named as argument if the
301 .\"The 4.4BSD system differs from historical 4BSD systems in that the
305 .\"commands follow symbolic links specified on the command line.
306 .SS Commands traversing a file tree
307 The following commands either optionally or always traverse file trees:
320 It is important to realize that the following rules apply equally to
321 symbolic links encountered during the file tree traversal and symbolic
322 links listed as command-line arguments.
324 The \fIfirst rule\fP applies to symbolic links that reference files other
326 Operations that apply to symbolic links are performed on the links
327 themselves, but otherwise the links are ignored.
330 .I "rm\ \-r slink directory"
333 as well as any symbolic links encountered in the tree traversal of
335 because symbolic links may be removed.
338 affect the file referred to by
341 The \fIsecond rule\fP applies to symbolic links that refer to directories.
342 Symbolic links that refer to directories are never followed by default.
343 This is often referred to as a "physical" walk, as opposed to a "logical"
344 walk (where symbolic links the refer to directories are followed).
346 Certain conventions are (should be) followed as consistently as
347 possible by commands that perform file tree walks:
349 A command can be made to follow
350 any symbolic links named on the command line,
351 regardless of the type of file they reference, by specifying the
353 (for "half-logical") flag.
354 This flag is intended to make the command-line name space look
355 like the logical name space.
356 (Note, for commands that do not always do file tree traversals, the
358 flag will be ignored if the
360 flag is not also specified.)
362 For example, the command
363 .I "chown\ \-HR user slink"
364 will traverse the file hierarchy rooted in the file pointed to by
368 is not the same as the previously discussed
373 flag causes symbolic links specified on the command line to be
374 dereferenced for the purposes of both the action to be performed
375 and the tree walk, and it is as if the user had specified the
376 name of the file to which the symbolic link pointed.
378 A command can be made to
379 follow any symbolic links named on the command line,
380 as well as any symbolic links encountered during the traversal,
381 regardless of the type of file they reference, by specifying the
383 (for "logical") flag.
384 This flag is intended to make the entire name space look like
385 the logical name space.
386 (Note, for commands that do not always do file tree traversals, the
388 flag will be ignored if the
390 flag is not also specified.)
392 For example, the command
393 .I "chown\ \-LR user slink"
394 will change the owner of the file referred to by
398 refers to a directory,
400 will traverse the file hierarchy rooted in the directory that it
402 In addition, if any symbolic links are encountered in any file tree that
404 traverses, they will be treated in the same fashion as
407 A command can be made to
408 provide the default behavior by specifying the
410 (for "physical") flag.
411 This flag is intended to make the entire name space look like the
414 For commands that do not by default do file tree traversals, the
419 flags are ignored if the
421 flag is not also specified.
422 In addition, you may specify the
427 options more than once;
428 the last one specified determines the command's behavior.
429 This is intended to permit you to alias commands to behave one way
430 or the other, and then override that behavior on the command line.
436 commands have exceptions to these rules:
440 command operates on the symbolic link, and not the file it references,
441 and therefore never follows a symbolic link.
444 command does not support the
451 To maintain compatibility with historic systems,
454 command acts a little differently.
455 If you do not specify the
462 will follow symbolic links specified on the command line.
467 follows all symbolic links,
468 regardless of their type,
469 whether specified on the command line or encountered in the tree walk.
487 .BR path_resolution (7)