Difficulty: Easy
Correct Answer: wc -l
Explanation:
Introduction / Context:
The wc (word count) utility summarizes text by reporting lines, words, and bytes. When scripting or auditing logs, you often need just the number of lines. Knowing the correct option avoids parsing extra fields.
Given Data / Assumptions:
Concept / Approach:
By default, wc filename prints three numbers: lines, words, and bytes. The -l option restricts output to the line count. Other options are -w for words and -c for bytes (or -m for characters on some systems).
Step-by-Step Solution:
Verification / Alternative check:
Use nl -ba file.txt | tail -1 to verify the highest printed line number equals the line count. Alternatively, awk 'END{print NR}' file.txt also returns the number of lines.
Why Other Options Are Wrong:
-r: Not a standard wc option. -w: word count, not line count. -c: byte count. None of the above: incorrect because -l is correct.
Common Pitfalls:
Using wc without options and then misreading the columns; confusing bytes and characters on multibyte encodings; counting lines in files that lack a trailing newline (tools may differ in edge handling).
Final Answer:
wc -l
Discussion & Comments