wc - Count Lines, Words, and Characters
Learn wc for counting lines, words, and bytes. Quick stats on files and pipeline output.
wc: Count Things
How many lines in this file? How many words? wc tells you:
wc file.txt
Output: 42 156 1089 file.txt
That's 42 lines, 156 words, 1089 bytes. Simple stats.
Getting Specific
Usually you just want one number:
Lines only:
wc -l file.txt
Words only:
wc -w file.txt
Bytes/characters only:
wc -c file.txt
The -l Flag Lives at the End of Pipelines
This is wc's most common use - counting how many results came through:
How many errors?
grep "error" log.txt | wc -l
How many files match?
find . -name ".txt" | wc -l
How many unique entries?
sort data.txt | uniq | wc -l
Multiple Files
wc .txt
Shows stats for each file, plus a total.
Quick Reference
| What you want | Command |
|---------------|---------|
| All stats | wc file |
| Line count | wc -l file |
| Word count | wc -w file |
| Byte count | wc -c file |
| Count pipe results | command \| wc -l |
Practice
In CTF challenges, wc -l is your sanity check. "Did my grep find anything?" "How many files am I dealing with?"
wc is the simplest possible question: how many?