rmdir(1)

rmdir1

Remove directories

Usage

rmdir [-pv] 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 following option is available:

-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.)

-v

Be verbose, listing each directory as it is removed.

Exit status

The rmdir utility exits with one of the following values:

0

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

1

An error occurred while attempting to remove one or more directories.

2

Invalid arguments.

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

87 releases since FreeBSD 2.0.5-RELEASE; the text changed 46 times.

  1. 2.0.5
  2. 2.1.5–2.1.7.1
  3. 2.2.2
  4. 2.2.5–2.2.6
  5. 2.2.7–2.2.8
  6. 2.2.9
  7. 3.0–3.2
  8. 3.3–3.5.1
  9. 4.0–4.2
  10. 4.3–4.11
  11. 5.0–5.2.1
  12. 5.3–5.5
  13. 6.0–6.3
  14. 6.4
  15. 7.0
  16. 7.1
  17. 7.2
  18. 7.3
  19. 7.4
  20. 8.0
  21. 8.1
  22. 8.2
  23. 8.3
  24. 8.4
  25. 9.0
  26. 9.1
  27. 9.2
  28. 9.3
  29. 10.0
  30. 10.1
  31. 10.2
  32. 10.3
  33. 10.4
  34. 11.0
  35. 11.1
  36. 11.2
  37. 11.3
  38. 11.4
  39. 12.0
  40. 12.1
  41. 12.2
  42. 12.3
  43. 12.4
  44. 13.0–13.2
  45. 13.3–14.5
  46. 15.0–15.1
  47. 16.0

-p since FreeBSD 2.2.5-RELEASE; -v since FreeBSD 5.3-RELEASE.

Standards

The rmdir utility is expected to be IEEE Std 1003.2 (“POSIX.2”) compatible.

The -v option is an extension to that specification.

History

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

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.