kmail.at
← learning

linux · difficulty ◆

rm — remove files and directories

Delete a file forever. There is no trash can and no undo.

2026-08-16 · 5 min read

$ rm

What it does

rm removes files and directories from the filesystem. Unlike a desktop trash can, rm unlinks the file immediately and permanently — the space is freed and the data is gone. With -r it descends into directories, and with -f it suppresses prompts and ignores missing files.

Why it matters

rm is how you clean up: deleting temp files, build artifacts, old logs, and unused code. It is also the command behind countless accidents, because there is no confirmation by default and no recycle bin. Knowing exactly what rm does — and what it does not do — is a core part of being safe on a Unix system.

Example

$ rm notes.txt
$ ls
notes.txt  report.md
$ rm notes.txt
$ ls
report.md

rm deletes notes.txt with no confirmation. The file is gone for good.

$ rm -rf build/
$ ls
build/  src/  package.json
$ rm -rf build/
$ ls
src/  package.json

-r recurses into the directory, -f forces without prompting. build/ and everything inside it is removed.

Common flags

-r
recursively remove directories and their contents
-f
force — ignore missing files and never prompt
-i
interactive — ask for confirmation before each removal
-v
verbose — report each file as it is removed
-d
remove empty directories (like rmdir)
--
end of options — lets you remove files whose names start with a dash

History

Origin

rm has been part of Unix since the very first editions in the early 1970s. Its name is simply the abbreviation of 'remove'. The core operation it performs — unlink — is a fundamental filesystem primitive that predates the command itself.

Fun fact

The infamous 'rm -rf /' is so dangerous that modern GNU rm refuses to operate on the root directory unless you pass --no-preserve-root. And many systems alias rm to 'rm -i' for interactive users, precisely because the default is so unforgiving.

Related commands

← all learning