Linux style 'watch' command on Mac OS

There is a handy command on Linux, and some more recent Unix machines called 'watch'. Any command you might like to run repetitively to keep an eye on something can run be run over and over with the output displayed on a cleared terminal. You might use it to keep an eye on your disk usage while doing something disk intensive like this:

watch df -h

I find it particularly handy to test out cron job scripts.

watch php ./cronjob_under_devel.php


However on Mac OS the command is normally not available. You can write a one line bash script to do a similar job. For example to watch the date and time:

while clear; date; df -h; do sleep 2; done


This is great for one off occasional use, and if you can remember it! If you really would like to use watch though, there is better a way.

If you have Homebrew (my preferred way) it is easy:

brew install watch

Or if you have MacPorts

sudo port install watch