rm (Remove)
Explanation
The rm command is used to remove (delete) files and directories. By default, it does not remove directories, but it can be instructed to do so recursively. Warning: Files deleted with rm are usually not recoverable, they do not go to a trash bin.
Basic Syntax
rm [OPTION]... FILE...
Common Flags and Options
| Flag | Description |
|---|---|
-r, -R, --recursive | Remove directories and their contents recursively. |
-i | Prompt before every removal. |
-f, --force | Ignore nonexistent files and arguments, never prompt. |
-v, --verbose | Explain what is being done. |
Real-world Examples
-
Remove a single file:
rm unwanted_file.txt -
Remove multiple files:
rm file1.txt file2.txt -
Remove a directory and all its contents (Use with caution!):
rm -r my_directory/ -
Force remove a directory without prompting:
rm -rf old_project/