Count lines and words with wc
wc is the classic counter that most people remember exists but forget the flag order for; -l counts lines, -w words, -m characters, and piping any command into it counts that stream.
Run `wc -l file.log` to count lines in a file, or pipe any listing into it like `grep ERROR app.log | wc -l`.
01Command
Command
$ wc -l access.log
wc -l *.txt
cat notes.md | wc -w02What it does
With no flags wc prints all three counts plus the filename, in the order lines, words, bytes. When counting lines generated by another command, the combination of grep/find with wc -l is one of the most reused idioms in shell history; note that wc counts newline characters, so a final line without a trailing newline is not counted.
03Risk
!Warning: A file whose last line lacks a newline terminator will show one line fewer than a text editor displays.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- wc — word, line, character, and byte countEvidence: Documents -l lines, -w words, -m characters, and -c bytes options.
Last verified: 2026-09-17 · Category: Files & Folders