rm, short for "remove," is a shell command for removing files (including special files such as directories) from the file system. Originally developed for Unix, it is now available on Unix-like systems and other platforms including KolibriOS, IBM i, the EFI shell, and Windows (via UnxUtils).
History
The rm command was originally written by Ken Thompson and Dennis Ritchie at AT&T Bell Laboratories and first released on November 3, 1971. The version in GNU Core Utilities was written by Paul Rubin, David MacKenzie, Richard Stallman, and Jim Meyering. On some early Unix versions, rm would remove directories if they were empty; this behavior can still be obtained with the -d flag in certain implementations.
Operation
rm does not necessarily delete a file's data immediately. Instead, it unlinks the file — removing a hard link via the unlink() system call. If a file has multiple hard links and fewer than all are removed, the file remains accessible through its other links. When a file's only link is removed, the file is deleted and its storage space is released for other use. The data may remain on disk until overwritten and can sometimes be recovered using specialized tools.
Common Options
| Option | Description |
|---|---|
-r |
Recursive; removes directories and their contents |
-i |
Interactive; prompts the user to confirm each deletion |
-f |
Force; ignores non-existent files and overrides confirmation prompts |
-v |
Verbose; logs status of each operation |
-d |
Removes empty directories |
--preserve-root |
Refuses to remove the root directory (default in GNU Coreutils ≥ 6.4) |
--no-preserve-root |
Overrides root protection to allow removing the root directory |
Safety
Because rm does not move files to a recycle bin or trash, accidental deletions can result in permanent data loss. Several safety mechanisms exist:
- Permission model: Removing a file requires write and execute permissions on the containing directory, not on the file itself.
- Sticky bit: If a directory has the sticky bit set, only the file's owner (or the superuser) can remove files within it.
- Interactive aliases: Users often create
alias rm="rm -i"to force interactive confirmation before each deletion. - Root protection: Modern implementations refuse to execute
rm -rf /unless the--no-preserve-rootflag is explicitly provided, even by the superuser.
Limitations
The GNU Core Utilities implementation limits command-line arguments to 32 times the kernel's page size (typically 128 KB on systems with 4 KB pages). Exceeding this limit results in an error.
Notable Incidents
Commands such as rm -rf * and rm -rf / are cited in anecdotes about catastrophic accidental data loss, including an incident during the production of the film Toy Story 2 where significant portions of the film's data were accidentally deleted.
See Also
rmdir— command for removing empty directoriesdel— the analogous command in MS-DOS, OS/2, and Windows Command Promptshredandsrm— commands that overwrite file data before deletionunlink— command that removes a single file