wc—counts lines, words, and characters

wc [ -lwc ] [ filename …]

wc counts lines, words, and characters in a file or in the standard input if no filename is given. A word is a string of characters delimited by a space, tab, or new line.

Example A.71.
1  wc filex
2  who | wc -l
3  wc -l filex
				

Explanation

  1. Prints the number of lines, words, and characters in filex.

  2. The output of the who command is piped to wc, displaying the number of lines counted.

  3. Prints the number of lines in filex.

Get Linux Shells by Example 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.