Back to the command reference

rmdir

FilesBeginner In simulator In real Linux

Remove empty directories

Name: rmdir = remove directory

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

rmdir removes directories only if they are empty; any entry inside, hidden files included, makes it fail. That limit is a safety net against deleting content by accident.

To remove a directory with its contents, use rm -r.

Syntax

rmdir [OPTION]... DIRECTORY...

Common options

-p / --parentsAlso remove parents that become empty
-v / --verbosePrint a line for each directory removed
--ignore-fail-on-non-emptyDo not complain about directories that are not empty (they stay)

Examples

  • $ mkdir empty && rmdir empty

    Create and remove an empty directory

    Explain
  • $ rmdir projects

    Fails on a non-empty directory; use rm -r instead

    Explain

Related