When to use rm
Use rm only after checking the exact files and directory tree you intend to remove. Deletion normally bypasses a desktop trash folder; keep recoverable backups of anything important.
Syntax
rm [OPTIONS] FILE…Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Ask before deleting a file
rm -i -- ./draft.txtThe named draft is removed only after interactive confirmation.
Delete multiple selected files
rm -i -- ./one.tmp ./two.tmpEach explicitly named temporary file is considered separately, with a prompt before removal.
Delete a separate test directory
rm -ri -- ./terminalus-demoThe demo tree is traversed recursively with confirmations; inspect it first and avoid unrelated paths.
Notes and limitations
- Deletion usually bypasses the trash and cannot be undone without a backup. Check the path and wildcard expansion before running the command.
- Do not recursively delete paths formed from unchecked variables. Never substitute the filesystem root into these examples.
Common questions and troubleshooting
Can rm restore a deleted file?
No built-in undo is provided. Stop writes if recovery is needed and restore from a verified backup rather than expecting a trash folder.
Why include two hyphens before a filename?
They end option parsing, so a filename beginning with a hyphen is treated as a path rather than an option.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man rm.