Home·Terminal commands

rm

Files and directories

Usage

rm -rf [path]

Deletes files for good — there is no trash can, and one stray space in rm -rf erases something you did not mean.

Common flags

FlagMeaning
-rDescend into directories and delete what is inside
-fNever prompt, and say nothing about files that are missing
-iAsk before every single removal
-dRemove an empty directory without -r
-vPrint each name as it goes
-IGNU: ask once before removing more than three files
-PmacOS: overwrite the file before unlinking it

Examples

rm -rf build

Deletes the build directory and everything under it.

rm -i *.log

Asks about each log file first.

rm -- -weird

Deletes a file whose name starts with a dash.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does rm do?

Deletes files for good — there is no trash can, and one stray space in rm -rf erases something you did not mean.

Q. How do I type it?

rm -rf [path] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man rm. This command sits under Files and directories.

Related commands

man page: man rm