Word count multiple files (shell script)

Here’s a quick shell script which can be used to get the total word count of all text files in a directory, and output it to a text file.

<code>wordcount=$(find /Users/sidoneill/Dropbox/Pool -type f -name "blogx*.*" -print0| xargs -0 cat | wc -w)
echo $wordcount > /Users/sidoneill/Dropbox/Public/wordcount.txt

You’ll need to replace the directories with your own, obviously, and as you can see I’m searching for all files whose names begin with blogx. Possible uses include:


I have a Hazel rule that’s set to run every time a file is updated in my Big Old Folder O’ Text Files. It just runs the shell script above.

Status Board

You can take that file, if it’s in your public Dropbox folder, and use it on your Status Board. You could even jazz it up a bit by adding some HTML to display the word count in a pretty way.

Applescript or Automator

It’s easy to set up an Applescript or Automator action to run as a system service (to give you a keyboard shortcut) or use Lingon or launchd to schedule it to run.

Display on your site

You could use an iframe to display the Dropbox file on your website, touting your dedication and productivity to everyone.

Log of progress

If you like to track your progress, you can change echo $wordcount > to echo $wordcount >>. This will append to the file as opposed to overwriting. You’ll probably want to add a date in there, and maybe some commas so you can view it as a spreadsheet. If you do this right, you could even display a chart of your progress on Status Board.