rm -r: The Danger Zone
rm -r (recursive) deletes a directory and everything inside it. Combined with -f (force), rm -rf is one of the most powerful — and dangerous — commands in the terminal.
Deleting a directory
rm -r old-folder/
This removes old-folder/ and all of its contents: every file, every subdirectory, everything. There is no trash can. There is no undo.
The flags
| Flag | Meaning |
|---|---|
-r | Recursive — required for directories |
-f | Force — skip confirmation, ignore missing files |
-rf | Both combined — the common form |
The notorious command
rm -rf directory-name
This is a legitimate and frequently-used command. It appears in deployment scripts, CI pipelines, and Docker builds every day.
The reason it has a reputation: on a real machine, a typo can be catastrophic.
# Intended
rm -rf ./build
# Typo: space after the dot
rm -rf . /build # deletes your entire current directory
The space in rm -rf . /build causes the shell to interpret . (current directory) and /build as two separate targets. The current directory and everything in it gets deleted. This mistake has destroyed production servers.
In the playground it's safe. On your machine, it's not.
Safe practices
- Double-check the path before pressing Enter.
- Use
lsfirst to confirm what's there:ls old-folder/thenrm -r old-folder/. - Prefer relative paths so you stay in scope.
rm -rf build/is safer thanrm -rf /home/user/project/build/(less to mistype). - Add
-iin practice to prompt before each deletion:rm -ri old-folder/.
Practice
Remove the danger directory and everything inside it using rm -r.