Delete a folder
Remove directories with rm -r
⏱ Est. ~3 min
01 · Read
Deleting a folder isn't the same as deleting a file. You have to tell rm to work recursively — meaning, delete everything inside first, then the folder itself.
💡 Picture thisYou can't tear down a room that's still full of furniture. rm -r clears out the contents first, then knocks down the room.
Key points
- rm -r deletes a folder and everything inside it
- The -r flag stands for recursive — it walks through all the contents
- Be very careful — once it's gone, all of it is gone with no undo
02 · Terminal exercise
Deleting a folder is a little different from deleting a file — you have to tell rm to be recursive.
(This section is interactive — please enable JavaScript.)
03 · Terminal exercise
To delete a folder and everything inside, add -r (recursive).
(This section is interactive — please enable JavaScript.)
04 · Quiz
Why does rm myfolder (without -r) fail?
- Folders are read-only by default
- You have to empty the folder first
- rm only deletes files by default — folders need -r (recursive) to delete the contents too
- Folder names need quotes around them
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.