Account
Categories

rm command


Definition:

The rm command is used to permanently remove files or directories from your system. Once removed, they cannot be recovered or undone. Use this command with caution.


Syntax:

rm [options] [file_or_directory]
    

[options]: -r → used to delete directories recursively

[file_or_directory]: The name of the file or folder you want to delete.


Explanation:

  • rm file1.txt → deletes a single file.
  • rm -r folder1 → deletes a folder and everything inside it.

Example 1: Remove a file

$ rm file1.txt
    

Explanation: This removes file1.txt from the current directory permanently, including its contents and name.


Example 2: Remove multiple files

$ rm file1.txt file2.txt
    

Explanation: This command deletes both file1.txt and file2.txt permanently at once.


Example 3: Remove a folder and its contents

$ rm -r myfolder
    

Explanation: Using the -r option deletes the folder myfolder along with all files and subfolders inside it permanently.


Notes:

  • Always double-check the file or folder name before running the rm command.
  • The -r option deletes directories and their contents recursively.
  • Data removed with rm cannot be recovered without backups.