Skip to content
English
Level 1: Your First 30 Minutes in the Terminal
Lesson 9 · +10 XP

Deleting (carefully)

You need to know up front: rm does not put things in the trash. It deletes them immediately and permanently. There is no recycle bin to fish files out of. There is no “undo.” There is no “are you sure?” — not by default.

This is not a scare tactic. It’s the single most important fact about the terminal, and every developer alive has been bitten by it at least once. Read this lesson all the way through before you run a single command from it.

The basic case

To delete a file:

echo "throwaway" > junk.txt
rm junk.txt

Run ls. junk.txt is gone. The terminal said nothing — silence here means success.

You can delete several at once:

touch a.txt b.txt c.txt
rm a.txt b.txt c.txt

All three are gone, instantly.

Deleting a folder

Try this on an empty folder:

mkdir empty-folder
rm empty-folder

You’ll get:

rm: empty-folder: is a directory

By default, rm refuses to delete folders. Just like with cp, the terminal wants you to be explicit about touching whole trees of files.

The flag is -r (recursive — folder and everything inside):

rm -r empty-folder

Gone. And if the folder had things in it, those would be gone too. All of them. rm -r on a folder is exactly as destructive as it sounds.

The flag that should make you nervous

You’ll see this on the internet a lot:

rm -rf <folder>

The -f means force — don’t ask, don’t complain about missing files, just delete. Combined with -r, it’s the “delete everything, no matter what” command. It’s useful. It is also the single most famous way to destroy a computer.

The legendary disaster is:

rm -rf /

That’s “delete everything under /” — which on a Mac or Linux machine is the entire file system. Modern systems refuse this exact command, but typos like rm -rf / mystuff (note the extra space after /) have nuked production servers and personal laptops alike.

Rule of thumb: never run rm -rf without re-reading the path twice. Out loud, if you’re tired.

How to be careful without being scared

Three habits keep rm from biting you:

1. Use Tab completion. If Tab doesn’t expand the name, the file doesn’t exist — and you shouldn’t be deleting it.

2. Use -i until it’s muscle memory. The -i flag (interactive) makes rm ask before each delete:

rm -i important.txt

You’ll type y and press Enter to confirm. Slow? Yes. Worth it? Also yes — at least until deleting feels routine.

3. ls first, rm second. Run ls (or ls -la) to see what you’re about to delete. Then delete. Two seconds of looking has saved more files than every backup tool combined.

The safer alternative

If rm makes you sweat, install trash-cli (or trash on macOS via Homebrew). It moves files to your system’s actual trash instead of deleting them, so you can fish them back out. Worth doing while you’re learning.

What you’ve learned

  • rm <file> — delete a file. Immediately. Permanently.
  • rm -r <folder> — delete a folder and everything inside.
  • rm -i — ask before each delete (use it liberally while you’re new).
  • rm -rf — the “no questions asked” version. Type with respect.

You now know all five verbs of file management in the terminal: list, make, copy, move, delete. The last lesson stitches them together into a real project.