*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->HP-UX 11i man pages -> unlink (2)              


 unlink(2)                                                         unlink(2)

 NAME    [Toc]    [Back]
      unlink - remove directory entry; delete file

 SYNOPSIS    [Toc]    [Back]
      #include <unistd.h>

      int unlink(const char *path);

 DESCRIPTION    [Toc]    [Back]
      The unlink() system call removes the directory entry named by the path
      name pointed to by path.

      When all links to a file have been removed and no process has the file
      open, the space occupied by the file is freed and the file ceases to
      exist.  If one or more processes have the file open when the last link
      is removed, only the directory entry is removed immediately so that
      processes that do not already have the file open cannot access the
      file.  After all processes close their references to the file, if
      there are no more links to the file, the space occupied by the file is
      then freed and the file ceases to exist.

 RETURN VALUE    [Toc]    [Back]
      unlink() returns the following values:

            0   Successful completion.
           -1   Failure.  errno is set to indicate the error.

 ERRORS    [Toc]    [Back]
      If unlink() fails, errno is set to one of the following values:

           [EACCES]            Search permission is denied for a component
                               of the path prefix.

           [EACCES]            Write permission is denied on the directory
                               containing the link to be removed.

           [EACCES]            The process does not have read/write access
                               permission to the parent directory.

           [EBUSY]             The entry to be unlinked is the mount point
                               for a mounted file system.

           [EFAULT]            path points outside the process's allocated
                               address space.  The reliable detection of
                               this error is implementation dependent.

           [ELOOP]             Too many symbolic links were encountered in
                               translating the path name.

           [ENAMETOOLONG]      The length of the specified path name exceeds
                               PATH_MAX bytes, or the length of a component

 Hewlett-Packard Company            - 1 -   HP-UX 11i Version 2: August 2003

 unlink(2)                                                         unlink(2)

                               of the path name exceeds NAME_MAX bytes while
                               _POSIX_NO_TRUNC is in effect.

           [ENOENT]            The named file does not exist (for example,
                               path is null or a component of path does not

           [ENOTDIR]           A component of the path prefix is not a

           [EPERM]             The directory containing the file to be
                               removed has the sticky bit set and neither
                               the containing directory nor the file to be
                               removed are owned by the effective user ID.

           [EPERM]             The named file is a directory and the
                               effective user ID is not a user with
                               appropriate privileges.

           [EROFS]             The directory entry to be unlinked is part of
                               a read-only file system.

           [ETXTBSY]           The entry to be unlinked is the last link to
                               a pure procedure (shared text) file that is
                               being executed.

 WARNINGS    [Toc]    [Back]
      If unlink() is used on a directory that is not empty (contains files
      other than .  and ..), the directory is unlinked, the files become
      orphans, and the directory link count is left with an inaccurate value
      unless they are linked by some other directory.

      If unlink() is used on a directory that is empty (contains only the
      files .  and ..), the directory is unlinked, but the parent
      directory's link count is left with an inaccurate value.

      In either of the above cases, the file system should be checked using
      fsck (see fsck(1M)).  To avoid these types of problems, use rmdir()
      instead (see rmdir(2)).

 SEE ALSO    [Toc]    [Back]
      rm(1), close(2), link(2), open(2), rmdir(2), remove(3C).

      unlink(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1

 Hewlett-Packard Company            - 2 -   HP-UX 11i Version 2: August 2003
[ Back ]
 Similar pages
Name OS Title
unlink NetBSD remove directory entry
remove NetBSD remove directory entry
unlink IRIX remove directory entry
unlink Tru64 Remove a directory entry
unlink FreeBSD remove directory entry
unlink OpenBSD remove directory entry
remove FreeBSD remove directory entry
deletehost IRIX delete an entry from the host file.
remove OpenBSD remove a file or directory
rmdir NetBSD remove a directory file
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service