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 ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.