Glossary

rm

rm deletes files. On Unix there is no built-in recycle bin: once rm returns, the directory entry is gone and the disk blocks are free to be reused. Recovery is difficult and not guaranteed.

rm file.txt                      # delete a file
rm -i file.txt                   # prompt before each delete
rm -f file.txt                   # force: no prompt, ignore missing
rm -r directory/                 # recurse: delete a tree
rm -rf /tmp/build                # recursive + force (use with care)

rm -rf is notorious: a stray space or shell expansion (rm -rf $VAR/ where VAR is unset) can wipe out everything under /. Modern GNU rm refuses to operate on / by default, but habits like quoting variables and using -- to terminate options remain essential.

Related terms: cp, mv, trash

Discussed in:

Textbook of Linux — Learn Linux on iPhone — Download on the App Store