wc Command Cheatsheet
The wc (word count) command is used to count lines, words, characters, and bytes in files or from standard input. It is a quick way to inspect file size and text statistics.
Common Syntax
The most common usage prints line, word, and byte counts.
wc [OPTION]... [FILE]... Without options, wc outputs three columns: lines, words, and bytes.
Common Count Options
You can specify exactly what type of count to display.
| Option | Description | Example |
|---|---|---|
-l | Count lines only. | wc -l notes.txt |
-w | Count words only. | wc -w article.txt |
-c | Count bytes only. | wc -c data.bin |
-m | Count characters only. | wc -m utf8.txt |
Useful Output Options
| Option | Description | Example |
|---|---|---|
-L | Print the length of the longest line. | wc -L report.txt |
--files0-from=F | Read input file names terminated by NUL from file F. | wc -l --files0-from=list.txt |
--total=WHEN | Control when to print a total line (GNU wc behavior). | wc --total=only *.log |
Using wc with Pipelines
wc is frequently used in command pipelines to summarize output from other tools.
# Count how many .log files exist in the current directory
ls -1 *.log 2>/dev/null | wc -l