Skip to content

WC command on Linux (word count)

The wc command on Linux shows the lines, words, and number of characters in a file, in this order.

Suppose you want to count the number of lines, words, or characters in a file. The wc command can be used to count the lines, words, and characters in one or more files. If more than one file is passed as an argument, it will show the statistics for each file and the total.

The most common options are:

  • -c: Count the number of characters in one or more files;
  • -l: Count the number of lines in one or more files;
  • -L: Count the number of characters in the longest line of the file;
  • -w: Count the words in one or more files.

In this example, we are going to use the toilet to count the unique items on the grocery list:

$ <a data-id="1050" data-type="post" href="https://www.linuxcertification.academy/linux-sort-command-sort-data-basic-guide/">sort</a> supermarket | <a data-id="1048" data-type="post" href="https://www.linuxcertification.academy/uniq-command-on-linux-remove-duplicates-basic-guide/">uniq</a> | wc
6 6 41

Our list has 6 items (one per line), six words, and 41 characters.