How to Delete a Directory in Terminal: Commands, Options, and What to Know First
Deleting a directory from the command line is one of those tasks that looks simple on the surface but carries real consequences if you get the syntax wrong. Unlike dragging a folder to the Trash, a terminal delete can be immediate, permanent, and unforgiving. Understanding exactly which command to use — and when — makes the difference between a clean operation and an accidental data loss.
The Two Core Commands for Removing Directories
On macOS, Linux, and other Unix-based systems, two commands handle directory deletion:
- rmdir — removes empty directories only
- rm -r — removes directories and all their contents recursively
Windows users working in Command Prompt use rmdir or its shorthand rd, while PowerShell supports Remove-Item with recursive options.
Using rmdir for Empty Directories
The rmdir command is the safer of the two. It will only succeed if the directory contains nothing at all — no files, no subdirectories, no hidden files.