Plain rm does not delete directories. The flag -r makes it recursive, the same as cp -r: it deletes the directory and everything under it, at all levels.
text
learner@tidepool:~/shop$ rm -r archive/2025- archive
- 2025← deleted, with everything under it
- january
- week-1.txt
- february
- week-5.txt
- 2026← stays
Look before you delete
rm -r does not ask, and there is no trash. Use this order:
- Run
treeorlson the same path. - Read the output. Is this what you want to delete?
- Run
rm -ron that path. Read the line two times before you push Enter.
One space changes the line
A space splits a path into two arguments:
| You type | rm gets |
|---|---|
rm -r ~/shop/archive | One directory: ~/shop/archive |
rm -r ~/shop /archive | Two directories: ~/shop and /archive |
-f: no errors for missing items
rm -f shows no error when an item does not exist. You will see rm -rf in instructions on the internet. It deletes a full tree and shows no errors. Use it only when you are sure of the path.