In Unix/Linux, which rm option enables interactive mode so that the command prompts for confirmation before deleting each file?

Difficulty: Easy

Correct Answer: -i

Explanation:


Introduction / Context:
File deletion on Unix/Linux is immediate and typically irreversible without backups. To reduce risk, the rm command provides an interactive mode that asks for confirmation for each item, making accidental mass deletions less likely—especially helpful when using wildcards.


Given Data / Assumptions:

  • You are considering a deletion affecting multiple files.
  • Safety and confirmation are preferred over speed.
  • You are using a POSIX-like shell environment.


Concept / Approach:
The -i option activates interactive prompts in rm, asking 'remove regular file 'name'?'. Some distributions also offer the more aggressive -I (capital i) to prompt once if the operation is large. The -r (or -R) option is recursive deletion for directories; it does not prompt by itself. Other flags shown (-x, -1) are not standard rm options for interactivity.


Step-by-Step Solution:

Preview with ls to see intended targets.Delete interactively: rm -i *.logAnswer y/n for each file as prompted.For directories: rm -ir project/ to combine recursion with prompts.


Verification / Alternative check:
Run a dry run using echo: echo rm -i *.log to verify expansion. Then perform rm -i and confirm that prompts appear. Use aliases (for example, alias rm='rm -i') as a safety net if desired.


Why Other Options Are Wrong:

  • -r: Enables recursion; it does not prompt unless combined with -i.
  • -x: Not a standard rm option for interactivity.
  • -1: Not a valid rm option; likely a distractor.
  • None of the above: Incorrect because -i is the correct interactive switch.


Common Pitfalls:
Relying solely on -i but using sudo in scripts (aliases may be bypassed), or forgetting that rm -rf will remove without prompting—use with extreme caution.


Final Answer:
-i

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion