events.log contains many lines.
Print only its first five lines to standard output.
Which command is appropriate?
head selects the beginning of input. The -n option counts lines, whereas -c counts bytes.
Detailed explanation
tail -n 5 events.logIncorrect. tail -n 5 selects the last five lines.
Incorrect. tail -n 5 selects the last five lines.
head -n 5 events.logCorrect. head -n 5 prints the first five lines.
Correct. head -n 5 prints the first five lines.
head -c 5 events.logIncorrect. -c 5 prints five bytes, not five lines.
Incorrect. -c 5 prints five bytes, not five lines.
tail -n +5 events.logIncorrect. tail -n +5 starts at line 5 and continues to the end.
Incorrect. tail -n +5 starts at line 5 and continues to the end.
Try it yourself
An example you can run in a temporary verification environment.
seq 1 8 | head -n 5Expected result
1
2
3
4
5Key points
- head selects the beginning
- -n specifies lines
- tail selects the end
Notes
- Environment: GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.