Skip to main content

rm Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for removing files and directories safely with rm in Linux

The `rm` command removes files and directories in Linux. This cheatsheet covers the most common `rm` options, safe deletion patterns, recursive removal, and practical command combinations.

Basic Syntax

Core command forms for file and directory removal.

CommandDescription
rm [OPTIONS] FILE...Remove one or more files
rm -r [OPTIONS] DIRECTORY...Remove directories recursively
rm -- FILETreat argument as filename even if it starts with -
rm -i FILEPrompt before each removal

Remove Files

Common file deletion commands.

CommandDescription
rm file.txtRemove one file
rm file1 file2 file3Remove multiple files
rm *.logRemove files matching pattern
rm -- -strange-filenameRemove file named with leading -
rm -v file.txtRemove file with verbose output

Remove Directories

Delete directories and their contents.

CommandDescription
rm -r dir/Remove directory recursively
rm -rf dir/Force recursive removal without prompts
rm -r dir1 dir2Remove multiple directories
rm -r -- */Remove all directories in current path

Prompt and Safety Options

Control how aggressively rm deletes files.

CommandDescription
rm -i file.txtPrompt before each file removal
rm -I file1 file2Prompt once before deleting many files
rm --interactive=always file.txtAlways prompt
rm --interactive=once *.tmpPrompt once
rm -f file.txtIgnore nonexistent files, never prompt

Useful Patterns

Frequent real-world combinations.

CommandDescription
find . -type f -name '*.tmp' -deleteRemove matching temporary files
find . -type d -empty -deleteRemove empty directories
rm -rf -- build/ dist/Remove common build directories
rm -f -- *.bak *.oldRemove backup files quietly

Troubleshooting

Quick checks for common removal errors.

IssueCheck
Permission deniedCheck ownership and permissions; use sudo only when needed
Is a directoryAdd -r to remove directories
No such file or directoryVerify path and shell glob expansion
Cannot remove write-protected fileUse -i for prompts or -f to force
File name starts with -Use rm -- filename

Use these references for safer file management workflows.

GuideDescription
Rm Command in LinuxFull rm guide with examples
How to Find Files in Linux Using the Command LineFind and target files before deleting
Chmod Command in LinuxFix permission errors before removal
Linux Commands CheatsheetGeneral Linux command quick reference