The wc command is used to count words, characters and lines. Here, we’ll run it a few different ways. -l shows the number of lines in a file. For example, in my home directory, I can use it to see how many lines are in my .gitconfig file:
wc -l .gitconfig
This would output something like the following:
11 .gitconfig
Or count the number of characters with -c:
wc -c .gitconfig
Or check the number of words:
wc -w .gitconfig
You can also run it against multiple files. For example, here I’ll check the number of lines in both my .gitconfig file and my .gitignore_global files:
wc -l .gitconfig .gitignore_global
Let’s say I have a list of numbers and I want to take an average of them. I can use this to quickly figure out how many numbers I have (and so will divide by) before tallying them up.