How to Delete Files and Directories in Linux (rm)
rm permanently removes files or directories — there is no built-in trash or undo.
Published September 30, 2026
rm deletes files, and rm -r deletes directories recursively. There is no recycle bin, so deleted files are gone, which makes rm one of the most dangerous commands.
How it works
Use -i to confirm each deletion and -f to force without prompts. rmdir removes only empty directories.
Always double-check the path, especially with variables and wildcards.
Try it
rm notes.txt
rm -ri old-folder
rm: remove directory 'old-folder'? y
Practical examples
Delete a file
rm file.txtDelete a directory
rm -r build/Preview with ls first
ls build/*.tmp
rm build/*.tmpSafer deletion
trash-put file.txt # from trash-cliCommon mistakes
- rm -rf with an unset variable (rm -rf $DIR/).
- Running rm -rf / or with a stray space (rm -rf / tmp).
- No backups.
Key takeaways
- No undo for rm.
- Preview paths first.
- Consider trash tools.
FAQ
Can I recover deleted files?
Rarely; stop writing to the disk and use recovery tools.
rm vs rmdir?
rmdir only removes empty directories.