How to Delete a Folder in the Terminal (rm -r)
You just finished a project, and now your folder is stuffed with leftover stuff you don’t need. Old build folders, junk files, things from three experiments ago. You want it all gone at once, not one file at a time. The good news: there is a single command for that.
To delete a folder in the terminal, type rm -r foldername and press Enter. The rm means remove, the -r means “go inside and remove everything in it too,” and foldername is the folder you want gone — including all the files inside it, in one shot.
That is the whole idea behind learning how to delete a folder in the terminal. Deleting one file is easy. But a folder packed with files needs a command that clears the entire thing in one go. Let’s break it down so it never feels scary.
What command deletes a whole folder?
The command is rm -r, followed by the folder’s name. Here is what each part does:
rmmeans remove — simply, “delete this.”-rmeans recursive — “go inside the folder and remove everything in it too.”buildis just the folder name — swap in whatever yours is called.
So to delete a folder called build, you type:
rm -r build
Press Enter, and it runs. The whole folder disappears, along with every file inside it.
Why does it delete everything inside too?
Without -r, the terminal refuses to remove a folder that has things in it. A plain rm build would complain. The -r flag tells it to step inside, clear out each file, then remove the folder itself. That is why one short command can wipe a whole tree of files at once.
Think of clearing a WhatsApp chat. You are not deleting one message — you are wiping the whole conversation, every message, all at once. And once that chat is gone, there is no getting it back. Deleting a folder this way works exactly the same.
Why should I be extra careful with this command?
Because there is no recycle bin here. No undo, no “are you sure?”, no second chance. One wrong name and that folder is gone for good.
So build one simple habit: always read the folder name twice before you press Enter. Make sure you are deleting build and not, say, your whole project folder. A two-second check saves hours of regret.
How do I try it safely?
The safest way to practice is to delete something that does not matter. Make a throwaway “junk” folder first, then remove it:
mkdir junk
rm -r junk
Watch the whole folder vanish. Since you created it just to test, there is nothing to lose. Once you have done this two or three times, the command stops feeling scary and starts feeling normal.
This builds right on what you learned about deleting single files with rm — the folder version is the same command with one extra flag. Next, you will pick up copying files with cp, so nothing important ever has to be at risk in the first place.
Key takeaways
- Command:
rm -r foldernamedeletes a folder and everything inside it. rmmeans remove;-rmeans recursive (go inside and clear it all).- No recycle bin: deletion is permanent — there is no undo.
- Safety habit: always read the folder name twice before pressing Enter.
- Practice safely: make a
junkfolder, then delete it to learn risk-free.
Want to go from “what’s a terminal?” to building real apps with AI, step by step? This lesson is part of the free Zero to AI Hero course by Meegrow Labs — simple Hindi and English, a new short lesson every day.
🚀 Take the full free course: Zero to AI Hero — learn to build with AI from scratch. New lessons daily, in Hindi & English.
Want to actually learn this?
151 free 2-minute lessons — from "what's a file?" to building with AI.
▶ Start the free course