Bird
Raised Fist0
Linux CLIscripting~20 mins

rm (remove files) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Master of rm command
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this command?
You run the command rm -i file1.txt in a directory where file1.txt exists. What will happen?
Linux CLI
rm -i file1.txt
AThe file file1.txt is deleted immediately without any prompt.
BThe system asks for confirmation before deleting file1.txt.
CThe command shows an error because -i is not a valid option.
DThe command deletes all files in the directory.
Attempts:
2 left
💡 Hint
The -i option in rm stands for interactive mode.
💻 Command Output
intermediate
2:00remaining
What happens when you run this command?
You run rm -r myfolder where myfolder contains files and subfolders. What is the result?
Linux CLI
rm -r myfolder
AThe command deletes only files inside myfolder but not subfolders.
BOnly the empty folder myfolder is deleted; files inside remain.
CThe folder myfolder and all its contents are deleted recursively.
DThe command fails with an error because -r is not valid.
Attempts:
2 left
💡 Hint
The -r option means recursive deletion.
🔧 Debug
advanced
2:00remaining
Why does this command fail?
You run rm -f file1.txt file2.txt but get an error saying rm: cannot remove 'file2.txt': Permission denied. What is the cause?
Linux CLI
rm -f file1.txt file2.txt
Afile2.txt exists, but the error appears because the command was run without sufficient permissions.
Bfile2.txt does not exist, but -f suppresses errors so no message should appear.
Cfile2.txt does not exist, but the error appears because the shell expanded a variable incorrectly.
Dfile2.txt does not exist, but the error appears because -f was not recognized.
Attempts:
2 left
💡 Hint
The -f option forces removal and suppresses errors for missing files.
📝 Syntax
advanced
2:00remaining
Which command correctly deletes all .log files in the current directory?
Choose the correct rm command to delete all files ending with .log in the current folder.
Arm *.log
Brm -r *.log
Crm -rf *.log
Drm -f *.log
Attempts:
2 left
💡 Hint
Use -f to force deletion without prompts.
🚀 Application
expert
3:00remaining
How many files remain after running this script?
You have a folder with files: a.txt, b.txt, c.log, d.log, e.txt. You run this script:
rm -f *.txt
rm -i *.log

After confirming deletion of only c.log, how many files remain?
A1
B2
C3
D0
Attempts:
2 left
💡 Hint
First command deletes all .txt files without prompt. Second asks for confirmation on .log files.

Practice

(1/5)
1. What does the rm command do in Linux?
easy
A. Deletes files or folders permanently
B. Copies files to another location
C. Lists files in a directory
D. Creates a new directory

Solution

  1. Step 1: Understand the purpose of rm

    The rm command is used to remove files or directories permanently from the system.
  2. Step 2: Compare with other commands

    Other commands like cp copy files, ls lists files, and mkdir creates directories, so they do not delete files.
  3. Final Answer:

    Deletes files or folders permanently -> Option A
  4. Quick Check:

    rm = delete files [OK]
Hint: Remember: rm means remove files permanently [OK]
Common Mistakes:
  • Confusing rm with cp or mv
  • Thinking rm moves files instead of deleting
  • Assuming rm lists files
2. Which of the following is the correct syntax to remove a file named example.txt?
easy
A. rm -i example.txt example2.txt
B. rm -r example.txt
C. rm example.txt
D. rm -f

Solution

  1. Step 1: Identify basic rm syntax

    The basic command to remove a single file is rm filename. Here, rm example.txt removes the file named example.txt.
  2. Step 2: Understand option usage

    -r is for directories, -i asks for confirmation, and -f forces removal but needs a filename. rm example.txt is simplest and correct for a single file.
  3. Final Answer:

    rm example.txt -> Option C
  4. Quick Check:

    Basic rm syntax = rm filename [OK]
Hint: Use rm filename to delete one file simply [OK]
Common Mistakes:
  • Using -r for files instead of directories
  • Forgetting to specify filename
  • Using -f without filename
3. What will happen if you run the command rm -i file1.txt file2.txt?
medium
A. Deletes both files without asking
B. Asks for confirmation before deleting each file
C. Deletes only file1.txt and ignores file2.txt
D. Shows an error because -i cannot be used with multiple files

Solution

  1. Step 1: Understand the -i option

    The -i option makes rm ask for confirmation before deleting each file.
  2. Step 2: Apply to multiple files

    When multiple files are listed, rm -i will ask for confirmation separately for each file before deleting.
  3. Final Answer:

    Asks for confirmation before deleting each file -> Option B
  4. Quick Check:

    -i means interactive confirmation [OK]
Hint: Use -i to confirm each file deletion [OK]
Common Mistakes:
  • Thinking -i deletes without asking
  • Believing -i works only for one file
  • Assuming -i causes error with multiple files
4. You try to delete a directory named myfolder using rm myfolder but get an error. What is the correct fix?
medium
A. Use rm -r myfolder to remove the directory and its contents
B. Use rm -f myfolder to force delete the directory
C. Use rm -i myfolder to confirm deletion
D. Rename the directory before deleting

Solution

  1. Step 1: Understand why error occurs

    By default, rm cannot delete directories without the -r (recursive) option.
  2. Step 2: Use recursive option to delete directory

    Using rm -r myfolder deletes the directory and all files inside it.
  3. Final Answer:

    Use rm -r myfolder to remove the directory and its contents -> Option A
  4. Quick Check:

    Delete directory = rm -r [OK]
Hint: Use -r to delete folders recursively [OK]
Common Mistakes:
  • Trying rm without -r on directories
  • Using -f alone does not delete directories
  • Thinking -i fixes directory deletion
5. You want to safely delete all files with extension .log in your current folder, but want to confirm each deletion. Which command should you use?
hard
A. rm -f *.log
B. rm -r *.log
C. rm *.log
D. rm -i *.log

Solution

  1. Step 1: Identify the need for confirmation

    You want to confirm each file deletion, so the -i option is needed.
  2. Step 2: Use wildcard for all .log files

    The pattern *.log matches all files ending with .log in the current folder.
  3. Step 3: Combine options correctly

    Using rm -i *.log will ask for confirmation before deleting each .log file.
  4. Final Answer:

    rm -i *.log -> Option D
  5. Quick Check:

    Confirm each deletion = rm -i [OK]
Hint: Add -i to confirm each file deletion with wildcard [OK]
Common Mistakes:
  • Using rm without -i deletes without confirmation
  • Using -r unnecessarily for files
  • Using -f forces deletion without asking
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard