The Linux wc command counts the total number of words in a file.

This command only works on plain-text files. More complex files, like documents saved in Rich Text Format, contain additional command codes that, although you don't see them when you open the file in an RTF-capable word processor, are nevertheless embedded in the document.

How to Use the 'wc' Command

The basic usage of the wc command is as follows:

wc filename



For example, a text file titled declaration.txt contains a key line from the Declaration of Independence. Executing the command:

wc declaration.txt



reveals data about the text within that file:

The command displays three numbers — 2 35 211 — plus the filename.

Those values indicate three contextual data points:

The first number counts the number of new lines of characters

The second number counts the number of words

The third number counts the number of bytes (i.e., the number of characters, visible or not)

Get the Total Word Count From Several Files

The wc command supports several filename arguments. For example, if we duplicate the declaration.txt as declaration2.txt, then run the wc command on both files, we'll see the totals for each and then the totals for both:

Command Switches

Adding a command switch refines the results of the wc command. It supports:

-c : Displays only the number of bytes and the filename

: Displays only the number of bytes and the filename -m : Displays only the number of characters

: Displays only the number of characters -l : Displays only the number of lines

: Displays only the number of lines -w: Displays only the number of words