Removing Folders
Rmdir and rm -r.
Deleting a folder is a little different from deleting a file. Linux protects you here, by making you say clearly what you want.

- Folders are different
- Linux protects you
- Say clearly what you want
rmdir for empty folders
RM dir removes a folder, but only if it's empty. Here we make an empty folder called old, and RM dir removes it. But Documents has files inside, so RM dir refuses, and says, directory not empty. That's a safety net.
mkdir old rmdir old rmdir Documents rmdir: failed to remove 'Documents': Directory not empty
rm -r for folders with files
To delete a folder and everything inside it, use RM dash R, for recursive. It deletes the folder, every file in it, and every folder inside that, all the way down. One command, and the whole Music folder is gone.
rm -r Music ls Documents Downloads Pictures notes.txt todo.txt
The command to respect
You'll see RM dash RF online. The F means force. Don't ask, don't complain, just delete. Combined with the wrong path, it can wipe out your work in a second, with no undo. Always double check the path. And never run RM dash RF with a slash, or a tilde, unless you're absolutely sure.
| key | value |
|---|---|
| rm -r | delete a folder and its contents |
| -f | force: no questions |
| No undo | gone for good |
| Always | double check the path |
Summary
RM dir removes empty folders, and RM dash R removes folders with everything inside. Treat RM dash RF with great respect. Next, wildcards. Working with many files at once.
Key takeaways- rmdir: empty folders
- rm -r: everything
- Respect rm -rf