O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required