Bird
0
0

What will be the output of tail -n +4 file.txt | head -n 2 if file.txt has 10 lines?

medium📝 Command Output Q5 of 15
Linux CLI - Viewing and Editing Files
What will be the output of tail -n +4 file.txt | head -n 2 if file.txt has 10 lines?
ALines 4 and 5 of file.txt
BLines 1 and 2 of file.txt
CLines 3 and 4 of file.txt
DLines 9 and 10 of file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand tail -n +4 file.txt

    This outputs the file starting from line 4 to the end (lines 4 to 10).
  2. Step 2: Pipe to head -n 2

    This takes the first 2 lines from the previous output, which are lines 4 and 5 of the file.
  3. Final Answer:

    Lines 4 and 5 of file.txt -> Option A
  4. Quick Check:

    tail -n +N starts at line N [OK]
Quick Trick: tail -n +N starts output from line N [OK]
Common Mistakes:
  • Thinking tail -n +4 outputs last 4 lines
  • Confusing line numbers
  • Ignoring pipe effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes