↑↓ move Enter open Esc close

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

More how-to guides