Skip to main content

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​

FlagDescription
-r, -R, --recursiveRemove directories and their contents recursively.
-iPrompt before every removal.
-f, --forceIgnore nonexistent files and arguments, never prompt.
-v, --verboseExplain what is being done.

Real-world Examples​

  1. Remove a single file:

    rm unwanted_file.txt
  2. Remove multiple files:

    rm file1.txt file2.txt
  3. Remove a directory and all its contents (Use with caution!):

    rm -r my_directory/
  4. Force remove a directory without prompting:

    rm -rf old_project/