OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / 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 .\"*******************************************************************
36 .\"
37 .\" This file was generated with po4a. Translate the source file.
38 .\"
39 .\"*******************************************************************
40 .TH SYMLINK 7 2008\-06\-18 Linux "Linux Programmer's Manual"
41 .SH 名前
42 symlink \- symbolic link handling
43 .SH "SYMBOLIC LINK HANDLING"
44 Symbolic links are files that act as pointers to other files.  To understand
45 their behavior, you must first understand how hard links work.
46
47 A hard link to a file is indistinguishable from the original file because it
48 is a reference to the object underlying the original filename.  (To be
49 precise: each of the hard links to a file is a reference to the same
50 \fIi\-node number\fP, where an i\-node number is an index into the i\-node table,
51 which contains metadata about all files on a file system.  See \fBstat\fP(2).)
52 Changes to a file are independent of the name used to reference the file.
53 Hard links may not refer to directories (to prevent the possibility of loops
54 within the file system tree, which would confuse many programs)  and may not
55 refer to files on different file systems (because i\-node numbers are not
56 unique across file systems).
57
58 A symbolic link is a special type of file whose contents are a string that
59 is the pathname another file, the file to which the link refers.  In other
60 words, a symbolic link is a pointer to another name, and not to an
61 underlying object.  For this reason, symbolic links may refer to directories
62 and may cross file system boundaries.
63
64 There is no requirement that the pathname referred to by a symbolic link
65 should exist.  A symbolic link that refers to a pathname that does not exist
66 is said to be a \fIdangling link\fP.
67
68 Because a symbolic link and its referenced object coexist in the file system
69 name space, confusion can arise in distinguishing between the link itself
70 and the referenced object.  On historical systems, commands and system calls
71 adopted their own link\-following conventions in a somewhat ad\-hoc fashion.
72 Rules for a more uniform approach, as they are implemented on Linux and
73 other systems, are outlined here.  It is important that site\-local
74 applications also conform to these rules, so that the user interface can be
75 as consistent as possible.
76 .SS "Symbolic link ownership, permissions, and timestamps"
77 The owner and group of an existing symbolic link can be changed using
78 \fBlchown\fP(2).  The only time that the ownership of a symbolic link matters
79 is when the link is being removed or renamed in a directory that has the
80 sticky bit set (see \fBstat\fP(2)).
81
82 The last access and last modification timestamps of a symbolic link can be
83 changed using \fButimensat\fP(2)  or \fBlutimes\fP(3).
84
85 .\" Linux does not currently implement an lchmod(2).
86 .\"
87 .\" The
88 .\" 4.4BSD
89 .\" system differs from historical
90 .\" 4BSD
91 .\" systems in that the system call
92 .\" .BR chown (2)
93 .\" has been changed to follow symbolic links.
94 .\" The
95 .\" .BR lchown (2)
96 .\" system call was added later when the limitations of the new
97 .\" .BR chown (2)
98 .\" became apparent.
99 On Linux, the permissions of a symbolic link are not used in any operations;
100 the permissions are always 0777 (read, write, and execute for all user
101 categories), and can't be changed.
102 .SS "Handling of symbolic links by system calls and commands"
103 Symbolic links are handled either by operating on the link itself, or by
104 operating on the object referred to by the link.  In the latter case, an
105 application or system call is said to \fIfollow\fP the link.  Symbolic links
106 may refer to other symbolic links, in which case the links are dereferenced
107 until an object that is not a symbolic link is found, a symbolic link that
108 refers to a file which does not exist is found, or a loop is detected.
109 (Loop detection is done by placing an upper limit on the number of links
110 that may be followed, and an error results if this limit is exceeded.)
111
112 There are three separate areas that need to be discussed.  They are as
113 follows:
114 .IP 1. 3
115 Symbolic links used as filename arguments for system calls.
116 .IP 2.
117 Symbolic links specified as command\-line arguments to utilities that are not
118 traversing a file tree.
119 .IP 3.
120 Symbolic links encountered by utilities that are traversing a file tree
121 (either specified on the command line or encountered as part of the file
122 hierarchy walk).
123 .SS "System calls"
124 The first area is symbolic links used as filename arguments for system
125 calls.
126
127 Except as noted below, all system calls follow symbolic links.  For example,
128 if there were a symbolic link \fIslink\fP which pointed to a file named
129 \fIafile\fP, the system call \fIopen("slink" ...\&)\fP would return a file
130 descriptor referring to the file \fIafile\fP.
131
132 .\" Maybe one day: .BR fchownat (2)
133 Various system calls do not follow links, and operate on the symbolic link
134 itself.  They are: \fBlchown\fP(2), \fBlgetxattr\fP(2), \fBllistxattr\fP(2),
135 \fBlremovexattr\fP(2), \fBlsetxattr\fP(2), \fBlstat\fP(2), \fBreadlink\fP(2),
136 \fBrename\fP(2), \fBrmdir\fP(2), and \fBunlink\fP(2).  Certain other system calls
137 optionally follow symbolic links.  They are: \fBfaccessat\fP(2),
138 \fBfchownat\fP(2), \fBfstatat\fP(2), \fBlinkat\fP(2), \fBopen\fP(2), \fBopenat\fP(2), and
139 \fButimensat\fP(2); see their manual pages for details.  Because \fBremove\fP(3)
140 is an alias for \fBunlink\fP(2), that library function also does not follow
141 symbolic links.  When \fBrmdir\fP(2)  is applied to a symbolic link, it fails
142 with the error \fBENOTDIR\fP.  The \fBlink\fP(2)  warrants special discussion.
143 POSIX.1\-2001 specifies that \fBlink\fP(2)  should dereference \fIoldpath\fP if it
144 is a symbolic link.  However, Linux does not do this.  (By default Solaris
145 is the same, but the POSIX.1\-2001 specified behavior can be obtained with
146 suitable compiler options.)  The upcoming POSIX.1 revision changes the
147 specification to allow either behavior in an implementation.
148 .SS "Commands not traversing a file tree"
149 The second area is symbolic links, specified as command\-line filename
150 arguments, to commands which are not traversing a file tree.
151
152 Except as noted below, commands follow symbolic links named as command\-line
153 arguments.  For example, if there were a symbolic link \fIslink\fP which
154 pointed to a file named \fIafile\fP, the command \fIcat slink\fP would display the
155 contents of the file \fIafile\fP.
156
157 It is important to realize that this rule includes commands which may
158 optionally traverse file trees, e.g., the command \fIchown file\fP is included
159 in this rule, while the command \fIchown\ \-R file\fP, which performs a tree
160 traversal, is not.  (The latter is described in the third area, below.)
161
162 If it is explicitly intended that the command operate on the symbolic link
163 instead of following the symbolic link, e.g., it is desired that \fIchown
164 slink\fP change the ownership of the file that \fIslink\fP is, whether it is a
165 symbolic link or not, the \fI\-h\fP option should be used.  In the above
166 example, \fIchown root slink\fP would change the ownership of the file referred
167 to by \fIslink\fP, while \fIchown\ \-h root slink\fP would change the ownership of
168 \fIslink\fP itself.
169
170 There are some exceptions to this rule:
171 .IP * 2
172 The \fBmv\fP(1)  and \fBrm\fP(1)  commands do not follow symbolic links named as
173 arguments, but respectively attempt to rename and delete them.  (Note, if
174 the symbolic link references a file via a relative path, moving it to
175 another directory may very well cause it to stop working, since the path may
176 no longer be correct.)
177 .IP *
178 The \fBls\fP(1)  command is also an exception to this rule.  For compatibility
179 with historic systems (when \fBls\fP(1)  is not doing a tree walk, i.e., the
180 \fI\-R\fP option is not specified), the \fBls\fP(1)  command follows symbolic links
181 named as arguments if the \fI\-H\fP or \fI\-L\fP option is specified, or if the
182 \fI\-F\fP, \fI\-d\fP, or \fI\-l\fP options are not specified.  (The \fBls\fP(1)  command is
183 the only command where the \fI\-H\fP and \fI\-L\fP options affect its behavior even
184 though it is not doing a walk of a file tree.)
185 .IP *
186 .\"
187 .\"The 4.4BSD system differs from historical 4BSD systems in that the
188 .\".BR chown (1)
189 .\"and
190 .\".BR chgrp (1)
191 .\"commands follow symbolic links specified on the command line.
192 The \fBfile\fP(1)  command is also an exception to this rule.  The \fBfile\fP(1)
193 command does not follow symbolic links named as argument by default.  The
194 \fBfile\fP(1)  command does follow symbolic links named as argument if the
195 \fI\-L\fP option is specified.
196 .SS "Commands traversing a file tree"
197 The following commands either optionally or always traverse file trees:
198 \fBchgrp\fP(1), \fBchmod\fP(1), \fBchown\fP(1), \fBcp\fP(1), \fBdu\fP(1), \fBfind\fP(1),
199 \fBls\fP(1), \fBpax\fP(1), \fBrm\fP(1), and \fBtar\fP(1).
200
201 It is important to realize that the following rules apply equally to
202 symbolic links encountered during the file tree traversal and symbolic links
203 listed as command\-line arguments.
204
205 The \fIfirst rule\fP applies to symbolic links that reference files other than
206 directories.  Operations that apply to symbolic links are performed on the
207 links themselves, but otherwise the links are ignored.
208
209 The command \fIrm\ \-r slink directory\fP will remove \fIslink\fP, as well as any
210 symbolic links encountered in the tree traversal of \fIdirectory\fP, because
211 symbolic links may be removed.  In no case will \fBrm\fP(1)  affect the file
212 referred to by \fIslink\fP.
213
214 The \fIsecond rule\fP applies to symbolic links that refer to directories.
215 Symbolic links that refer to directories are never followed by default.
216 This is often referred to as a "physical" walk, as opposed to a "logical"
217 walk (where symbolic links the refer to directories are followed).
218
219 Certain conventions are (should be) followed as consistently as possible by
220 commands that perform file tree walks:
221 .IP * 2
222 A command can be made to follow any symbolic links named on the command
223 line, regardless of the type of file they reference, by specifying the \fI\-H\fP
224 (for "half\-logical") flag.  This flag is intended to make the command\-line
225 name space look like the logical name space.  (Note, for commands that do
226 not always do file tree traversals, the \fI\-H\fP flag will be ignored if the
227 \fI\-R\fP flag is not also specified.)
228
229 For example, the command \fIchown\ \-HR user slink\fP will traverse the file
230 hierarchy rooted in the file pointed to by \fIslink\fP.  Note, the \fI\-H\fP is not
231 the same as the previously discussed \fI\-h\fP flag.  The \fI\-H\fP flag causes
232 symbolic links specified on the command line to be dereferenced for the
233 purposes of both the action to be performed and the tree walk, and it is as
234 if the user had specified the name of the file to which the symbolic link
235 pointed.
236 .IP *
237 A command can be made to follow any symbolic links named on the command
238 line, as well as any symbolic links encountered during the traversal,
239 regardless of the type of file they reference, by specifying the \fI\-L\fP (for
240 "logical") flag.  This flag is intended to make the entire name space look
241 like the logical name space.  (Note, for commands that do not always do file
242 tree traversals, the \fI\-L\fP flag will be ignored if the \fI\-R\fP flag is not
243 also specified.)
244
245 For example, the command \fIchown\ \-LR user slink\fP will change the owner of
246 the file referred to by \fIslink\fP.  If \fIslink\fP refers to a directory,
247 \fBchown\fP will traverse the file hierarchy rooted in the directory that it
248 references.  In addition, if any symbolic links are encountered in any file
249 tree that \fBchown\fP traverses, they will be treated in the same fashion as
250 \fIslink\fP.
251 .IP *
252 A command can be made to provide the default behavior by specifying the
253 \fI\-P\fP (for "physical") flag.  This flag is intended to make the entire name
254 space look like the physical name space.
255 .PP
256 For commands that do not by default do file tree traversals, the \fI\-H\fP,
257 \fI\-L\fP, and \fI\-P\fP flags are ignored if the \fI\-R\fP flag is not also specified.
258 In addition, you may specify the \fI\-H\fP, \fI\-L\fP, and \fI\-P\fP options more than
259 once; the last one specified determines the command's behavior.  This is
260 intended to permit you to alias commands to behave one way or the other, and
261 then override that behavior on the command line.
262
263 The \fBls\fP(1)  and \fBrm\fP(1)  commands have exceptions to these rules:
264 .IP * 2
265 The \fBrm\fP(1)  command operates on the symbolic link, and not the file it
266 references, and therefore never follows a symbolic link.  The \fBrm\fP(1)
267 command does not support the \fI\-H\fP, \fI\-L\fP, or \fI\-P\fP options.
268 .IP *
269 To maintain compatibility with historic systems, the \fBls\fP(1)  command acts
270 a little differently.  If you do not specify the \fI\-F\fP, \fI\-d\fP or \fI\-l\fP
271 options, \fBls\fP(1)  will follow symbolic links specified on the command
272 line.  If the \fI\-L\fP flag is specified, \fBls\fP(1)  follows all symbolic links,
273 regardless of their type, whether specified on the command line or
274 encountered in the tree walk.
275 .SH 関連項目
276 \fBchgrp\fP(1), \fBchmod\fP(1), \fBfind\fP(1), \fBln\fP(1), \fBls\fP(1), \fBmv\fP(1),
277 \fBrm\fP(1), \fBlchown\fP(2), \fBlink\fP(2), \fBlstat\fP(2), \fBreadlink\fP(2),
278 \fBrename\fP(2), \fBsymlink\fP(2), \fBunlink\fP(2), \fButimensat\fP(2), \fBlutimes\fP(3),
279 \fBpath_resolution\fP(7)