1UNLINK(2)                  Linux Programmer's Manual                 UNLINK(2)
2
3
4

NAME

6       unlink - delete a name and possibly the file it refers to
7

SYNOPSIS

9       #include <unistd.h>
10
11       int unlink(const char *pathname);
12

DESCRIPTION

14       unlink()  deletes  a  name  from the file system.  If that name was the
15       last link to a file and no processes have the file  open  the  file  is
16       deleted and the space it was using is made available for reuse.
17
18       If  the  name  was the last link to a file but any processes still have
19       the file open the file will remain in existence  until  the  last  file
20       descriptor referring to it is closed.
21
22       If the name referred to a symbolic link the link is removed.
23
24       If  the  name  referred  to a socket, fifo or device the name for it is
25       removed but processes which have the object open may  continue  to  use
26       it.
27

RETURN VALUE

29       On  success,  zero is returned.  On error, -1 is returned, and errno is
30       set appropriately.
31

ERRORS

33       EACCES Write access to the directory containing pathname is not allowed
34              for  the  process's  effective UID, or one of the directories in
35              pathname did not allow search permission.  (See also  path_reso‐
36              lution(7).)
37
38       EBUSY (not on Linux)
39              The file pathname cannot be unlinked because it is being used by
40              the system or another process and the  implementation  considers
41              this an error.
42
43       EFAULT pathname points outside your accessible address space.
44
45       EIO    An I/O error occurred.
46
47       EISDIR pathname  refers  to  a directory.  (This is the non-POSIX value
48              returned by Linux since 2.1.132.)
49
50       ELOOP  Too many symbolic links were encountered  in  translating  path‐
51              name.
52
53       ENAMETOOLONG
54              pathname was too long.
55
56       ENOENT A component in pathname does not exist or is a dangling symbolic
57              link, or pathname is empty.
58
59       ENOMEM Insufficient kernel memory was available.
60
61       ENOTDIR
62              A component used as a directory in pathname is not, in  fact,  a
63              directory.
64
65       EPERM  The system does not allow unlinking of directories, or unlinking
66              of directories requires  privileges  that  the  calling  process
67              doesn't  have.   (This  is the POSIX prescribed error return; as
68              noted above, Linux returns EISDIR for this case.)
69
70       EPERM (Linux only)
71              The file system does not allow unlinking of files.
72
73       EPERM or EACCES
74              The directory containing pathname has the sticky  bit  (S_ISVTX)
75              set  and  the  process's effective UID is neither the UID of the
76              file to be deleted nor that of the directory containing it,  and
77              the  process  is  not  privileged  (Linux:  does  not  have  the
78              CAP_FOWNER capability).
79
80       EROFS  pathname refers to a file on a read-only file system.
81

CONFORMING TO

83       SVr4, 4.3BSD, POSIX.1-2001.
84

BUGS

86       Infelicities in the protocol underlying NFS can  cause  the  unexpected
87       disappearance of files which are still being used.
88

SEE ALSO

90       rm(1),  chmod(2),  link(2),  mknod(2),  open(2),  rename(2),  rmdir(2),
91       unlinkat(2), mkfifo(3), remove(3), path_resolution(7), symlink(7)
92

COLOPHON

94       This page is part of release 3.25 of the Linux  man-pages  project.   A
95       description  of  the project, and information about reporting bugs, can
96       be found at http://www.kernel.org/doc/man-pages/.
97
98
99
100Linux                             2004-06-23                         UNLINK(2)
Impressum