rm(1)
Remove files or directories.
UbuntuDebianFedoraArch
Synopsis
rm [OPTION]... FILE...Description
Remove (delete) each specified file. By default, rm does not remove directories; use the -r or -R option to remove directory trees recursively.
If a file is write-protected, rm prompts for confirmation unless the -f (force) option is given. Be careful: deleted files cannot be recovered.
Common options
| Flag | What it does |
|---|---|
-f, --force | Force removal without prompting, even if write-protected |
-i | Prompt for confirmation before removing each file |
-I | Prompt once if removing more than 3 files or recursively |
-r, -R, --recursive | Remove directories and their contents recursively |
-d, --dir | Remove empty directories |
-v, --verbose | Print names of files as they are removed |
--interactive=WHEN | Prompt based on WHEN: never, once, or always |
Examples
Delete a single file without confirmation
rm file.txtDelete with confirmation prompt
rm -i file.txtRecursively delete a directory and all its contents without prompting
rm -rf /path/to/directoryDelete all files matching the pattern (all .log files in current directory)
rm *.logDelete multiple files and show verbose output of what's being removed
rm -v file1.txt file2.txt file3.txtDelete backup files with a single confirmation prompt instead of one per file
rm -I *.bak