Skip to content

The rmdir command

The rmdir command removes empty directories…

The rmdir command removes empty directories, and refuses to remove one with anything in it, which makes it a safe way to tidy up.

Taught in Beginner, lesson 6

A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.

Usage

rmdir DIRECTORY...

Remove empty directories. Removes directories, but only empty ones, which makes it a safe way to tidy up. Use rm -r for a directory with files in it.

How to use rmdir

Remove an empty folder

rmdir old && ls -d old*
old-site  old.txt

A folder that isn’t empty

rmdir stops with "Directory not empty". To delete a folder and everything in it, use rm -r, carefully.

rm -r build

More examples

rmdir old
Remove the empty folder old

Questions about rmdir

What is the difference between rmdir and rm -r?

rmdir only removes empty directories. rm -r removes a directory and everything inside it, with no undo.

Learn it step by step

Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.