rm

The command that deletes files, and with -r whole directory trees, permanently.

Deletion is permanent, and rm -rf with a mistaken or empty argument can wipe out whole trees.

In more detail

There is no trash can: the name is removed and the space reused. -r recurses into directories and -f never asks and ignores missing files, so rm -rf with an unquoted or empty variable is the classic way to destroy the wrong files. Quote every expansion you pass to it and check the variable is set first.

Examples

rm -r old-build/
rm -rf "$work"
rm -rf .git deletes a repository's history but leaves the working files.
rm works by unlinking: it removes the directory entry you name and decrements the inode's link count. If another hard link exists, or a process still has the file open, the data stays on disk. rm does not overwrite data, and there is no undo, so check the path before running it, especially with -r or -f.

Related terms

Taught in

References

Certification courses