Count the Number of Words in a Text File (OSX, Linux, BSD)

Say you have a text file,  and you want to know either how many lines are in the file, how many words are in the file, or how many characters are in the file.

How can you do that?  Counting them manually would take way too long.  This is where wc comes in!

The wc manpage (this is the Ubuntu manpage) shows the options, but using it is simple from a terminal:

Count the number of lines:

wc -l filename.txt

Count the number of words:

wc -w filename.txt

Count the number of characters:

wc -m filename.txt

That will give a basic look at the number of lines, words, or characters of the supplied text file – there are many other small command line utilities which can be used in conjunction with wc to do all sorts of clever things, and I hope to produce further posts on these in the near future.