Linux Basic Commands

6. rm

rm stands for remove.
It is used to delete files and directories in Linux.

⚠️ Be careful: Once deleted with rm, files cannot be recovered easily.


🔹 Basic Syntax:

rm [options] [file_or_directory]

🔹 Examples:

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. Remove an empty directory (use -d)

rm -d empty_folder

👉 Deletes an empty folder.


4. Remove a non-empty directory (use -r or -rf)

rm -r myfolder

👉 Recursively deletes the folder and everything inside it.

Use -f to force delete (no confirmation):

rm -rf myfolder

⚠️ Dangerous! This will delete everything inside without asking.


🔹 Practice Example:

mkdir testfolder
touch testfolder/file1.txt
rm -r testfolder

👉 This creates a folder, adds a file, and then deletes the whole folder.

Try with Linux Practice