wc

Format:

wc options files 

Options:

-c Print character count
-l Print line count
-w Print word count

This counts the number of characters or words.

					$ who|wc 
      1    6    46 
$ who|wc -l 
      1
				

In the first example output the who command is piped through to wc, and the following columns are displayed:

number of lines, number of words, number of characters 

In the second example, wc just prints the number of lines.

					$ VAR="tapedrive" 
echo $VAR | wc -c
10
				

The number of characters in the string VAR is output.

Get Linux and Unix Shell Programming 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.