1 .\" Copyright (c) 1992, 1993, 1994
2 .\" The Regents of the University of California. All rights reserved.
4 .\" %%%LICENSE_START(BSD_3_CLAUSE_UCB)
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
30 .\" @(#)symlink.7 8.3 (Berkeley) 3/31/94
31 .\" $FreeBSD: src/bin/ln/symlink.7,v 1.30 2005/02/13 22:25:09 ru Exp $
33 .\" 2008-06-11, mtk, Taken from FreeBSD 6.2 and heavily edited for
34 .\" specific Linux details, improved readability, and man-pages style.
36 .TH SYMLINK 7 2008-06-18 "Linux" "Linux Programmer's Manual"
38 symlink \- symbolic link handling
39 .SH SYMBOLIC LINK HANDLING
40 Symbolic links are files that act as pointers to other files.
41 To understand their behavior, you must first understand how hard links
44 A hard link to a file is indistinguishable from the original file because
45 it is a reference to the object underlying the original filename.
46 (To be precise: each of the hard links to a file is a reference to
49 where an i-node number is an index into the i-node table,
50 which contains metadata about all files on a filesystem.
53 Changes to a file are independent of the name used to reference the file.
54 Hard links may not refer to directories
55 (to prevent the possibility of loops within the filesystem tree,
56 which would confuse many programs)
57 and may not refer to files on different filesystems
58 (because i-node numbers are not unique across filesystems).
60 A symbolic link is a special type of file whose contents are a string
61 that is the pathname another file, the file to which the link refers.
62 In other words, a symbolic link is a pointer to another name,
63 and not to an underlying object.
64 For this reason, symbolic links may refer to directories and may cross
65 filesystem boundaries.
67 There is no requirement that the pathname referred to by a symbolic link
69 A symbolic link that refers to a pathname that does not exist is said
73 Because a symbolic link and its referenced object coexist in the filesystem
74 name space, confusion can arise in distinguishing between the link itself
75 and the referenced object.
76 On historical systems,
77 commands and system calls adopted their own link-following
78 conventions in a somewhat ad-hoc fashion.
79 Rules for a more uniform approach,
80 as they are implemented on Linux and other systems,
82 It is important that site-local applications also conform to these rules,
83 so that the user interface can be as consistent as possible.
84 .SS Symbolic link ownership, permissions, and timestamps
85 The owner and group of an existing symbolic link can be changed
88 The only time that the ownership of a symbolic link matters is
89 when the link is being removed or renamed in a directory that
90 has the sticky bit set (see
93 The last access and last modification timestamps
94 of a symbolic link can be changed using
99 On Linux, the permissions of a symbolic link are not used
100 in any operations; the permissions are always
101 0777 (read, write, and execute for all user categories),
102 .\" Linux does not currently implement an lchmod(2).
103 and can't be changed.
107 .\" system differs from historical
109 .\" systems in that the system call
111 .\" has been changed to follow symbolic links.
114 .\" system call was added later when the limitations of the new
117 .SS Handling of symbolic links by system calls and commands
118 Symbolic links are handled either by operating on the link itself,
119 or by operating on the object referred to by the link.
121 an application or system call is said to
124 Symbolic links may refer to other symbolic links,
125 in which case the links are dereferenced until an object that is
126 not a symbolic link is found,
127 a symbolic link that refers to a file which does not exist is found,
128 or a loop is detected.
129 (Loop detection is done by placing an upper limit on the number of
130 links that may be followed, and an error results if this limit is
133 There are three separate areas that need to be discussed.
136 Symbolic links used as filename arguments for system calls.
138 Symbolic links specified as command-line arguments to utilities that
139 are not traversing a file tree.
141 Symbolic links encountered by utilities that are traversing a file tree
142 (either specified on the command line or encountered as part of the
143 file hierarchy walk).
145 The first area is symbolic links used as filename arguments for
148 Except as noted below, all system calls follow symbolic links.
149 For example, if there were a symbolic link
151 which pointed to a file named
154 .I "open(""slink"" ...\&)"
155 would return a file descriptor referring to the file
158 Various system calls do not follow links, and operate
159 on the symbolic link itself.
164 .BR lremovexattr (2),
172 Certain other system calls optionally follow symbolic links.
175 .\" Maybe one day: .BR fchownat (2)
183 see their manual pages for details.
188 that library function also does not follow symbolic links.
191 is applied to a symbolic link, it fails with the error
195 warrants special discussion.
196 POSIX.1-2001 specifies that
200 if it is a symbolic link.
201 However, Linux does not do this.
202 (By default Solaris is the same,
203 but the POSIX.1-2001 specified behavior can be obtained with
204 suitable compiler options.)
205 The upcoming POSIX.1 revision changes the specification to allow
206 either behavior in an implementation.
207 .SS Commands not traversing a file tree
208 The second area is symbolic links, specified as command-line
209 filename arguments, to commands which are not traversing a file tree.
211 Except as noted below, commands follow symbolic links named as
212 command-line arguments.
213 For example, if there were a symbolic link
215 which pointed to a file named
219 would display the contents of the file
222 It is important to realize that this rule includes commands which may
223 optionally traverse file trees, e.g., the command
225 is included in this rule, while the command
226 .IR "chown\ \-R file" ,
227 which performs a tree traversal, is not.
228 (The latter is described in the third area, below.)
230 If it is explicitly intended that the command operate on the symbolic
231 link instead of following the symbolic link, e.g., it is desired that
233 change the ownership of the file that
235 is, whether it is a symbolic link or not, the
237 option should be used.
238 In the above example,
239 .I "chown root slink"
240 would change the ownership of the file referred to by
243 .I "chown\ \-h root slink"
244 would change the ownership of
248 There are some exceptions to this rule:
254 commands do not follow symbolic links named as arguments,
255 but respectively attempt to rename and delete them.
256 (Note, if the symbolic link references a file via a relative path,
257 moving it to another directory may very well cause it to stop working,
258 since the path may no longer be correct.)
262 command is also an exception to this rule.
263 For compatibility with historic systems (when
265 is not doing a tree walk, i.e., the
267 option is not specified),
270 command follows symbolic links named as arguments if the
280 options are not specified.
283 command is the only command where the
287 options affect its behavior even though it is not doing a walk of
292 command is also an exception to this rule.
295 command does not follow symbolic links named as argument by default.
298 command does follow symbolic links named as argument if the
302 .\"The 4.4BSD system differs from historical 4BSD systems in that the
306 .\"commands follow symbolic links specified on the command line.
307 .SS Commands traversing a file tree
308 The following commands either optionally or always traverse file trees:
321 It is important to realize that the following rules apply equally to
322 symbolic links encountered during the file tree traversal and symbolic
323 links listed as command-line arguments.
325 The \fIfirst rule\fP applies to symbolic links that reference files other
327 Operations that apply to symbolic links are performed on the links
328 themselves, but otherwise the links are ignored.
331 .I "rm\ \-r slink directory"
334 as well as any symbolic links encountered in the tree traversal of
336 because symbolic links may be removed.
339 affect the file referred to by
342 The \fIsecond rule\fP applies to symbolic links that refer to directories.
343 Symbolic links that refer to directories are never followed by default.
344 This is often referred to as a "physical" walk, as opposed to a "logical"
345 walk (where symbolic links the refer to directories are followed).
347 Certain conventions are (should be) followed as consistently as
348 possible by commands that perform file tree walks:
350 A command can be made to follow
351 any symbolic links named on the command line,
352 regardless of the type of file they reference, by specifying the
354 (for "half-logical") flag.
355 This flag is intended to make the command-line name space look
356 like the logical name space.
357 (Note, for commands that do not always do file tree traversals, the
359 flag will be ignored if the
361 flag is not also specified.)
363 For example, the command
364 .I "chown\ \-HR user slink"
365 will traverse the file hierarchy rooted in the file pointed to by
369 is not the same as the previously discussed
374 flag causes symbolic links specified on the command line to be
375 dereferenced for the purposes of both the action to be performed
376 and the tree walk, and it is as if the user had specified the
377 name of the file to which the symbolic link pointed.
379 A command can be made to
380 follow any symbolic links named on the command line,
381 as well as any symbolic links encountered during the traversal,
382 regardless of the type of file they reference, by specifying the
384 (for "logical") flag.
385 This flag is intended to make the entire name space look like
386 the logical name space.
387 (Note, for commands that do not always do file tree traversals, the
389 flag will be ignored if the
391 flag is not also specified.)
393 For example, the command
394 .I "chown\ \-LR user slink"
395 will change the owner of the file referred to by
399 refers to a directory,
401 will traverse the file hierarchy rooted in the directory that it
403 In addition, if any symbolic links are encountered in any file tree that
405 traverses, they will be treated in the same fashion as
408 A command can be made to
409 provide the default behavior by specifying the
411 (for "physical") flag.
412 This flag is intended to make the entire name space look like the
415 For commands that do not by default do file tree traversals, the
420 flags are ignored if the
422 flag is not also specified.
423 In addition, you may specify the
428 options more than once;
429 the last one specified determines the command's behavior.
430 This is intended to permit you to alias commands to behave one way
431 or the other, and then override that behavior on the command line.
437 commands have exceptions to these rules:
441 command operates on the symbolic link, and not the file it references,
442 and therefore never follows a symbolic link.
445 command does not support the
452 To maintain compatibility with historic systems,
455 command acts a little differently.
456 If you do not specify the
463 will follow symbolic links specified on the command line.
468 follows all symbolic links,
469 regardless of their type,
470 whether specified on the command line or encountered in the tree walk.
488 .BR path_resolution (7)