OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / man2 / unlink.2
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"             and Copyright (C) 1993 Ian Jackson
3 .\"             and Copyright (C) 2006, 2014 Michael Kerrisk.
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1996-09-08 by Arnt Gulbrandsen <agulbra@troll.no>
29 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 2001-05-17 by aeb
31 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\"
33 .TH UNLINK 2 2014-02-21 "Linux" "Linux Programmer's Manual"
34 .SH NAME
35 unlink, unlinkat \- delete a name and possibly the file it refers to
36 .SH SYNOPSIS
37 .nf
38 .B #include <unistd.h>
39 .sp
40 .BI "int unlink(const char *" pathname );
41 .sp
42 .BR "#include <fcntl.h>           " "/* Definition of AT_* constants */"
43 .B #include <unistd.h>
44 .sp
45 .BI "int unlinkat(int " dirfd ", const char *" pathname ", int " flags );
46 .fi
47 .sp
48 .in -4n
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
51 .in
52 .sp
53 .BR unlinkat ():
54 .PD 0
55 .ad l
56 .RS 4
57 .TP 4
58 Since glibc 2.10:
59 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
60 .TP
61 Before glibc 2.10:
62 _ATFILE_SOURCE
63 .RE
64 .ad
65 .PD
66 .SH DESCRIPTION
67 .BR unlink ()
68 deletes a name from the filesystem.
69 If that name was the
70 last link to a file and no processes have the file open, the file is
71 deleted and the space it was using is made available for reuse.
72
73 If the name was the last link to a file but any processes still have
74 the file open, the file will remain in existence until the last file
75 descriptor referring to it is closed.
76
77 If the name referred to a symbolic link, the link is removed.
78
79 If the name referred to a socket, FIFO, or device, the name for it is
80 removed but processes which have the object open may continue to use
81 it.
82 .SS unlinkat()
83 The
84 .BR unlinkat ()
85 system call operates in exactly the same way as either
86 .BR unlink ()
87 or
88 .BR rmdir (2)
89 (depending on whether or not
90 .I flags
91 includes the
92 .B AT_REMOVEDIR
93 flag)
94 except for the differences described here.
95
96 If the pathname given in
97 .I pathname
98 is relative, then it is interpreted relative to the directory
99 referred to by the file descriptor
100 .I dirfd
101 (rather than relative to the current working directory of
102 the calling process, as is done by
103 .BR unlink ()
104 and
105 .BR rmdir (2)
106 for a relative pathname).
107
108 If the pathname given in
109 .I pathname
110 is relative and
111 .I dirfd
112 is the special value
113 .BR AT_FDCWD ,
114 then
115 .I pathname
116 is interpreted relative to the current working
117 directory of the calling process (like
118 .BR unlink ()
119 and
120 .BR rmdir (2)).
121
122 If the pathname given in
123 .I pathname
124 is absolute, then
125 .I dirfd
126 is ignored.
127
128 .I flags
129 is a bit mask that can either be specified as 0, or by ORing
130 together flag values that control the operation of
131 .BR unlinkat ().
132 Currently only one such flag is defined:
133 .TP
134 .B AT_REMOVEDIR
135 By default,
136 .BR unlinkat ()
137 performs the equivalent of
138 .BR unlink ()
139 on
140 .IR pathname .
141 If the
142 .B AT_REMOVEDIR
143 flag is specified, then
144 performs the equivalent of
145 .BR rmdir (2)
146 on
147 .IR pathname .
148 .PP
149 See
150 .BR openat (2)
151 for an explanation of the need for
152 .BR unlinkat ().
153 .SH RETURN VALUE
154 On success, zero is returned.
155 On error, \-1 is returned, and
156 .I errno
157 is set appropriately.
158 .SH ERRORS
159 .TP
160 .B EACCES
161 Write access to the directory containing
162 .I pathname
163 is not allowed for the process's effective UID, or one of the
164 directories in
165 .I pathname
166 did not allow search permission.
167 (See also
168 .BR path_resolution (7).)
169 .TP
170 .BR EBUSY
171 The file
172 .I pathname
173 cannot be unlinked because it is being used by the system
174 or another process;
175 for example, it is a mount point
176 or the NFS client software created it to represent an
177 active but otherwise nameless inode ("NFS silly renamed").
178 .TP
179 .B EFAULT
180 .I pathname
181 points outside your accessible address space.
182 .TP
183 .B EIO
184 An I/O error occurred.
185 .TP
186 .B EISDIR
187 .I pathname
188 refers to a directory.
189 (This is the non-POSIX value returned by Linux since 2.1.132.)
190 .TP
191 .B ELOOP
192 Too many symbolic links were encountered in translating
193 .IR pathname .
194 .TP
195 .B ENAMETOOLONG
196 .IR pathname " was too long."
197 .TP
198 .B ENOENT
199 A component in
200 .I pathname
201 does not exist or is a dangling symbolic link, or
202 .I pathname
203 is empty.
204 .TP
205 .B ENOMEM
206 Insufficient kernel memory was available.
207 .TP
208 .B ENOTDIR
209 A component used as a directory in
210 .I pathname
211 is not, in fact, a directory.
212 .TP
213 .B EPERM
214 The system does not allow unlinking of directories,
215 or unlinking of directories requires privileges that the
216 calling process doesn't have.
217 (This is the POSIX prescribed error return;
218 as noted above, Linux returns
219 .B EISDIR
220 for this case.)
221 .TP
222 .BR EPERM " (Linux only)"
223 The filesystem does not allow unlinking of files.
224 .TP
225 .BR EPERM " or " EACCES
226 The directory containing
227 .I pathname
228 has the sticky bit
229 .RB ( S_ISVTX )
230 set and the process's effective UID is neither the UID of the file to
231 be deleted nor that of the directory containing it, and
232 the process is not privileged (Linux: does not have the
233 .B CAP_FOWNER
234 capability).
235 .TP
236 .B EROFS
237 .I pathname
238 refers to a file on a read-only filesystem.
239 .PP
240 The same errors that occur for
241 .BR unlink ()
242 and
243 .BR rmdir (2)
244 can also occur for
245 .BR unlinkat ().
246 The following additional errors can occur for
247 .BR unlinkat ():
248 .TP
249 .B EBADF
250 .I dirfd
251 is not a valid file descriptor.
252 .TP
253 .B EINVAL
254 An invalid flag value was specified in
255 .IR flags .
256 .TP
257 .B EISDIR
258 .I pathname
259 refers to a directory, and
260 .B AT_REMOVEDIR
261 was not specified in
262 .IR flags .
263 .TP
264 .B ENOTDIR
265 .I pathname
266 is relative and
267 .I dirfd
268 is a file descriptor referring to a file other than a directory.
269 .SH VERSIONS
270 .BR unlinkat ()
271 was added to Linux in kernel 2.6.16;
272 library support was added to glibc in version 2.4.
273 .SH CONFORMING TO
274 .BR unlink ():
275 SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
276 .\" SVr4 documents additional error
277 .\" conditions EINTR, EMULTIHOP, ETXTBSY, ENOLINK.
278
279 .BR unlinkat ():
280 POSIX.1-2008.
281 .SH BUGS
282 Infelicities in the protocol underlying NFS can cause the unexpected
283 disappearance of files which are still being used.
284 .SH SEE ALSO
285 .BR rm (1),
286 .BR chmod (2),
287 .BR link (2),
288 .BR mknod (2),
289 .BR open (2),
290 .BR rename (2),
291 .BR rmdir (2),
292 .BR mkfifo (3),
293 .BR remove (3),
294 .BR path_resolution (7),
295 .BR symlink (7)
296 .SH COLOPHON
297 This page is part of release 3.68 of the Linux
298 .I man-pages
299 project.
300 A description of the project,
301 information about reporting bugs,
302 and the latest version of this page,
303 can be found at
304 \%http://www.kernel.org/doc/man\-pages/.