Name

wc

Synopsis

    wc [options] [files]

Word count. Print a character, word, and line count for files. If multiple files, print totals as well. If no files are given, read standard input. See other examples under ls and sort.

Common Options

-c, --bytes

Print byte count only.

-l, --lines

Print line count only.

-m, --chars

Print character count only. This will be different than -c in a multibyte character environment.

-w, --words

Print word count only.

Solaris Option

-C

Same as -m.

GNU/Linux Option

-L, --max-line-length

Print length of longest line.

Examples

Count the number of users logged in:

    who | wc -l

Count the words in three essay files:

    wc -w essay.[123]

Count lines in file named by $file (don’t display filename):

    wc -l < $file

Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.