rm command in Linux

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.

  • rm deletes files permanently from the system.
  • It does not move deleted data to the Trash/Recycle Bin.
  • By default, rm does not delete directories.
  • Options like -r, -f, and -i extend its functionality.

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

  • -v (verbose): Displays details of each file as it is deleted.
  • -d (delete empty directory): Removes only empty directories.
  • -rf (recursive + force): Deletes directories and files recursively without any confirmation.
  • --preserve-root (default safety option): Prevents accidental deletion of the root (/) directory.
  • --no-preserve-root (unsafe option): Allows removal of the root directory (highly dangerous and not recommended).
  • -i (interactive mode): Prompts the user once before deleting multiple files.
  • --help: Displays the help manual with usage information and available options.
  • --one-file-system: Ensures deletion stays within the same filesystem and avoids mounted sub-directories.

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.

  • Deleted files are not stored in any recycle bin or temporary location.
  • rm performs immediate removal, not reversible deletion.
  • Standard undelete tools cannot recover data removed by rm.
  • Recovery is only theoretically possible using specialized forensic tools-and not guaranteed.

Difference Between rm vs rmdir

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

Featurermrmdir
PurposeDeletes files and directoriesDeletes only empty directories
Recursive SupportYes, using rm -rNot supported
Force DeleteYes, rm -fNot applicable
Confirmation PromptOptional using -iNo confirmation, fails if directory not empty
  • rm: removes files instantly and can remove folders with -r
  • rmdir: removes folders only if they contain no files

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

Comment

Explore