Bird
0
0

What will be the output of the following command if file.txt exists?

medium📝 Command Output Q4 of 15
Linux CLI - Pipes and Redirection
What will be the output of the following command if file.txt exists?
cat file.txt && echo 'File found' || echo 'File missing'
A'File found' only
B'File missing' only
CContents of file.txt followed by 'File found'
DContents of file.txt followed by 'File missing'
Step-by-Step Solution
Solution:
  1. Step 1: Analyze cat command success

    If file.txt exists, cat file.txt succeeds and prints its contents.
  2. Step 2: Understand chaining behavior

    Because cat succeeds, && runs echo 'File found'. The || part is skipped since the left side succeeded.
  3. Final Answer:

    Contents of file.txt followed by 'File found'. -> Option C
  4. Quick Check:

    Success && echo runs, failure || echo skipped [OK]
Quick Trick: && runs next on success; || runs next on failure [OK]
Common Mistakes:
  • Thinking || echo runs after && echo
  • Ignoring cat output
  • Assuming 'File missing' prints when file exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes