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 2021-08-27 "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)):
56 _POSIX_C_SOURCE >= 200809L
62 deletes a name from the filesystem.
64 last link to a file and no processes have the file open, the file is
65 deleted and the space it was using is made available for reuse.
67 If the name was the last link to a file but any processes still have
68 the file open, the file will remain in existence until the last file
69 descriptor referring to it is closed.
71 If the name referred to a symbolic link, the link is removed.
73 If the name referred to a socket, FIFO, or device, the name for it is
74 removed but processes which have the object open may continue to use
79 system call operates in exactly the same way as either
83 (depending on whether or not
88 except for the differences described here.
90 If the pathname given in
92 is relative, then it is interpreted relative to the directory
93 referred to by the file descriptor
95 (rather than relative to the current working directory of
96 the calling process, as is done by
100 for a relative pathname).
102 If the pathname given in
110 is interpreted relative to the current working
111 directory of the calling process (like
116 If the pathname given in
123 is a bit mask that can either be specified as 0, or by ORing
124 together flag values that control the operation of
126 Currently, only one such flag is defined:
131 performs the equivalent of
137 flag is specified, then
138 performs the equivalent of
145 for an explanation of the need for
148 On success, zero is returned.
149 On error, \-1 is returned, and
151 is set to indicate the error.
155 Write access to the directory containing
157 is not allowed for the process's effective UID, or one of the
160 did not allow search permission.
162 .BR path_resolution (7).)
167 cannot be unlinked because it is being used by the system
169 for example, it is a mount point
170 or the NFS client software created it to represent an
171 active but otherwise nameless inode ("NFS silly renamed").
175 points outside your accessible address space.
178 An I/O error occurred.
182 refers to a directory.
183 (This is the non-POSIX value returned by Linux since 2.1.132.)
186 Too many symbolic links were encountered in translating
190 .IR pathname " was too long."
195 does not exist or is a dangling symbolic link, or
200 Insufficient kernel memory was available.
203 A component used as a directory in
205 is not, in fact, a directory.
208 The system does not allow unlinking of directories,
209 or unlinking of directories requires privileges that the
210 calling process doesn't have.
211 (This is the POSIX prescribed error return;
212 as noted above, Linux returns
216 .BR EPERM " (Linux only)"
217 The filesystem does not allow unlinking of files.
219 .BR EPERM " or " EACCES
220 The directory containing
224 set and the process's effective UID is neither the UID of the file to
225 be deleted nor that of the directory containing it, and
226 the process is not privileged (Linux: does not have the
231 The file to be unlinked is marked immutable or append-only.
233 .BR ioctl_iflags (2).)
237 refers to a file on a read-only filesystem.
239 The same errors that occur for
245 The following additional errors can occur for
254 nor a valid file descriptor.
257 An invalid flag value was specified in
262 refers to a directory, and
271 is a file descriptor referring to a file other than a directory.
274 was added to Linux in kernel 2.6.16;
275 library support was added to glibc in version 2.4.
278 SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
279 .\" SVr4 documents additional error
280 .\" conditions EINTR, EMULTIHOP, ETXTBSY, ENOLINK.
286 On older kernels where
288 is unavailable, the glibc wrapper function falls back to the use of
294 is a relative pathname,
295 glibc constructs a pathname based on the symbolic link in
297 that corresponds to the
301 Infelicities in the protocol underlying NFS can cause the unexpected
302 disappearance of files which are still being used.
314 .BR path_resolution (7),