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 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
8 .\" Modified 1996-09-08 by Arnt Gulbrandsen <agulbra@troll.no>
9 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
10 .\" Modified 2001-05-17 by aeb
11 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
13 .TH unlink 2 (date) "Linux man-pages (unreleased)"
15 unlink, unlinkat \- delete a name and possibly the file it refers to
18 .RI ( libc ", " \-lc )
21 .B #include <unistd.h>
23 .BI "int unlink(const char *" pathname );
25 .BR "#include <fcntl.h> " "/* Definition of " AT_* " constants */"
26 .B #include <unistd.h>
28 .BI "int unlinkat(int " dirfd ", const char *" pathname ", int " flags );
32 Feature Test Macro Requirements for glibc (see
33 .BR feature_test_macros (7)):
39 _POSIX_C_SOURCE >= 200809L
45 deletes a name from the filesystem.
47 last link to a file and no processes have the file open, the file is
48 deleted and the space it was using is made available for reuse.
50 If the name was the last link to a file but any processes still have
51 the file open, the file will remain in existence until the last file
52 descriptor referring to it is closed.
54 If the name referred to a symbolic link, the link is removed.
56 If the name referred to a socket, FIFO, or device, the name for it is
57 removed but processes which have the object open may continue to use
62 system call operates in exactly the same way as either
66 (depending on whether or not
71 except for the differences described here.
73 If the pathname given in
75 is relative, then it is interpreted relative to the directory
76 referred to by the file descriptor
78 (rather than relative to the current working directory of
79 the calling process, as is done by
83 for a relative pathname).
85 If the pathname given in
93 is interpreted relative to the current working
94 directory of the calling process (like
99 If the pathname given in
106 is a bit mask that can either be specified as 0, or by ORing
107 together flag values that control the operation of
109 Currently, only one such flag is defined:
114 performs the equivalent of
120 flag is specified, then
121 performs the equivalent of
128 for an explanation of the need for
131 On success, zero is returned.
132 On error, \-1 is returned, and
134 is set to indicate the error.
138 Write access to the directory containing
140 is not allowed for the process's effective UID, or one of the
143 did not allow search permission.
145 .BR path_resolution (7).)
150 cannot be unlinked because it is being used by the system
152 for example, it is a mount point
153 or the NFS client software created it to represent an
154 active but otherwise nameless inode ("NFS silly renamed").
158 points outside your accessible address space.
161 An I/O error occurred.
165 refers to a directory.
166 (This is the non-POSIX value returned since Linux 2.1.132.)
169 Too many symbolic links were encountered in translating
173 .IR pathname " was too long."
178 does not exist or is a dangling symbolic link, or
183 Insufficient kernel memory was available.
186 A component used as a directory in
188 is not, in fact, a directory.
191 The system does not allow unlinking of directories,
192 or unlinking of directories requires privileges that the
193 calling process doesn't have.
194 (This is the POSIX prescribed error return;
195 as noted above, Linux returns
199 .BR EPERM " (Linux only)"
200 The filesystem does not allow unlinking of files.
202 .BR EPERM " or " EACCES
203 The directory containing
207 set and the process's effective UID is neither the UID of the file to
208 be deleted nor that of the directory containing it, and
209 the process is not privileged (Linux: does not have the
214 The file to be unlinked is marked immutable or append-only.
216 .BR ioctl_iflags (2).)
220 refers to a file on a read-only filesystem.
222 The same errors that occur for
228 The following additional errors can occur for
237 nor a valid file descriptor.
240 An invalid flag value was specified in
245 refers to a directory, and
254 is a file descriptor referring to a file other than a directory.
260 SVr4, 4.3BSD, POSIX.1-2001.
261 .\" SVr4 documents additional error
262 .\" conditions EINTR, EMULTIHOP, ETXTBSY, ENOLINK.
269 On older kernels where
271 is unavailable, the glibc wrapper function falls back to the use of
277 is a relative pathname,
278 glibc constructs a pathname based on the symbolic link in
280 that corresponds to the
284 Infelicities in the protocol underlying NFS can cause the unexpected
285 disappearance of files which are still being used.
297 .BR path_resolution (7),