rm

rm linux command cheatsheet by Thamizhiniyan C S

Introduction

The rm command is used to remove files or directories.


Syntax

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


Important Flags

FlagDescription

-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

CommandDescription

Removing one file at a time.

Removing more than one file at a time.

To remove an empty directory.

To remove a directory whose name starts with a hyphen (-).

Removes a file whose name starts with a hyphen (-).

To delete a directory that contains subdirectories and files (Recursive Deletion)

To delete a directory that contains subdirectories and files (Recursive Deletion), and the -v flag to list each step of the process.

-r : Deletes all files and sub-directories recursively in the parent directory.

Asks for confirmation before removing each file (Interactive Deletion).

Use the -i option to display a prompt asking for confirmation before removing a directory.

Overrides write protection and removes the file forcefully (Force Deletion).

Remove a write-protected directory.

To avoid confirmation when deleting a directory.

Elevate command privileges to remove a write-protected directory.

Use this command to remove a write-protected directory that contains other files and directories.

Displays the version of rm currently running on the system.

Last updated