How to Delete a Directory in Linux

Remove empty or non-empty directories safely with rmdir and rm -r.

Use `rmdir` for an empty directory and `rm -r` when a directory contains files. Recursive deletion is powerful because it does not move items to a recycle bin.

Step by step

1 Remove an empty directory

$ rmdir old-folder/

Fails if the directory still contains entries, which makes it a safer first choice.

2 Remove a non-empty directory

$ rm -r old-folder/

Recursively removes the directory and its contents.

3 Confirm each removal

$ rm -ri old-folder/

Interactive recursive mode asks before removing entries.

4 Preview the target

$ find old-folder -maxdepth 2 -print

List what is below the target before destructive removal.

Tips worth knowing

Frequently asked questions

How do I delete an empty directory?

Use `rmdir directory/`.

How do I delete a folder with files?

Use `rm -r directory/` after verifying the target.

Why is rm -rf dangerous?

It recursively removes files without interactive confirmation and can cause irreversible data loss.

The commands behind it

rm

Delete files and directories — and understand -r, -f and why there is no trash bin.

find

Locate files anywhere in a directory tree by name, type, size, date — and act on them.

More how-to guides

Check disk space in Linux

See how much space is left, and find out what is using it.

Extract a .tar.gz archive

Unpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.

Free a port that is already in use

Find which process holds a port and stop it cleanly.

Find and replace text in files

Replace text in one file or across a whole project, safely.