Display the number of newline-terminated lines in records.txt.
Do not display word or byte counts.
Which command is appropriate?
wc -l counts newline characters. A final line without a newline can therefore differ from a visual line count.
Detailed explanation
wc -w records.txtIncorrect. -w counts words.
wc -l records.txtCorrect. wc -l reports the number of newline characters as lines.
wc -c records.txtIncorrect. -c counts bytes.
nl records.txtIncorrect. nl adds line numbers and displays content rather than only the count.
Try it yourself
An example you can run in a temporary verification environment.
printf 'a\nb\nc\n' | wc -lExpected result
3Key points
- -l means newlines
- -w means words
- -c means bytes
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
wc -l counts newline characters, which normally correspond to complete text lines.
Check the side effect
Include an input with and without a final newline when checking edge behavior.