# Starting Useful Commands: wc to Count Aspects of a File

Starting useful commands: wc to count aspects of a file

The UNIX wc command is a useful tool for counting the number of lines, words and characters in a file.

In order to demonstrate the wc command, let’s create a text file to give it something to count.

Create a file using the nano editor called fruit.txt

Then populate it with the following line:

Orange

Apple

Pear

Banana

Grape

Select control-x to exit and type y and press enter to save the changes and write the file to disk.

Type ls to list the directory contents and you will see a file called fruit.txt

ls

The following terminal details various wc outputs:

wc fruit.txt gives a full output of the number of lines (5), words (5) and characters (31).

wc -l outputs the number of lines in the fruit.txt file i.e. 5

wc -w outputs the number of words in the fruit.txt file i.e. 5

wc -c outputs the number of characters in the fruit.txt file i.e. 31

Further information on the wc command and its parameters can be found by accessing the following link.

Or by accessing the manual pages for wc within a terminal session, by typing:

man wc