Print the first five lines of events.log without modifying the file.
Which command is appropriate?
head -n N writes the first N input lines to standard output and leaves the source file unchanged.
Detailed explanation
head -n 5 events.logCorrect. head -n 5 events.log prints the first five lines.
Correct. head -n 5 events.log prints the first five lines.
tail -n 5 events.logIncorrect. tail -n 5 prints the final five lines.
Incorrect. tail -n 5 prints the final five lines.
wc -l events.logIncorrect. wc -l counts lines but does not print their contents.
Incorrect. wc -l counts lines but does not print their contents.
split -l 5 events.logIncorrect. split creates multiple output files rather than displaying lines.
Incorrect. split creates multiple output files rather than displaying lines.
Try it yourself
An example you can run in a temporary verification environment.
seq 1 8 | head -n 5Expected result
1から5までの5行Key points
- head selects the beginning
- -n sets the line count
- 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.