The rm -r command removes directories and their contents recursively. It deletes the folder and everything inside it, including subfolders and files.
Click to reveal answer
beginner
Why should you be careful when using rm -r?
Because rm -r deletes everything inside the directory without asking for confirmation by default. This can cause loss of important files if used carelessly.
Click to reveal answer
intermediate
How can you make rm -r ask for confirmation before deleting each file?
You can add the -i option like rm -ri directory_name. This makes the command ask you to confirm before deleting each file or folder.
Click to reveal answer
intermediate
What is the difference between rm -r and rm -rf?
rm -r removes directories recursively and may ask for confirmation if files are write-protected. rm -rf forces removal without any prompts, even for write-protected files.
Click to reveal answer
beginner
Can rm -r delete hidden files and folders?
Yes, rm -r deletes all files and folders inside the directory, including hidden ones (those starting with a dot).
Click to reveal answer
What does the -r option do in the rm command?
ARemoves directories and their contents recursively
BRenames files
CReads file contents
DRestores deleted files
✗ Incorrect
-r means recursive removal of directories and their contents.
Which command will delete a directory named docs and all its contents without asking for confirmation?
Arm docs
Brm -r docs
Crm -i docs
Drm -rf docs
✗ Incorrect
rm -rf docs forces recursive deletion without prompts.
If you want to be asked before deleting each file inside a directory, which command should you use?
Arm -r directory
Brm -rf directory
Crm -ri directory
Drm directory
✗ Incorrect
-i option makes rm interactive, asking for confirmation.
Does rm -r delete hidden files inside directories?
ANo, it skips hidden files
BYes, it deletes hidden files too
COnly if you add <code>-h</code>
DOnly if files are not write-protected
✗ Incorrect
rm -r deletes all files including hidden ones.
What happens if you run rm -r /important_folder by mistake?
AThe folder and all its contents will be deleted
BThe folder will be renamed
CNothing happens, it just lists files
DThe folder is backed up automatically
✗ Incorrect
The command deletes the folder and everything inside it.
Explain what the rm -r command does and why it should be used carefully.
Think about deleting a folder with many files inside.
You got /4 concepts.
Describe how to safely delete a directory using rm -r with confirmation prompts.
Add an option to make the command interactive.
You got /4 concepts.
Practice
(1/5)
1. What does the command rm -r foldername do in Linux?
easy
A. Moves the folder named 'foldername' to the trash bin.
B. Deletes the folder named 'foldername' and all its contents recursively.
C. Renames the folder named 'foldername' to 'r'.
D. Creates a new folder named 'foldername'.
Solution
Step 1: Understand the rm command
The rm command is used to remove files or directories in Linux.
Step 2: Understand the -r option
The -r option means recursive, so it deletes the folder and everything inside it.
Final Answer:
Deletes the folder named 'foldername' and all its contents recursively. -> Option B
Quick Check:
rm -r deletes folders recursively = C [OK]
Hint: Remember: rm -r removes folders and all inside them [OK]
Common Mistakes:
Thinking rm -r moves files to trash
Confusing rm -r with renaming
Assuming rm -r only deletes empty folders
2. Which of the following is the correct syntax to remove a directory named data and all its contents?
easy
A. rm data -r
B. rmdir -r data
C. rm -r data
D. rm -f data
Solution
Step 1: Check the position of the -r option
The correct syntax places options before the target, so rm -r data is valid.
Step 2: Validate other options
rm data -r is incorrect syntax; rm -f data does not recurse on directories; rmdir -r data is invalid because rmdir does not support -r.
Final Answer:
rm -r data -> Option C
Quick Check:
Options come before target in rm command = D [OK]
Hint: Options go before folder name in rm command [OK]