wc

wc — "word count" — counts what is in a file: its lines, its words, and its bytes.

wc [options] [file...]
$ wc report.txt
  214  1832 12044 report.txt

By default wc prints three numbers per file — lines, words, bytes — followed by the file name. Given several files, it adds a total line. With no file, it reads standard input.

Choosing what to count #

Pass any of these and wc prints only the counts you ask for, in the fixed order lines, words, characters/bytes, longest-line:

OptionCounts
-l, --linesThe number of lines.
-w, --wordsThe number of words — runs of non-whitespace.
-c, --bytesThe number of bytes.
-m, --charsThe number of characters. This differs from -c for multi-byte text, where one character is several bytes.
-L, --max-line-lengthThe length of the longest line.
$ wc -l report.txt        # just the line count
214 report.txt

Other options #

OptionEffect
--files0-from=FTake the list of files to count from F, as NUL-terminated names. - reads the list from standard input.
--total=WHENControl the total line: auto (the default — shown for more than one file), always, only (just the total, no per-file lines), or never.

Exit status #

CodeMeaning
0Every file was counted.
1A file could not be read.

Edit this page