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
| Flag | Meaning |
|---|---|
| -p | Remove the directory and every parent that becomes empty |
| -v | Report each removal |
| --ignore-fail-on-non-empty | GNU: stay quiet when a directory is not empty |
Examples
rmdir oldRemoves old only if nothing is inside.
rmdir -p a/b/cRemoves 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