Bird
0
0

What will be the output of the following commands if file.txt does not exist?

medium📝 Command Output Q13 of 15
Linux CLI - Pipes and Redirection
What will be the output of the following commands if file.txt does not exist?
cat file.txt && echo "File exists" || echo "File missing"
AFile exists
BFile missing
CNo output
Dcat: file.txt: No such file or directory
Step-by-Step Solution
Solution:
  1. Step 1: Understand command chaining behavior

    cat file.txt fails because file does not exist, so && echo "File exists" is skipped, and || echo "File missing" runs.
  2. Step 2: Predict output

    The error message from cat is printed to stderr (not shown here), but the command output from chaining is File missing.
  3. Final Answer:

    File missing -> Option B
  4. Quick Check:

    Failed cat triggers || echo [OK]
Quick Trick: Remember: || runs next if previous fails [OK]
Common Mistakes:
  • Expecting 'File exists' output
  • Ignoring that cat prints error to stderr
  • Thinking no output appears

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes