$wc
Print newline, word, and byte counts for files.
wc [OPTIONS] [FILE...]Try `wc` Live in Interactive Sandbox
Zero-install client simulation with real-time feedback.
Overview & How wc Works
`wc` (Word Count) reads files or standard input and computes statistics including line count (`-l`), word count (`-w`), and byte count (`-c`). It is widely used in shell pipelines to count query results or filter matches (e.g., `grep ... | wc -l`).
Common Flags & Command Options
| Flag / Option | Description |
|---|---|
| -l | Count and print total newline line counts. |
| -w | Count and print total words. |
| -c | Count and print total bytes. |
| -m | Count and print total characters. |
Practical Real-World Examples
wc -l welcome.txtOutputs the line count for welcome.txt.
grep "error" /var/log/syslog | wc -lPipes grep output into wc -l to get the exact integer count.
Frequently Asked Questions
Why does wc -l sometimes show 1 less line than expected?
`wc -l` counts newline (`\n`) characters. If the final line in a file lacks a trailing newline character, it is not counted as a full line.
Related Linux Commands
Search for matching string patterns or regular expressions inside text files.
Concatenate and print file contents directly to the terminal standard output.
Output the first part (top lines) of text files.
Output the last part (bottom lines) of files or stream real-time logs.
Print text strings or write data to files using shell redirection.
Stream editor for filtering and transforming text using pattern substitutions.