Bird
0
0

Given a file data.txt with 20 lines, what will be the output of head -n 3 data.txt | tail -n 2?

medium📝 Command Output Q13 of 15
Linux CLI - Viewing and Editing Files
Given a file data.txt with 20 lines, what will be the output of head -n 3 data.txt | tail -n 2?
ALines 2 and 3 of data.txt
BLines 1 and 2 of data.txt
CLines 18 and 19 of data.txt
DLines 3 and 4 of data.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand head -n 3 data.txt

    This command outputs the first 3 lines: lines 1, 2, and 3.
  2. Step 2: Apply tail -n 2 on the output

    tail -n 2 takes the last 2 lines of the previous output, so lines 2 and 3.
  3. Final Answer:

    Lines 2 and 3 of data.txt -> Option A
  4. Quick Check:

    head 3 then tail 2 = lines 2 & 3 [OK]
Quick Trick: Pipe head then tail to slice lines from start [OK]
Common Mistakes:
  • Assuming tail works on whole file, not head output
  • Confusing line numbers
  • Thinking tail -n 2 shows first 2 lines

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes