files

rm

Removes files and, with -r, directory trees. Deletions are immediate and not recoverable from the shell.

rm [OPTION]... FILE...

Common flags

Flag Purpose
-r Recursively remove directories and their contents
-f Force: ignore nonexistent files, never prompt
-i Prompt before each removal
-v Verbose: print each file removed
-d Remove empty directories
--one-file-system Skip mount points when recursing (safety on -rf)

Examples

rm notes.txt

Delete a single file

rm -rf build/

Delete an entire build directory tree

rm -i *.bak

Interactively clean up backup files

rm -v -- -oddname.txt

Delete a file whose name starts with a dash using --

Gotcha

rm -rf / (or an unexpanded variable in a path like rm -rf $VAR/) can nuke a system; always quote paths and consider --one-file-system.

Related commands

← All Linux commands · Linux cheat sheet