The rm command

remove files or directories 10 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.

Options in the examples

-r, -R, --recursive
remove directories and their contents recursively
-f, --force
ignore nonexistent files and arguments, never prompt
-i
prompt before every removal
-I
prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection…
-v, --verbose
explain what is being done

Examples

rm file.txt
rm file1.txt file2.txt file3.txt
rm *.txt

Delete all .txt files

rm -r directory/

Delete directory and all contents

rm -i file.txt

Interactive: confirm each deletion

rm -I *.txt

Prompt once before deleting 3+ files

rm -v file.txt

Verbose: show what's being deleted

rm -rf /

NEVER run this — deletes everything!

rm ~/.bash_history

Delete history file

sudo rm oldfile.log

Delete if it's safe to lose

Lessons that use rm