Linux command list

rm command: delete files and directories

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying rm. Nothing here can touch your real files.
user@webterm:~/project$
 

rm deletes files. There is no recycle bin and no undo. Learn what -r and -f really do, and why the combination is feared, in a browser terminal where nothing can go wrong.

Updated: 2026-09-04

Syntax

rm [options] file...

There is no way to get back what rm removes. Files are deleted where they are, not moved to a recycle bin.

Try it first

The terminal on this page holds files and directories that are safe to destroy.

$ ls
build/  draft.txt  empty/  notes.txt  README.md

$ rm draft.txt
$ ls
build/  empty/  notes.txt  README.md

rm prints nothing on success. Things disappear quietly, which is exactly why you check the target first.

The options worth knowing

OptionWhat it does
-rRemove a directory and everything inside it
-fAsk nothing, and do not complain about files that do not exist
-iAsk before each file

Removing directories

By default, directories are refused.

$ rm build
rm: cannot remove 'build': Is a directory

$ rm -r build
$ ls
empty/  notes.txt  README.md

-r removes everything inside. Do not type it while unsure what the directory contains.

For an empty directory, rmdir also works. It fails when the directory is not empty, which makes it the safer choice when "this should be empty" is an assumption you want checked.

$ rmdir empty
$ ls
notes.txt  README.md

When you actually reach for it

SituationWhat to typeWatch out for
Drop one unwanted filerm draft.txtRun ls first
Throw away build outputrm -r buildConfirm the path
Remove a supposedly empty directoryrmdir emptyFails if not empty, which is the point
Clean up inside a scriptrm -fKeeps going when the file is absent

rm -f exists for scripts. A missing target is not an error, so cleanup steps do not halt the run.

$ rm missing.txt
rm: cannot remove 'missing.txt': No such file or directory

$ rm -f missing.txt
$ echo $?
0

Things that trip people up

rm -rf is the dangerous combination. -r takes everything inside, and -f asks nothing. One mistyped character in the path can remove far more than you meant. Check where you are with pwd and what you are targeting with ls before you press Enter.

Preview wildcards with ls first. Before rm *.txt, run ls *.txt. You see exactly what would disappear. One character changes the match, so looking first is the reliable habit.

Here, nothing you delete matters. Everything runs in a virtual file system inside your browser tab and never touches your real files. If you have ever wondered what rm -rf / actually does, this is the place to find out. Reloading the page restores a clean environment.

Practise it hands-on

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.

See the course

Related commands

rmdir / mv / ls

Frequently asked questions

Can I undo an rm?
No. Files are removed straight away rather than moved to a recycle bin. Checking your location with pwd and your target with ls beforehand is the real safety net.
I tried to delete a directory and got Is a directory.
By default rm only removes files. Add -r to remove a directory and everything inside it, or use rmdir if the directory is empty.
What does -f do?
It suppresses prompts and does not complain about files that do not exist. It removes safety checks, so confirm your target before using it.
Why is rm -rf considered dangerous?
-r removes everything inside, and -f asks nothing. A single mistyped character in the path can wipe out far more than you intended.
Is it safe to try rm -rf / on this page?
Yes. Everything runs in a virtual file system inside your browser tab and cannot touch your real files. Reloading the page gives you a clean environment.
Can I be asked before each deletion?
Yes. Add -i and you are prompted one file at a time.