Your Guide to How To Delete a Directory In Terminal
What You Get:
Free Guide
Free, helpful information about Computers & Operating Systems and related How To Delete a Directory In Terminal topics.
Helpful Information
Get clear and easy-to-understand details about How To Delete a Directory In Terminal topics and resources.
Personalized Offers
Answer a few optional questions to receive offers or information related to Computers & Operating Systems. The survey is optional and not required to access your free guide.
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.