Bird
0
0

What will be the output of the command sequence?

medium📝 Command Output Q5 of 15
Linux CLI - Pipes and Redirection
What will be the output of the command sequence?
cat < file.txt | head -n 1

Assuming file.txt contains:
line1
line2
line3
ANo output
Bline2
Cline3
Dline1
Step-by-Step Solution
Solution:
  1. Step 1: Understand cat with stdin redirection

    cat reads file.txt content via < and outputs all lines.
  2. Step 2: Pipe output to head -n 1

    head -n 1 takes the first line from cat's output, which is 'line1'.
  3. Final Answer:

    line1 -> Option D
  4. Quick Check:

    Pipe output of cat < file to head -n 1 = first line [OK]
Quick Trick: Pipe cat < file to head -n 1 to get first line [OK]
Common Mistakes:
  • Thinking head reads file directly
  • Confusing pipe direction
  • Assuming no output from cat

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes