Counting words

Okay. We can find the files we want and get a fair amount of information, but there are still a few more tricks to make things easier.

For example, let's say that our longText.txt file needs to be fewer than 500 words. There's an easy way to check that:

wc longText.txt

The "wc" command gives us the "word count" - among some other things.

You can see that this command gaves us back 3 numbers: 9 - 492 - 3005. These are the line, word and character counts for the longText.txt file.

And again, you can use pipes to count the output of other programs. How many readme files do we have in the home directory?

find ~ -name "*.txt" -print | grep README | wc -l

First, find will find all text files, then grep will select those that have "readme" in their name and "wc -l" will count how many lines were given to it by grep. On my computer I have 24 readme files in my home directory.

source: Makers Academy

results matching ""

    No results matching ""