wc

line, word, character/byte count and max line length

wc [-l [c|m] wL] [file]

Outputs the number of lines, words, and/or characters and the filename in each input file, or standard input (if no file is specified) to the standard output.
When multiple files are listed total(s) are shown.
A line is defined as a string of characters delimited by a NL .
Characters beyond the final NL will not be included in the line count.

A word is defined as a string of characters delimited by white space characters, the set of characters for which the iswspace(3) function returns true.

-l lines
-w words
-c Characters (bytes). Cancels prior -m
-m equivalent to -c . Cancels prior -c if the current locale does not support multibyte characters.
-L Length of longest line

The order of output is lines, words, character and file name.
Default -lwc.
Each count is 8 columns wide, allowing form a total of 99,999,999 characters.

>hexdump -C dafile
00000000  31 2c 32 20 33 09 34 0a  0a 0a                    |1,2 3.4...|
0000000a
> wc dafile
 3  3 10 dafile
> wc -L dafile
9 dafile
If no files are specified, the standard input is used accepting input until receiving EOF Usually [^D] and no file name is displayed.

Environment

$LANG, $LC_ALL and $LC_CTYPE affect as described in environ

Exits 0 on success, and >0 if an error occurs.

Errors

wc: inputFilename:489: Invalid or incomplete multibyte or wide character

EXAMPLES

Count the number of lines, words and characters in each of the files report1 and report2 as well as the totals for both:
wc -mlw report1 report2

See

"Is White Space" : iswspace(widec) - test for whitespace wide character

wide-character equivalent of the isspace() tests whether widec is a wide character belonging to the wide character class "space".

class "space" is disjoint from the wide character class "graph" and therefore also disjoint from its subclasses "alnum", "alpha", "upper", "lower", "digit", "xdigit", "punct".

contains the wide character class "blank".

Always contains at least the space character and the control characters \f, \n, \r, \t, \v.

See

isspace(), iswctype()

Depends on the LC_CTYPE category of the current locale.