$linuxjunkies
>

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

FlagWhat it does
-f, --forceForce removal without prompting, even if write-protected
-iPrompt for confirmation before removing each file
-IPrompt once if removing more than 3 files or recursively
-r, -R, --recursiveRemove directories and their contents recursively
-d, --dirRemove empty directories
-v, --verbosePrint names of files as they are removed
--interactive=WHENPrompt based on WHEN: never, once, or always

Examples

Delete a single file without confirmation

rm file.txt

Delete with confirmation prompt

rm -i file.txt

Recursively delete a directory and all its contents without prompting

rm -rf /path/to/directory

Delete all files matching the pattern (all .log files in current directory)

rm *.log

Delete multiple files and show verbose output of what's being removed

rm -v file1.txt file2.txt file3.txt

Delete backup files with a single confirmation prompt instead of one per file

rm -I *.bak

Related commands