rmdir(1)

rmdir1

Remove directories

Usage

rmdir [-p] directory ...

Overview

The rmdir utility removes the directory entry specified by each directory argument, provided it is empty.

Arguments are processed in the order given. In order to remove both a parent directory and a subdirectory of that parent, the subdirectory must be specified first so the parent directory is empty when rmdir tries to remove it.

The options are as follows:

-p

Each directory argument is treated as a pathname of which all components will be removed, if they are empty, starting with the last most component. (See rm(1) for fully non-discriminant recursive removal.)

Exit status

The rmdir utility exits with one of the following values:

0

Each directory argument referred to an empty directory and was removed successfully.

0

An error occurred.

Examples

Remove the directory foobar, if it is empty:

$ rmdir foobar

Remove all directories up to and including cow, stopping at the first non-empty directory (if any):

$ rmdir -p cow/horse/monkey

Releases

61 releases since OpenBSD 2.1; the text changed 12 times.

  1. 2.1–2.3
  2. 2.4
  3. 2.5
  4. 2.6
  5. 2.7
  6. 2.8–2.9
  7. 3.0
  8. 3.1–3.2
  9. 3.3
  10. 3.4–4.1
  11. 4.2–4.4
  12. 4.5–4.8
  13. 4.9–8.0

Standards

The rmdir utility is compliant with the IEEE Std 1003.1-2008 (“POSIX.1”) specification.

History

A rmdir command appeared in Version 1 AT&T UNIX.

From man 8.0-current-20261101 in OpenBSD 8.0-current (2026-11-01). Parsed by carta from the page's mdoc source.