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
- Avoid `rm -rf` unless you genuinely need forced recursive removal.
- Never run a destructive rm command until you have checked the current directory and path.
- Backups are the only reliable recovery after an accidental permanent deletion.
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
Delete files and directories — and understand -r, -f and why there is no trash bin.
findLocate files anywhere in a directory tree by name, type, size, date — and act on them.
More how-to guides
See how much space is left, and find out what is using it.
Extract a .tar.gz archiveUnpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.