In Unix, how do I get the line, word, or character count of a document?
In Unix, to get the line, word, or character count
of a document, use the wc command. At the Unix
shell prompt, enter:
wc filename
Replace filename with the file or files for which you
want information. For each file, wc will output
three numbers. The first is the line count, the second is the word
count, and the third is the character count. For example, if you
entered wc .login, the output would be something
similar to the following:
38 135 847 .login
To narrow the focus of your query, use one or more of the
following wc options:
| Option | Entities counted |
|---|---|
-c |
bytes |
-l |
lines |
-m |
characters |
-w |
words |
Note: In some versions of wc, the
-m option will not be available or
-c
will report characters. However, in most cases, the values for
-c and -m are equal.
For example, to find out how many bytes are in the .login
file, you could enter:
wc -c .login
You may also pipe standard output into wc to
determine the size of a stream. For example, to find out how
many files are in a directory, enter:
/bin/ls -l | wc -l
For more information about wc, read its
man page. To do this, at the Unix prompt, enter:
man wc
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on September 16, 2010.







