rm command in Linux (original) (raw)

Last Updated : 10 Jan, 2026

The rm command in Linux is used to delete files and directories permanently from the file system. It removes data immediately without sending it to any recycle bin, so deleted files cannot be recovered.

Example of Using the rm Command

Given below there are some examples to delete files by using rm command.

[Example 1]: Assume your directory contains:

Assume your directory contains the following files:

$ ls

image---2025-12-01T115507623

To Delete one file:

**Command:

rm a.txt

**Output:

image---2025-12-01T115508379

The rm command deletes the file a.txt permanently.

[Example 2]: Delete multiple files

You can delete more than one file at a time:

**Command:

rm b.txt c.txt

**Output:

image---2025-12-01T115509463

The files b.txt and c.txt are deleted successfully.

Syntax of rm Command

rm [OPTIONS] FILE...

Commonly Used Options in rm Command

Given below the options of rm command:

1. rm -i (Interactive Delete)

Prompts for confirmation before deleting each file.

rm -i file.txt

image---2025-12-01T120838224

2. rm -f (Force Delete)

Deletes files without asking for confirmation, even if write-protected.

rm -f file.txt

image---2025-12-01T120839077

3. rm -r or rm -R (Recursive Delete)

Deletes directories and all contents inside them.

rm -r foldername/

image---2025-12-01T120839841

4. rm -- (Delete File Starting with Hyphen)

Used to delete files that begin with -.

rm -- -file.txt

image---2025-12-01T120840842

Additional rm Command Options

Understanding rm Behavior

The rm command permanently deletes files and directories from the Linux filesystem without moving them to any Trash or recovery area. Once deleted, the data is typically unrecoverable unless advanced forensic recovery methods are attempted.

Difference Between rm vs rmdir

Given below are the common differences between the rm and rmdir commands.

Feature rm rmdir
Purpose Deletes files and directories Deletes only empty directories
Recursive Support Yes, using rm -r Not supported
Force Delete Yes, rm -f Not applicable
Confirmation Prompt Optional using -i No confirmation, fails if directory not empty

Example:

rm file.txt # deletes a file
rm -r folder/ # deletes folder + content
rmdir emptyfolder/ # deletes empty folder only

Safety Tips While Using rm

Follow these precautions to prevent accidental permanent deletion of important files and system directories.

  1. Double-check paths before executing to avoid deleting critical system files.
  2. Use interactive mode for safety:
    rm -i file.txt
  3. Avoid using rm -rf on system directories like:
    /, /home, /etc, /var, /boot
  4. Avoid running destructive commands as root unless required.
  5. Prefer rm -I over rm -i when deleting many files:
    rm -I *.log
  6. Keep regular system backups (especially servers).

?list=PLqM7alHXFySFc4KtwEZTANgmyJm3NqS_L