The wc Command
wc stands for "word count," but it does much more.
Basic Usage
Three numbers:
- 42 - lines
- 256 - words
- 1847 - bytes (characters)
Count Lines Only
This is by far the most common use of wc.
Quick Line Count
"How many lines in this file?" โ wc -l file
"How many files in this directory?" โ ls | wc -l
Count Words Only
Count Characters
-c= bytes-m= characters (matters for Unicode)
Multiple Files
Counts each file plus a total.
Combined with Pipes
Counting Results
Pipe anything to wc -l to count results:
- How many errors?
grep 'ERROR' log | wc -l - How many JavaScript files?
find . -name '*.js' | wc -l - How many processes?
ps aux | wc -l
Real-World Examples
Lines of Code
Users on System
Running Processes
(Subtract 1 for the header line)
Log Entries Today
How do you count the number of lines in a file?
Quick Reference
| Flag | Counts |
|---|---|
-l | Lines |
-w | Words |
-c | Bytes |
-m | Characters |
Key Takeaways
wc= word count (lines, words, bytes)-lis most commonly used for line counts- Pipe output to
wc -lto count anything - Works on multiple files and shows totals
- Essential for quick statistics on files and command output
Next: character translation with tr.