1 .\" Copyright (c) 1980, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)unlink.2 8.1 (Berkeley) 6/4/93
37 .Nd remove directory entry
43 .Fn unlink "const char *path"
45 .Fn unlinkat "int dfd" "const char *path" "int flag"
47 .Fn funlinkat "int dfd" "const char *path" "int fd" "int flag"
52 removes the link named by
54 from its directory and decrements the link count of the
55 file which was referenced by the link.
56 If that decrement reduces the link count of the file
58 and no process has the file open, then
59 all resources associated with the file are reclaimed.
60 If one or more process have the file open when the last link is removed,
61 the link is removed, but the removal of the file is delayed until
62 all references to it have been closed.
66 may not be a directory.
70 system call is equivalent to
74 except in the case where
76 specifies a relative path.
77 In this case the directory entry to be removed is determined
78 relative to the directory associated with the file descriptor
80 instead of the current working directory.
84 are constructed by a bitwise-inclusive OR of flags from the following list,
87 .Bl -tag -width indent
89 Remove the directory entry specified by
93 as a directory, not a normal file.
95 Only unlink files and directories which are beneath of the topping
97 See the description of the
106 is passed the special value
110 parameter, the current working directory is used and the behavior is
111 identical to a call to
115 respectively, depending on whether or not the
121 system call can be used to unlink an already-opened file, unless that
122 file has been replaced since it was opened.
127 is already open as the file descriptor
129 Otherwise, the path will not be removed and an error will be returned.
146 A component of the path prefix is not a directory.
148 The named file is a directory.
149 .It Bq Er ENAMETOOLONG
150 A component of a pathname exceeded 255 characters,
151 or an entire path name exceeded 1023 characters.
153 The named file does not exist.
155 Search permission is denied for a component of the path prefix.
157 Write permission is denied on the directory containing the link
160 Too many symbolic links were encountered in translating the pathname.
162 The named file is a directory.
164 The named file has its immutable, undeletable or append-only flag set, see the
166 manual page for more information.
168 The parent directory of the named file has its immutable or append-only flag
171 The directory containing the file is marked sticky,
172 and neither the containing directory nor the file to be removed
173 are owned by the effective user ID.
175 An I/O error occurred while deleting the directory entry
176 or deallocating the inode.
178 The named file resides on a read-only file system.
183 points outside the process's allocated address space.
185 On file systems supporting copy-on-write or snapshots, there was not enough
186 free space to record metadata for the delete operation of the file.
189 In addition to the errors returned by the
198 argument does not specify an absolute path and the
202 nor a valid file descriptor open for searching.
210 argument names a directory that is not an empty directory,
211 or there are hard links to the directory other than dot or
212 a single entry in dot-dot.
220 does not name a directory.
224 argument is not valid.
228 argument is not an absolute path and
232 nor a file descriptor associated with a directory.
233 .It Bq Er ENOTCAPABLE
236 or contained a ".." component leading to a
237 directory outside of the directory hierarchy specified by
239 and the process is in capability mode.
240 .It Bq Er ENOTCAPABLE
247 does not have its tail fully contained under the topping directory,
253 In addition to the errors returned by
259 The file descriptor is not associated with the path.
270 system call follows The Open Group Extended API Set 2 specification.
278 system call appeared in
282 system call appeared in
287 system call traditionally allows the super-user to unlink directories which
288 can damage the file system integrity.
289 This implementation no longer permits it.