Skip to main content

Command referencerm

rm command (Linux / bash / sh / zsh)

LinuxbashshzshfilebeginnerDestructive — use carefully

What it does

Remove files and directory trees permanently. When people search for the rm command linux safely, they usually want rm's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Remove files and directory trees permanently.

Syntax

rm [OPTION]... FILE...

Common options

Flag / optionMeaning
-rRemove directories and their contents recursively.
-iPrompt before every removal.
-fIgnore missing files and suppress prompts.
--preserve-rootRefuse recursive removal of root.

Practical examples

Remove one file

rm old-report.txt

Deletes the named file.

Review then remove

rm -i *.tmp

Prompts before deleting each matching temporary file.

Remove empty tree

rm -r empty-project/

Recursively removes the selected directory tree.

Linux ↔ Windows equivalent

Closest match: Remove-Item (Windows / PowerShell). Delete provider items such as files, directories, registry keys, and variables.

Common mistakes

  • Danger: combining `-r` and `-f` can erase an entire tree without confirmation; verify the expanded path first.
  • Running rm with an unset variable or overly broad wildcard.
  • Expecting deleted files to move to a desktop trash folder.

FAQ

What does rm do in Linux?

Remove files and directory trees permanently.

How do I use rm from the terminal?

Start with `rm [OPTION]... FILE...`, then choose only the options needed for the task.

What is a practical rm example?

Try `rm old-report.txt` — Deletes the named file.

Can I use rm in a shell script?

Yes. rm works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.