Bird
0
0

What will be the output of this command?

medium📝 Command Output Q5 of 15
Linux CLI - Pipes and Redirection
What will be the output of this command?
grep 'pattern' /nonexistentfile > /dev/null 2>&1 && echo 'Found' || echo 'Not Found'
ANot Found
BFound
CNo output
DError message displayed
Step-by-Step Solution
Solution:
  1. Step 1: Analyze command behavior

    The file does not exist, so grep will fail and return a non-zero exit status.
  2. Step 2: Output redirection

    Both standard output and error are redirected to /dev/null, so no messages appear.
  3. Step 3: Conditional execution

    The && runs echo 'Found' only if grep succeeds; otherwise, || runs echo 'Not Found'.
  4. Final Answer:

    Not Found -> Option A
  5. Quick Check:

    Non-zero exit triggers 'Not Found' [OK]
Quick Trick: Non-zero exit triggers 'Not Found' echo [OK]
Common Mistakes:
  • Expecting error messages to display
  • Confusing output redirection with exit status
  • Assuming 'Found' will print despite failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes