Removing Things, and the Command That Deserves Respect

The commands.

rm file removes a file.

rmdir dir removes a directory, but only if it is empty.

rm -r dir removes a directory and everything inside it.

rm -f ignores anything that is not there rather than complaining.

✦ There is no recycle bin

rm does not move a file to a trash folder. It unlinks it, and it is gone. No undo, no confirmation, no undelete. This is not a design flaw, it is what makes the shell usable for scripting, but it means rm deserves a moment of attention every time you use it, especially with -r.

Why rm -rf is the famous one. Combined, -r recurses into directories and -f suppresses complaints. It is genuinely the right tool for deleting a build directory. It is also the command that erases a project when the path is slightly wrong.

The habit that protects you is simple: run ls on the path first. If ls thepath shows what you expected to delete, then rm -r thepath will delete what you expected.

SANKOFA SANDBOX
learner:~$

This sandbox is the one place you can do this without consequence. Reset brings everything back.

Try it → Run `rm logs` and read why it refuses. Then run `ls logs` to check what is in there, then `rm -r logs` and `ls` to confirm. Then hit Reset and get it all back.

◈ Graded Task

Scaffold a new project and clean up after yourself. Create a directory called writing containing a drafts subdirectory, both in one command. Put a file called ideas.md inside drafts containing the single line Start here. Then delete the entire map project, which is no longer needed.

Checked against the filesystem you leave behind, not the commands you type, so any route that gets the job done counts. 5 visible and 2 hidden checks.

SANKOFA SANDBOX
learner:~$

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Practice Test →
← Back