Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

rm Command Guide for Moving and Renaming Files

This guide explains how to use the rm (remove) command to delete files and directories safely in Unix-like systems.


What is rm, and Why Use It?

The rm command is used to delete files or directories permanently from the file system.

Why Learn rm?

  • Free up space by removing unnecessary files
  • Clean up scripts, logs, or temporary data
  • Essential for file management in any Unix/Linux system

⚠️ Warning: rm does not move files to the trash — it deletes them immediately. Use it with care.


1. Remove a Single File

rm file.txt
  • Deletes file.txt from the current directory.

2. Remove Multiple Files

rm file1.txt file2.txt
  • Deletes both files at once.

3. Prompt Before Deleting (Safer)

rm -i file.txt
  • -i (interactive) asks for confirmation before each deletion.

4. Remove a Directory and Its Contents

rm -r my_folder/
  • -r (recursive) deletes the folder and all files/subfolders inside it.

5. Force Delete Without Prompt

rm -rf some_folder/
  • -f (force) skips confirmation.
  • -r ensures folders and their contents are deleted.

⚠️ Only use rm -rf when you're absolutely sure — it cannot be undone.


6. Verbose Mode (Show What’s Being Deleted)

rm -v file.txt
  • -v (verbose) prints each file as it's removed.

Remove Cheatsheet

CommandDescription
rm file.txtDelete a single file
rm file1.txt file2.txtDelete multiple files
rm -i file.txtConfirm before deletion
rm -r folder/Delete folder and contents recursively
rm -rf folder/Force delete a folder (no confirmation)
rm -v file.txtShow file(s) as they are deleted

For safer usage, many users create an alias like alias rm='rm -i' to avoid accidents. Always double-check what you're removing — especially with wildcards like * or recursive flags.