Overview
wc counts the lines, words, and bytes in each file, or in standard input. A line is counted at each newline, so a last line without a trailing newline is not counted.
Background
wc counts lines, words, and bytes. A wc command appeared in Version 1 Unix, according to the FreeBSD and macOS manuals. Today the name covers GNU wc, the wc that macOS ships, and the wc applet in BusyBox. They agree on -l, -w, and -c, and differ on output padding and extra options such as -L.
Examples
Show lines, words, and bytes for a file:
wc notes.txt
Count lines only:
wc -l notes.txt
Count words only:
wc -w notes.txt
Count bytes only:
wc -c notes.txt
Count the lines of a command's output; reading standard input prints no file name:
cat notes.txt | wc -l
Count several files; a total is added:
wc -l app.log logs/server.log
Options
-l
Count newline characters, which is the number of lines.
-w
Count words, meaning runs of characters separated by whitespace.
-c
Count bytes. For characters in a multibyte encoding use -m where it is supported.
Common mistakes
The column padding of the output differs between implementations, so do not compare it as text; split on whitespace instead. Counting a file by name prints the name, while counting standard input does not, which matters when you capture the number in a script.
Portability
-l, -w, and -c are in the Common examples. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check). Output padding and the default -m behavior differ.
About GNU wc
GNU wc is part of GNU coreutils, and this page's checks ran coreutils 9.11. It adds options such as -L, which prints the longest line length.
GNU examples
Print the length of the longest line. -L is a GNU option:
wc -L notes.txt
References
Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.