The wc command

The wc (word count) command counts lines, words, and bytes of its input. The default output is to show all three:

$ wc .bashrc
 101  550 3391 .bashrc

In this example, our .bashrc file has 101 lines, 550 space-delimited words, and 3,391 bytes. You can print only one of these numbers with the -l, -w, and -c options, respectively.

Technically, wc -l counts the number of newlines in the file, not the number of lines that they delimit. This is almost the same thing, but not exactly.

If you provide more than one file for wc to examine, it will also print a total:

$ wc -c .bashrc .bash_profile
3391 .bashrc
 471 .bash_profile
3862 total

Be careful to distinguish between bytes and characters. If you actually need to count the number of characters, for example if you're dealing with a file with Japanese characters or emojis in it, you can use the -m option instead:

$ wc -m -c japanese
 6 16 japanese

Note here that the number of characters (6) is different from the number of bytes (16), as some of the characters are composed of more than one byte in UTF-8 encoding.

The character counts returned with the -m option will depend on your system's locale settings. Most modern systems will provide a UTF-8 locale to new users.