Difficulty: Easy
Correct Answer: wc -c
Explanation:
Introduction / Context:
The wc utility (short for word count) is a standard Unix/Linux tool for quickly reporting basic text statistics. While many people use it to count lines or words, wc is equally useful for counting the number of characters (commonly interpreted as bytes in POSIX systems). This question tests recognition of the correct switch to retrieve only the character count.
Given Data / Assumptions:
Concept / Approach:
wc supports separate flags for each statistic: -l for lines, -w for words, and -c for bytes (often referred to as characters). When invoked with a single flag, wc prints only that metric. Without flags, wc prints all three (plus the filename). Counting bytes is the most portable, as wc -c reports the number of bytes read from the file stream.
Step-by-Step Solution:
Verification / Alternative check:
As a sanity check, compare wc -c results with an alternate method such as using a programming language or summing byte counts from a hex dump. For small files without multibyte complications, the count should match exactly.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing characters with lines or words, assuming -m is always available (some wc implementations also support -m for characters, but -c is the portable choice), or forgetting to handle filenames with spaces when scripting.
Final Answer:
wc -c
Discussion & Comments