rm removes files — immediately, permanently, and without asking. There is no trash can on a typical Linux system, which makes rm the most powerful command in this series and the one that deserves the most respect.
Everyday removal #
$ rm notes.txt
$ rm old/*.log
$ rm -r old-builds/
Plain rm handles files. -r (recursive) is required for directories and their contents.
The flags #
| Flag | Behaviour |
|---|---|
-r | Recurse into directories |
-f | Force: ignore missing files, suppress prompts |
-i | Prompt before every removal |
-I | Prompt once before removing more than three files |
-v | Print each file as it is removed |
The two-step habit is the safest pattern: list what a glob matches, then remove it.
$ ls old/*.log
$ rm old/*.log
When age matters #
rm does not care about recency, but find does — and pairing them is the classic cleanup:
$ find /var/log/myapp -name "*.log" -mtime +30 -delete
The -delete form is safer than piping into rm because find only acts on paths its tests matched. See find for the full tour.
Accidental deletion is a backup problem, not a shell problem: snapshots, git, or a nightly tar archive are what stand between a typo and data loss. Before removing, it helps to see exactly what is there with ls. More in the journal.
