OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / original / man7 / symlink.7
1 .\"-
2 .\" Copyright (c) 1992, 1993, 1994
3 .\"     The Regents of the University of California.  All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
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.
16 .\"
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
27 .\" SUCH DAMAGE.
28 .\"
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 $
31 .\"
32 .\" 2008-06-11, mtk, Taken from FreeBSD 6.2 and heavily edited for
33 .\"     specific Linux details, improved readability, and man-pages style.
34 .\"
35 .TH SYMLINK 7 2008-06-18 "Linux" "Linux Programmer's Manual"
36 .SH NAME
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
41 work.
42
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
46 the same
47 .IR "i-node number" ,
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.
50 See
51 .BR stat (2).)
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).
58
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.
65
66 There is no requirement that the pathname referred to by a symbolic link
67 should exist.
68 A symbolic link that refers to a pathname that does not exist is said
69 to be a
70 .IR "dangling link" .
71
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,
80 are outlined here.
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
85 using
86 .BR lchown (2).
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
90 .BR stat (2)).
91
92 The last access and last modification timestamps
93 of a symbolic link can be changed using
94 .BR utimensat (2)
95 or
96 .BR lutimes (3).
97
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.
103 .\"
104 .\" The
105 .\" 4.4BSD
106 .\" system differs from historical
107 .\" 4BSD
108 .\" systems in that the system call
109 .\" .BR chown (2)
110 .\" has been changed to follow symbolic links.
111 .\" The
112 .\" .BR lchown (2)
113 .\" system call was added later when the limitations of the new
114 .\" .BR chown (2)
115 .\" became apparent.
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.
119 In the latter case,
120 an application or system call is said to
121 .I follow
122 the link.
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
130 exceeded.)
131
132 There are three separate areas that need to be discussed.
133 They are as follows:
134 .IP 1. 3
135 Symbolic links used as filename arguments for system calls.
136 .IP 2.
137 Symbolic links specified as command-line arguments to utilities that
138 are not traversing a file tree.
139 .IP 3.
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).
143 .SS System calls
144 The first area is symbolic links used as filename arguments for
145 system calls.
146
147 Except as noted below, all system calls follow symbolic links.
148 For example, if there were a symbolic link
149 .I slink
150 which pointed to a file named
151 .IR afile ,
152 the system call
153 .I "open(""slink"" ...\&)"
154 would return a file descriptor referring to the file
155 .IR afile .
156
157 Various system calls do not follow links, and operate
158 on the symbolic link itself.
159 They are:
160 .BR lchown (2),
161 .BR lgetxattr (2),
162 .BR llistxattr (2),
163 .BR lremovexattr (2),
164 .BR lsetxattr (2),
165 .BR lstat (2),
166 .BR readlink (2),
167 .BR rename (2),
168 .BR rmdir (2),
169 and
170 .BR unlink (2).
171 Certain other system calls optionally follow symbolic links.
172 They are:
173 .BR faccessat (2),
174 .\" Maybe one day: .BR fchownat (2)
175 .BR fchownat (2),
176 .BR fstatat (2),
177 .BR linkat (2),
178 .BR open (2),
179 .BR openat (2),
180 and
181 .BR utimensat (2);
182 see their manual pages for details.
183 Because
184 .BR remove (3)
185 is an alias for
186 .BR unlink (2),
187 that library function also does not follow symbolic links.
188 When
189 .BR rmdir (2)
190 is applied to a symbolic link, it fails with the error
191 .BR ENOTDIR .
192 The
193 .BR link (2)
194 warrants special discussion.
195 POSIX.1-2001 specifies that
196 .BR link (2)
197 should dereference
198 .I oldpath
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.
209
210 Except as noted below, commands follow symbolic links named as
211 command-line arguments.
212 For example, if there were a symbolic link
213 .I slink
214 which pointed to a file named
215 .IR afile ,
216 the command
217 .I "cat slink"
218 would display the contents of the file
219 .IR afile .
220
221 It is important to realize that this rule includes commands which may
222 optionally traverse file trees, e.g., the command
223 .I "chown file"
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.)
228
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
231 .I "chown slink"
232 change the ownership of the file that
233 .I slink
234 is, whether it is a symbolic link or not, the
235 .I \-h
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
240 .IR slink ,
241 while
242 .I "chown\ \-h root slink"
243 would change the ownership of
244 .I slink
245 itself.
246
247 There are some exceptions to this rule:
248 .IP * 2
249 The
250 .BR mv (1)
251 and
252 .BR rm (1)
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.)
258 .IP *
259 The
260 .BR ls (1)
261 command is also an exception to this rule.
262 For compatibility with historic systems (when
263 .BR ls (1)
264 is not doing a tree walk, i.e., the
265 .I \-R
266 option is not specified),
267 the
268 .BR ls (1)
269 command follows symbolic links named as arguments if the
270 .I \-H
271 or
272 .I \-L
273 option is specified,
274 or if the
275 .IR \-F ,
276 .IR \-d ,
277 or
278 .I \-l
279 options are not specified.
280 (The
281 .BR ls (1)
282 command is the only command where the
283 .I \-H
284 and
285 .I \-L
286 options affect its behavior even though it is not doing a walk of
287 a file tree.)
288 .IP *
289 The
290 .BR file (1)
291 command is also an exception to this rule.
292 The
293 .BR file (1)
294 command does not follow symbolic links named as argument by default.
295 The
296 .BR file (1)
297 command does follow symbolic links named as argument if the
298 .I \-L
299 option is specified.
300 .\"
301 .\"The 4.4BSD system differs from historical 4BSD systems in that the
302 .\".BR chown (1)
303 .\"and
304 .\".BR chgrp (1)
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:
308 .BR chgrp (1),
309 .BR chmod (1),
310 .BR chown (1),
311 .BR cp (1),
312 .BR du (1),
313 .BR find (1),
314 .BR ls (1),
315 .BR pax (1),
316 .BR rm (1),
317 and
318 .BR tar (1).
319
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.
323
324 The \fIfirst rule\fP applies to symbolic links that reference files other
325 than directories.
326 Operations that apply to symbolic links are performed on the links
327 themselves, but otherwise the links are ignored.
328
329 The command
330 .I "rm\ \-r slink directory"
331 will remove
332 .IR slink ,
333 as well as any symbolic links encountered in the tree traversal of
334 .IR directory ,
335 because symbolic links may be removed.
336 In no case will
337 .BR rm (1)
338 affect the file referred to by
339 .IR slink .
340
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).
345
346 Certain conventions are (should be) followed as consistently as
347 possible by commands that perform file tree walks:
348 .IP * 2
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
352 .I \-H
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
357 .I \-H
358 flag will be ignored if the
359 .I \-R
360 flag is not also specified.)
361
362 For example, the command
363 .I "chown\ \-HR user slink"
364 will traverse the file hierarchy rooted in the file pointed to by
365 .IR slink .
366 Note, the
367 .I \-H
368 is not the same as the previously discussed
369 .I \-h
370 flag.
371 The
372 .I \-H
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.
377 .IP *
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
382 .I \-L
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
387 .I \-L
388 flag will be ignored if the
389 .I \-R
390 flag is not also specified.)
391
392 For example, the command
393 .I "chown\ \-LR user slink"
394 will change the owner of the file referred to by
395 .IR slink .
396 If
397 .I slink
398 refers to a directory,
399 .B chown
400 will traverse the file hierarchy rooted in the directory that it
401 references.
402 In addition, if any symbolic links are encountered in any file tree that
403 .B chown
404 traverses, they will be treated in the same fashion as
405 .IR slink .
406 .IP *
407 A command can be made to
408 provide the default behavior by specifying the
409 .I \-P
410 (for "physical") flag.
411 This flag is intended to make the entire name space look like the
412 physical name space.
413 .PP
414 For commands that do not by default do file tree traversals, the
415 .IR \-H ,
416 .IR \-L ,
417 and
418 .I \-P
419 flags are ignored if the
420 .I \-R
421 flag is not also specified.
422 In addition, you may specify the
423 .IR \-H ,
424 .IR \-L ,
425 and
426 .I \-P
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.
431
432 The
433 .BR ls (1)
434 and
435 .BR rm (1)
436 commands have exceptions to these rules:
437 .IP * 2
438 The
439 .BR rm (1)
440 command operates on the symbolic link, and not the file it references,
441 and therefore never follows a symbolic link.
442 The
443 .BR rm (1)
444 command does not support the
445 .IR \-H ,
446 .IR \-L ,
447 or
448 .I \-P
449 options.
450 .IP *
451 To maintain compatibility with historic systems,
452 the
453 .BR ls (1)
454 command acts a little differently.
455 If you do not specify the
456 .IR \-F ,
457 .IR \-d
458 or
459 .I \-l
460 options,
461 .BR ls (1)
462 will follow symbolic links specified on the command line.
463 If the
464 .I \-L
465 flag is specified,
466 .BR ls (1)
467 follows all symbolic links,
468 regardless of their type,
469 whether specified on the command line or encountered in the tree walk.
470 .SH SEE ALSO
471 .BR chgrp (1),
472 .BR chmod (1),
473 .BR find (1),
474 .BR ln (1),
475 .BR ls (1),
476 .BR mv (1),
477 .BR rm (1),
478 .BR lchown (2),
479 .BR link (2),
480 .BR lstat (2),
481 .BR readlink (2),
482 .BR rename (2),
483 .BR symlink (2),
484 .BR unlink (2),
485 .BR utimensat (2),
486 .BR lutimes (3),
487 .BR path_resolution (7)