When to use wc
Use wc to count lines, words or bytes in files and streams. Select the quantity explicitly for scripts and distinguish byte size from character count in multibyte text.
Syntax
wc [OPTIONS] [FILE...]Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Count lines
wc -l ./app.logThe count is the number of newline characters, not a visual line count in an editor.
View size in bytes
wc -c ./report.txtThe file's byte count is reported, including all encoded bytes.
Count lines in output
printf '%s\n' one two three | wc -lThree newline-terminated records produce a line count of three.
Notes and limitations
- A final line without a newline does not increase the -l count.
- Byte counts and character counts differ for multibyte encodings.
Common questions and troubleshooting
Why is my last line missing from the count?
A final record without a terminating newline does not add a newline character. This explains common differences from editor line numbering.
Are bytes and characters the same count?
Only for some encodings and content. Multibyte text can use several bytes per character; choose the character-count mode when appropriate.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man wc.