Korean

rm — Linux basic command

Linux / Basic Linux commands / rm.html

Basic Linux commandsOriginalRegistered 2026-10-19T09:00:00+09:00

A command to delete files or directories. Permanently deletes immediately without using the trash.

Basic Information

Command Namerm
One-line IntroductionA command to delete files or directories. Permanently deletes immediately without using the trash.
Provided ByGNU coreutils (Included by default in all Linux distributions)
Official Documentationhttps://man7.org/linux/man-pages/man1/rm.1.html
Supported Operating SystemsLinux, macOS, BSD, WSL
Installation StatusIncluded by default (No separate installation required)
ClassificationBasic Linux command (Tags: file deletion, directory, Linux, basic)

What is this command?

rm is an abbreviation for remove, a command that deletes files or directories from the file system. Since Linux's rm has no trash concept and permanently deletes immediately upon execution, caution is required.

Deleting directories requires the -r (recursive) option, and the -f option can skip confirmation prompts.

What problem does it solve?

  • Deletes unnecessary files.
  • Deletes directories and all their contents.
  • Cleans up temporary files.
  • Frees up disk space.

Key Features

File Deletion

Deletes the specified file.

  • Usage Scenario: When cleaning up unnecessary files.
  • Result Obtained: The file is deleted immediately (no trash).
  • Limitations: Recovery after deletion is difficult.

Recursive Directory Deletion (-r)

Deletes a directory and all its contents within.

  • Usage Scenario: When deleting an entire project folder.
  • Result Obtained: All subdirectories and files are deleted.
  • Limitations: Very dangerous, so -rf must be used with caution.

Force Deletion (-f)

Deletes without confirmation prompts and ignores non-existent files.

  • Usage Scenario: When automating deletion in scripts.
  • Result Obtained: Deletion is performed quickly without interruption.
  • Limitations: Increases the risk of accidents.

Safe Deletion (Interactive -i)

Displays a confirmation prompt before deletion.

  • Usage Scenario: Used as a safeguard when deleting important files.
  • Result Obtained: Prevents accidental deletion.
  • Limitations: Can be cumbersome for bulk deletions.

Installation and Execution

Checking Default Inclusion

It is included by default in all Linux distributions.

which rm
rm --version

Safe Alternative (trash-cli)

By installing trash-cli with trash bin functionality, accidental deletions can be prevented.

sudo apt install trash-cli

# Delete with trash-put (moves to trash bin)
trash-put file.txt

# Check trash bin
trash-list

# Empty trash bin
trash-empty

Practical Usage Examples

Basic File Deletion

Deletes a file.

# Delete a file
rm file.txt

# Delete with confirmation prompt
rm -i important.txt
# rm: remove regular file 'important.txt'? y

# Delete multiple files
rm file1.txt file2.txt file3.txt

Directory Deletion

Deletes a directory and its contents.

# Delete an empty directory
rmdir empty-folder/

# Delete directory and all contents
rm -r project-folder/

# Force delete without confirmation (Caution!)
rm -rf temp-build/

Pattern Deletion and Safety Measures

Uses wildcards and options for safe deletion.

# Delete by specific extension
rm *.tmp

# Confirm before deletion
rm -i *.log

# Delete while ignoring non-existent files
rm -f non-existent.txt 2>/dev/null

# Confirm before deleting important directory
rm -ri /var/log/old-logs/