.TH unlink() "" "" "System Call (libc)"
.PC "Remove a file"
.B "#include <unistd.h>"
\fBint unlink(\fIname\^\fB) char *\fIname\^\fB;\fR
.PP
.B unlink()
removes the directory entry for the given file
.IR name ,
which in effect erases
.I name
from the disk.
.I name
cannot be opened once it has been
.BR unlink() 'd.
If
.I name
is the last link,
.B unlink()
frees the i-node and data blocks.
Deallocation is delayed if the file is open.
Other links to the file remain intact.
.SH Example
This example removes the files named on the command line.
.DM
#include <unistd.h>
main(argc, argv)
int argc; char *argv[];
{
	int i;
.DE
.DM
	for (i = 1; i < argc; i++) {
		if (unlink(argv[i]) == -1) {
			printf("Cannot unlink \e"%s\e"\en", argv[i]);
			exit(EXIT_FAILURE);
		}
	}
	exit(EXIT_SUCCESS);
}
.DE
.SH "See Also"
.Xr "libc," libc
.Xr "link()," link
.Xr "ln," ln
.Xr "remove()," remove
.Xr "rm," rm
.Xr "rmdir," rmdir
.Xr "unistd.h" unistd.h
.br
\*(PX Standard, \(sc5.5.1
.SH Diagnostics
.B unlink()
returns zero when successful.
It returns \-1 if
.I file
does not exist, if the user does not have write and search
permission in the directory containing
.IR file ,
or if
.I file
is a directory and the invoker is not the superuser.
