Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · file management

rmdir

remove an empty directory

rmdir deletes a directory and refuses if anything is still inside it. That refusal is the point: it cannot destroy files by accident, which rm -r can.

The safe way to remove a directory: it only works when there is nothing to lose.

Removes
Empty directories
and nothing else
If not empty
An error
nothing is deleted
Parents too
-p
a/b/c, then a/b, then a
For full ones
rm -r
with care

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashcoreutils
$ rmdir old-reports
1$ rmdir project
2rmdir: failed to remove 'project': Directory not empty
3$ ls -a project
. .. .gitignore
4$ rmdir -pv a/b/c
rmdir: removing directory, 'a/b/c'
rmdir: removing directory, 'a/b'
rmdir: removing directory, 'a'
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
Success is silent

old-reports was empty and is gone. Like most commands, rmdir prints nothing when it works.

2
A directory with contents is refused

Nothing was removed. The error is the safety feature doing its job.

3
It looked empty, but was not

A hidden file was inside. ls -a shows dot files; plain ls would have shown nothing.

4
-p removes the chain

Each directory is removed once the one inside it has gone, as long as each is empty in turn.

Switches

A switch changes how the command behaves. These are the ones used day to day; man rmdir lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-p
Parents: remove each directory in the path as it becomes empty.
-v
Verbose: print each directory removed.
--ignore-fail-on-non-empty
Do not report an error for directories that are not empty.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

rmdir dir1 dir2 dir3

Removes several empty directories at once.

find . -type d -empty -delete

Removes every empty directory beneath the current one.

rmdir --ignore-fail-on-non-empty */

Removes the empty ones and stays quiet about the rest.

rm -r project

Removes a directory and all its contents — the tool for when it is not empty.

In cybersecurity

Choosing rmdir over rm -r is a habit that prevents accidents.

Prefer it in scripts

A cleanup script that uses rmdir fails loudly if a directory unexpectedly has contents, instead of deleting them.

Empty directories still matter

A mount point is an empty directory. Removing it makes the mount fail at next boot.

Removal needs write on the parent

What decides whether you may remove a directory is the permission on the directory that contains it, not on the directory itself.

Filed under

File management

Read alongside