text

wc

Counts lines, words, characters, and bytes in files or stdin. Frequently used at the end of pipelines to size results.

wc [OPTION]... [FILE]...

Common flags

Flag Purpose
-l Print the newline count
-w Print the word count
-c Print the byte count
-m Print the character count
-L Print the length of the longest line

Examples

wc -l *.py

Count lines in every Python file plus a total

grep ERROR app.log | wc -l

Count matching lines in a pipeline

wc -c file.bin

Report byte size of a binary

wc -L source.txt

Find the longest line's width

Gotcha

-c counts bytes, -m counts characters -- they diverge for multibyte encodings like UTF-8.

Related commands

← All Linux commands · Linux cheat sheet