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.
tail -n 5 events.logIncorrect. tail -n 5 prints the final five lines.
wc -l events.logIncorrect. wc -l counts lines but does not print their contents.
split -l 5 events.logIncorrect. 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 / 生成した標準入力
- Use small, disposable text streams when testing filters.
- Locale, encoding, and GNU/POSIX implementation details can affect edge cases.
Foundation review
Place the operation
head -n provides a bounded preview without reading the whole result interactively.
Check the side effect
Count the newline-delimited records in a small test input.