1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\" and Copyright (C) 1993 Ian Jackson
3 .\" and Copyright (C) 2006, 2014 Michael Kerrisk.
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.
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.
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
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
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>
33 .TH UNLINK 2 2017-03-13 "Linux" "Linux Programmer's Manual"
35 unlink, unlinkat \- delete a name and possibly the file it refers to
38 .B #include <unistd.h>
40 .BI "int unlink(const char *" pathname );
42 .BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
43 .B #include <unistd.h>
45 .BI "int unlinkat(int " dirfd ", const char *" pathname ", int " flags );
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
59 _POSIX_C_SOURCE\ >=\ 200809L
68 deletes a name from the filesystem.
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.
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.
77 If the name referred to a symbolic link, the link is removed.
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
85 system call operates in exactly the same way as either
89 (depending on whether or not
94 except for the differences described here.
96 If the pathname given in
98 is relative, then it is interpreted relative to the directory
99 referred to by the file descriptor
101 (rather than relative to the current working directory of
102 the calling process, as is done by
106 for a relative pathname).
108 If the pathname given in
116 is interpreted relative to the current working
117 directory of the calling process (like
122 If the pathname given in
129 is a bit mask that can either be specified as 0, or by ORing
130 together flag values that control the operation of
132 Currently, only one such flag is defined:
137 performs the equivalent of
143 flag is specified, then
144 performs the equivalent of
151 for an explanation of the need for
154 On success, zero is returned.
155 On error, \-1 is returned, and
157 is set appropriately.
161 Write access to the directory containing
163 is not allowed for the process's effective UID, or one of the
166 did not allow search permission.
168 .BR path_resolution (7).)
173 cannot be unlinked because it is being used by the system
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").
181 points outside your accessible address space.
184 An I/O error occurred.
188 refers to a directory.
189 (This is the non-POSIX value returned by Linux since 2.1.132.)
192 Too many symbolic links were encountered in translating
196 .IR pathname " was too long."
201 does not exist or is a dangling symbolic link, or
206 Insufficient kernel memory was available.
209 A component used as a directory in
211 is not, in fact, a directory.
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
222 .BR EPERM " (Linux only)"
223 The filesystem does not allow unlinking of files.
225 .BR EPERM " or " EACCES
226 The directory containing
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
237 The file to be unlinked is marked immutable or append-only.
239 .BR ioctl_iflags (2).)
243 refers to a file on a read-only filesystem.
245 The same errors that occur for
251 The following additional errors can occur for
256 is not a valid file descriptor.
259 An invalid flag value was specified in
264 refers to a directory, and
273 is a file descriptor referring to a file other than a directory.
276 was added to Linux in kernel 2.6.16;
277 library support was added to glibc in version 2.4.
280 SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
281 .\" SVr4 documents additional error
282 .\" conditions EINTR, EMULTIHOP, ETXTBSY, ENOLINK.
288 On older kernels where
290 is unavailable, the glibc wrapper function falls back to the use of
296 is a relative pathname,
297 glibc constructs a pathname based on the symbolic link in
299 that corresponds to the
303 Infelicities in the protocol underlying NFS can cause the unexpected
304 disappearance of files which are still being used.
316 .BR path_resolution (7),