---
description: rm linux command cheatsheet by Thamizhiniyan C S
---

# rm

## Introduction

The `rm` command is used to remove files or directories.

***

## Syntax

`rm [OPTION]... [FILE]...`

***

## Important Flags

| Flag        | Description                                                                      |
| ----------- | -------------------------------------------------------------------------------- |
| `-f`        | Forces the removal of all files or directories.                                  |
| `-i`        | Prompts for confirmation before removing.                                        |
| `-I`        | Prompts once before removing more than three files or when removing recursively. |
| `-r`        | Removes directories and their content recursively.                               |
| `-d`        | Removes empty directories.                                                       |
| `-v`        | Provides a verbose output.                                                       |
| `--help`    | Displays the help text.                                                          |
| `--version` | Displays the command version.                                                    |

***

## Examples

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm a.txt
</code></pre></td><td>Removing one file at a time.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm b.txt c.txt
</code></pre></td><td>Removing more than one file at a time.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -d Example
</code></pre></td><td>To remove an empty directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -- [directory name]
</code></pre></td><td>To remove a directory whose name starts with a hyphen (-).</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -- -file.txt
</code></pre></td><td>Removes a file whose name starts with a hyphen (-).</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -r Example
</code></pre></td><td>To delete a directory that contains subdirectories and files (Recursive Deletion)</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -r -v Example
</code></pre></td><td>To delete a directory that contains subdirectories and files (Recursive Deletion), and the -v flag to list each step of the process.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -r *
</code></pre></td><td>-r : Deletes all files and sub-directories recursively in the parent directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -i d.txt
</code></pre></td><td>Asks for confirmation before removing each file (Interactive Deletion).</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -d -i Example
</code></pre></td><td>Use the -i option to display a prompt asking for confirmation before removing a directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -f e.txt
</code></pre></td><td>Overrides write protection and removes the file forcefully (Force Deletion).</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -d Example
</code></pre></td><td>Remove a write-protected directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -d -f Example
</code></pre></td><td>To avoid confirmation when deleting a directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo rm -d Example
</code></pre></td><td>Elevate command privileges to remove a write-protected directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm -rf 
</code></pre></td><td>Use this command to remove a write-protected directory that contains other files and directories.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">rm --version
</code></pre></td><td>Displays the version of rm currently running on the system.</td></tr></tbody></table>
