Home·Terminal commands

rmdir

Files and directories

Usage

rmdir [dir]

Deletes a directory only when it is empty; anything inside makes it refuse, which is why people reach for rm -r.

Common flags

FlagMeaning
-pRemove the directory and every parent that becomes empty
-vReport each removal
--ignore-fail-on-non-emptyGNU: stay quiet when a directory is not empty

Examples

rmdir old

Removes old only if nothing is inside.

rmdir -p a/b/c

Removes c, then b, then a while each is empty.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does rmdir do?

Deletes a directory only when it is empty; anything inside makes it refuse, which is why people reach for rm -r.

Q. How do I type it?

rmdir [dir] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

3 are listed here; the full set is in man rmdir. This command sits under Files and directories.

Related commands

man page: man rmdir