Skip to content
zero2vibecodelearn vibe coding
Level 2 · Working with content 6 min Reviewed by the author · Aug 4, 2026

Deleting: rm and the missing trash can

`rm` deletes a file and `rm -r` deletes a folder. Neither of them uses a trash can — what you delete here is gone.

Level 2 · 0 / 4 lessons0%

Time to be blunt about this one.

There is no trash can

When you delete a file in a graphical file manager, it goes to the trash. You can change your mind.

The terminal has no such thing. rm removes the file, and there is nowhere to look for it afterwards.

rm draft.txt

Silent, instant, permanent. No confirmation, no “are you sure”, no undo.

Important

This is not a scare tactic and it is not a simulator quirk. On a real machine, a file removed with rm is genuinely unrecoverable by any normal means. Professionals lose work to this every year.

Quick check

You delete a file with rm and immediately regret it. Where do you look for it?

Deleting a folder: -r

Point rm at a folder and it refuses:

rm temp
rm: cannot remove 'temp': Is a directory

That refusal is deliberate. A folder can hold hundreds of files, and deleting it deletes all of them. So rm makes you ask again, explicitly, with -r for recursive:

rm -r temp

Now temp and everything inside it is gone, at every depth.

Quick check

Why does rm need -r for a folder when it does not for a file?

The flag combination to slow down for

-f stands for force. It tells rm to stop objecting — including about files that do not exist, and about things it would normally hesitate over.

Put them together and you get rm -rf, which means: delete this folder and everything in it, recursively, and do not complain about anything.

It is a legitimate command. Cleaning a build folder is exactly what it is for. What makes it dangerous is that it removes every guard rail at the same moment you are handing it a — and if that path is wrong, nothing will stop you.

Important

The infamous one is rm -rf /, which aims the whole thing at the root of the disk. This simulator will refuse it and tell you off. Your laptop will not be as friendly.

Quick check

An AI agent proposes `rm -rf node_modules`. Is that reasonable?

The habit that actually protects you

Not fear. A two-second routine:

  1. ls the folder, so you can see what you are about to delete.
  2. Read the path in your rm command out loud, once.
  3. Then run it.

Most rm accidents are not typos in the command — they are the right command aimed at the wrong folder, run by someone who did not check where they were standing. pwd and ls are the cure.

Tip

On a real machine there is a better default: put things in a trash folder of your own with mv, and empty it when you are sure. mv is reversible; rm is not.

Try it

The scratch folder has one file to keep, one to delete, and a whole folder of rubbish.

  1. ls — look before you delete.
  2. rm draft.txt — remove the file.
  3. rm -r temp — remove the folder and its contents.
  4. ls — confirm that old-notes.txt is still there.

Step 4 matters as much as steps 2 and 3. Deleting the right things is only half the job; the other half is confirming you did not take anything else with them.

Check your understanding

Answered 0/3
Mode:

Where does a file go when you delete it with `rm`?

Why does `rm` refuse to delete a folder without `-r`?

What does `-f` add to `rm`?

Finish the task in the terminal and answer the questions to complete the lesson.

📝 My notes

Saved automatically in this browser · shows up on the Notes page.

Task

Delete draft.txt and the whole temp folder. Leave old-notes.txt alone.

Tab complete · history · Ctrl+L clear · help commands

  • Not done: Delete the file draft.txt
  • Not done: Delete the folder temp with -r
  • Done: old-notes.txt survived

Lesson Q&A

Where does a file go when you delete it with `rm`?

The desktop trash can belongs to the file manager, not the terminal. rm unlinks the file and that is the end of it.

Why does `rm` refuse to delete a folder without `-r`?

The extra flag is a deliberate speed bump on a much bigger action.

What does `-f` add to `rm`?

f is for force. It silences the objections, which is exactly why -rf is the flag combination to slow down for.

You delete a file with rm and immediately regret it. Where do you look for it?

The trash can is a feature of the graphical file manager. rm goes around it entirely.

Why does rm need -r for a folder when it does not for a file?

The flag is a speed bump proportional to the damage. One file versus a whole subtree is not the same decision.

An AI agent proposes `rm -rf node_modules`. Is that reasonable?

The flag is not the problem, the target is. node_modules is regenerated by npm install. The same command aimed at src would be a disaster.

Move between lessons with · search with ⌘K