Bird
0
0

Given a file data.log with 50 lines, what will be the output of head -n 5 data.log | tail -n 3?

medium📝 Command Output Q4 of 15
Linux CLI - Viewing and Editing Files
Given a file data.log with 50 lines, what will be the output of head -n 5 data.log | tail -n 3?
ALines 1 to 3 of data.log
BLines 5 to 7 of data.log
CLines 3 to 5 of data.log
DLines 48 to 50 of data.log
Step-by-Step Solution
Solution:
  1. Step 1: Understand the first command head -n 5 data.log

    This outputs the first 5 lines of the file.
  2. Step 2: Understand the pipe to tail -n 3

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

    Lines 3 to 5 of data.log -> Option C
  4. Quick Check:

    Pipe head then tail = last lines of first lines [OK]
Quick Trick: Pipe head then tail to get middle lines from start [OK]
Common Mistakes:
  • Assuming tail applies to whole file
  • 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