Get the line, word, or character count of a document in Unix
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 |
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 Get help for Linux or Unix at IU.
Related documents
This is document adpb in the Knowledge Base.
Last modified on 2023-07-13 10:51:29.