wc Count lines, words and bytes
Counts the lines, words and bytes in files or in piped input. Use it to see how big a file is, or to count how many results another command produced.
Synopsis
wc [-clmw] [FILE]...
COMMAND | wc -l
Common options
| Option or form | What it does |
|---|---|
-l | Count lines (newline characters) |
-w | Count words, meaning runs of non-blank characters |
-c | Count bytes |
-m | Count characters. Differs from -c when text has multi-byte characters such as accented letters |
Examples
wc notes.txt
wc -l notes.txt
wc -l notes.txt app.log data.csv
ls docs | wc -l
grep -i error app.log | wc -l
2
find docs -type f | wc -l
2
Notes
- wc -l counts newline characters. A last line with no newline at the end is not counted.
- With several files, wc adds a total line at the end.
- When reading from a file name, wc prints the name after the count. When reading from a pipe or with <, it prints the number alone, which is easier to use in scripts.
- On macOS the numbers are padded with leading spaces. Some scripts compare them as text by mistake. Compare numerically, or strip the spaces with tr -d ' '.
- grep -c counts matching lines directly, so grep -c error app.log is shorter than grep error app.log | wc -l.
See also
Last reviewed 2026-10-07.