Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

rmdir - remove directory

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

int rmdir(const char *path); 

Description

rmdir() removes a directory whose name is given by path. The directory is removed only if it is an empty directory.

If path is a symbolic link, it is not followed.

If path is the root directory, then path is set to EBUSY; if path is the current directory of an active process, the behavior of rmdir() is unspecified.

If the directory link count becomes 0 and no process has the directory open, the space occupied by the directory will be freed and the directory will no longer be accessible. If one or more processes have the directory open when the last link is removed, the dot and dot-dot entries, if present, are removed before rmdir() returns and no new entries may be created in the directory, but the directory is not removed until all references to the directory are closed.

Upon successful completion, rmdir() marks the st_ctime and st_mtime fields of the parent directory for update.

Return val.

0

if successful.


-1

if an error occurs. errno is set to indicate the error.

Errors

rmdir() will fail if:

 

 

EACCES

Search permission is denied on a component of the path, or write permission is denied on the parent directory of the directory to be removed.

 

EBUSY

The directory to be removed is currently in use by the system or another process.

 

EEXIST or ENOTEMPTY 



path names a directory that is not an empty directory.

 

Extension


 

EFAULT

 path points outside the allocated address space of the process.

 

EINVAL

The directory to be removed is the current directory.

 

EIO

An I/O error occurred when accessing the file system.

 

ELOOP

Too many symbolic links were encountered in resolving path. (End)


ENAMETOOLONG



The length of the path argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX} and {_POSIX_NO_TRUNC} is set.


ENOENT

path names a non-existent directory or points to an empty string .


ENOTDIR

A component of the path is not a directory. (End)


EROFS

The directory entry to be removed resides on a read-only file system.

 Notes

rmdir() is executed only for POSIX files.

 See also

mkdir(), remove(), unlink(), unistd.h.