rm
Quick Reference
Command Name:
rm
Category:
file management
Platform:
linux
Basic Usage:
Common Use Cases
- 1
File removal
Permanently delete files from the filesystem
- 2
Cleanup
Remove unnecessary or temporary files
- 3
Security
Securely erase sensitive data from disks
- 4
Scripting
Use in shell scripts to remove files programmatically
Syntax
rm [OPTION]... [FILE]...
Options
Option | Description |
---|---|
-f, --force | Ignore nonexistent files and arguments, never prompt for confirmation |
-i | Prompt before every removal |
-I | Prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes |
--interactive[=WHEN] | Prompt according to WHEN: never, once (-I), or always (-i); without WHEN, prompt always |
--one-file-system | When removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument |
--no-preserve-root | Do not treat '/' specially |
--preserve-root | Do not remove '/' (default) |
-r, -R, --recursive | Remove directories and their contents recursively |
-d, --dir | Remove empty directories |
-v, --verbose | Explain what is being done |
--help | Display help information and exit |
--version | Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the rm
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
rm file.txt
Deletes a single file named file.txt from the current directory. This is the most basic usage of the rm command.
rm file1.txt file2.txt file3.txt
Deletes multiple files at once. This example removes three files named file1.txt, file2.txt, and file3.txt from the current directory.
rm -i important.txt
Removes a file with confirmation. The -i (interactive) option prompts for confirmation before removing each file, which is useful for important files to prevent accidental deletion.
rm -f locked.txt
Forces removal without confirmation. The -f (force) option ignores nonexistent files and never prompts for confirmation, which is useful for removing write-protected files without being asked.
Advanced Examples:
rm -r directory/
Removes a directory and its contents recursively. The -r (recursive) option is required when deleting directories, as it tells rm to remove the directory and all files and subdirectories within it.
rm -rf temp/
Forces recursive removal of a directory. Combining -r (recursive) with -f (force) removes directories and their contents without confirmation, even if they contain write-protected files. Use with extreme caution!