Bird
0
0

You want to discard both standard output and error from a command, but your script still shows errors. What is wrong with this command?

medium📝 Debug Q14 of 15
Linux CLI - Pipes and Redirection
You want to discard both standard output and error from a command, but your script still shows errors. What is wrong with this command?
command > /dev/null 2>1
AThe command will only discard standard output
BThe command does not discard any output
CThe output is redirected to the wrong file
DThe error redirection syntax is incorrect; it should be <code>2>&1</code>
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the error redirection syntax

    The command uses '2>1' which redirects standard error to a file named '1', not to standard output.
  2. Step 2: Correct syntax for redirecting error to output

    The correct syntax to redirect standard error to the same place as standard output is '2>&1'.
  3. Final Answer:

    The error redirection syntax is incorrect; it should be 2>&1 -> Option D
  4. Quick Check:

    Use 2>&1 to redirect errors to output [OK]
Quick Trick: Use '2>&1' to combine error with output redirection [OK]
Common Mistakes:
  • Writing '2>1' instead of '2>&1'
  • Forgetting '&' in error redirection
  • Assuming '2>1' redirects errors to output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes