Bird
0
0

What does the command ls nonexistingfile 2> error.log do in Linux?

easy📝 Conceptual Q11 of 15
Linux CLI - Pipes and Redirection
What does the command ls nonexistingfile 2> error.log do in Linux?
ASends the error message to the file error.log, replacing its content.
BAppends the error message to the file error.log.
CSends the normal output to error.log.
DDisplays the error message on the screen only.
Step-by-Step Solution
Solution:
  1. Step 1: Understand 2> redirection

    The operator 2> redirects standard error (stderr) to a file, replacing its content.
  2. Step 2: Analyze the command behavior

    The command tries to list a non-existing file, so it produces an error message sent to error.log, overwriting previous content.
  3. Final Answer:

    Sends the error message to the file error.log, replacing its content. -> Option A
  4. Quick Check:

    2> replaces error file content [OK]
Quick Trick: 2> overwrites error file, 2>> appends error [OK]
Common Mistakes:
  • Confusing 2> with 2>>
  • Thinking 2> sends normal output
  • Assuming error shows on screen

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes