rm command (Linux / bash / sh / zsh)
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 / option | Meaning |
|---|---|
| -r | Remove directories and their contents recursively. |
| -i | Prompt before every removal. |
| -f | Ignore missing files and suppress prompts. |
| --preserve-root | Refuse 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.
Related commands
- findWalk directory trees and select entries using tests and actions.
- rmdirRemove an empty directory or an entire directory tree.
- Remove-ItemDelete provider items such as files, directories, registry keys, and variables.
- lsList directory entries and inspect file metadata.
- cdChange the shell's current working directory.
- dirList files and subdirectories with names, dates, sizes, and attributes.
- Get-ChildItemEnumerate items and child items in filesystem, registry, and other providers.
- cdDisplay or change the current directory in Command Prompt.
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.