Account
Categories

rm command


Definition:

When you run the rm command in your terminal, it permanently removes files or directories from the OS, which means they are deleted and cannot be recovered/ undone.

Syntax:

Rm [options] [file or directory]

[options] → -r( for deleting directories)

[file or directory] → You should type in here the file or folder name that you want to remove.

Explanation:

rm file1.txt → deletes a single file

rm -r folder1 → deletes a folder and everything inside it

Examples:

1. Remove a file :

Command:

rm file1.txt

Explanation:

  • It deletes file1.txt from the current directory.
  • The file has been permanently deleted, along with its contents and name.

2. Remove multiple files at once:

Command:

rm file1.txt file2.txt

Explanation:

  • When you run this command with more than one file, it permanently deletes all the specified files.

3. Remove a folder and everything inside it:

Command:

rm -r myfolder

Explanation:

  • When you use the -r option, it permanently deletes the folder (for example, myfolder) along with all files and subfolders inside it.

Notes:

  • When you use this command, verify the file or folder name carefully before running the rm command.
  • When you use the -r option, it deletes the file/ folder and everything inside it recursively. You must be very careful before running it.