--- layout: page author: Alessandro Luini category-page: advanced category-title: Advanced commands tags: word count lines title: wc ---

The program reads either standard input or a list of files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.

How to use

Sample execution of wc:
wc file1.txt file2.txt
will output:
      40      149      947     file1.txt
    2294    16638    97724    file2.txt
    2334    16787    98671    total
The first column is the count of newlines, meaning that the text file file1.txt has 40 newlines while bar has 2294 newlines- resulting in a total of 2334 newlines. The second column indicates the number of words in each text file showing that there are 149 words in file1.txt and 16638 words in file2.txt – giving a total of 16787 words.
The last column indicates the number of characters in each text file, meaning that the file file1.txt has 947 characters while bar has 97724 characters – 98671 characters all in all.

Flags

wc -l file1.txt
Prints the line count (note that if the last line does not have \n, it will not be counted).
wc -c file1.txt
Prints the byte count.
wc -m file1.txt
Prints the character count.
wc -L file1.txt
Prints the length of longest line (GNU extension)
wc -w file1.txt
Prints the word count.