Course outline · 0% complete

0/29 lessons0%

Course overview →

Deleting safely: rm

lesson 3-3 · ~9 min · 9/29

rm is forever

rm file removes a file. Burn this in now: there is no trash can. The file doesn't go somewhere recoverable, it's gone. That's why lesson 2-2 stressed tab completion: completing a filename means you delete the file you meant, not a typo-neighbor.

The family:

  • rm file.txt: delete a file.
  • rm -i file.txt: ask "are you sure?" before each deletion (i for interactive).
  • rmdir emptydir: delete a directory, but only if it's already empty.
  • rm -r dir: delete a directory recursively, everything inside included.
  • rm -rf dir: same, but -f (force) skips every confirmation and warning.

Treat rm -rf like a chainsaw. Never run it on a path you haven't just verified with ls, and never, ever on /.

Code exercise · bash

Run it. We delete one file (ls proves keep.txt survived), then remove a whole directory tree with rm -r.

Quiz

Which flag makes rm ask for confirmation before each file it deletes?

A pre-delete checklist

Before any rm -r, professionals do a two-second ritual:

  1. ls the-target to see exactly what's about to disappear.
  2. Read the command back once. Especially check for stray spaces: rm -r stuff / deletes stuff and then starts on the root /, while rm -r stuff/ deletes only stuff.

That one space has destroyed real production servers. The habit costs nothing.

The safe-delete ritual, hands on (simulated). The directory old-project needs to go.

Step 1/3: Before deleting anything, look inside old-project.

$ 

Problem

Write the command that deletes the directory `old-project` and everything inside it (no confirmation prompts needed).