Counting words, lines, and bytes in files (wc command)
Use the wc command to count the number of lines, words, and bytes in the files specified by the File parameter.
If a file is not specified for the File parameter, standard input is used. The command writes the results to standard output and keeps a total count for all named files. If flags are specified, the ordering of the flags determines the ordering of the output. A word is defined as a string of characters delimited by spaces, tabs, or newline characters.
When files are specified on the command line, their names are printed along with the counts.
See the following examples:
- To display the line, word, and byte counts of the file named chap1,
type the following:
This displays the number of lines, words, and bytes in the chap1 file.wc chap1 - To display only byte and word counts, type the following:
This displays the number of bytes and words in each file where the name starts with chap, and displays the totals.wc -cw chap*