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.
Incorrect. -w counts words.
wc -l records.txtCorrect. wc -l reports the number of newline characters as lines.
Correct. wc -l reports the number of newline characters as lines.
wc -c records.txtIncorrect. -c counts bytes.
Incorrect. -c counts bytes.
nl records.txtIncorrect. nl adds line numbers and displays content rather than only the count.
Incorrect. 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 / 標準入力
- 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.