UnixDroid

Files · Linux command

rm command in Linux

What does rm do?

rm permanently deletes files. With -r it deletes folders and everything in them. Linux has no recycle bin, so deleted files are gone.

rm [options] file…

Most useful options

OptionWhat it does
-rdelete folders recursively
-fforce: no questions, no errors
-iask before every file
-vshow what is deleted

rm examples

$ rm old.txt Try it ›

delete one file

$ rm -i *.tmp Try it ›

delete .tmp files, asking each time

$ rm -r build/ Try it ›

delete a folder

In security work

Never run rm -rf with a variable that might be empty (rm -rf $DIR/) — it can wipe the whole system.

Questions about rm

Can I recover a file deleted with rm?

Not easily — there is no trash. Forensic tools can sometimes recover data, but take backups instead.