Install Watch Command on OS X
If there was one command I would really complain about not being on Mac OS X, it would be “watch”. Watch is one of those great pieces of software that is tiny and completely out of the way, but when needed it will be a life saver. We’re going to show you three different ways to install the watch command; through a precompiled binary, with HomeBrew, and with MacPorts. Plus, we’ll show you a little about how to use watch and why it’s useful.
What is ‘watch’ and how does it work?
What is the watch command? For the unfamiliar, it’s simple to explain watch; Watch will run a command repeatedly and then display the output in an “ncurses” friendly manner. Another way to explain this might be to say, you can turn any command line program output into a “real time” display. A good example is using watch to monitor disk usage.
Now of course it’s hard to demonstrate the command running in a repetitive manner using a still image, but this might be something you would want to run when monitoring the amount of space left on your hard drive while transferring a large file(s). If you examine the screen shot closely, in the upper left hand corner you will notice that the command is being run every 5.0s, or 5 seconds. The command being run, is “df -kh”. The output tells us the disk size, used space, available space and percentage used (capacity) in a human readable format (thats what the “h” stands for in df -kh). As we delete a large portion of files, or copy new files to our computer we will see these values change. If you wanted to see smaller increments you would remove the “h” and just run “df -k”.
The basic usage for watch is: watch -n number_of_seconds “command”
So, watch is pretty great. Let’s get watch working on your Mac.
How to Install & Run Watch in OS X
As mentioned, we have three choices; installing watch as a precompiled binary, installing watch with Homebrew, or installing Watch with MacPorts. The precompiled binary will work if you do not have homebrew or ports installed in OS X.
Download the precompiled “watch” command from Terminal.app
We are using “curl”, a command line “browser”, this will download watch to your Mac, but if you want you can use MacPorts or Homebrew to install watch as well, which are shown below:
curl -O http://ktwit.net/code/watch-0.2-macosx/watch
Make “watch” executable
By doing this we tell Mac OS that this is a program that can run
chmod +x watch
Test the program
Let’s make sure everything is in working order.
Optional: By following this next step we are placing watch into a system location that will allow you to run it from any location in the Terminal (You will be prompted for your password)
sudo mv watch /usr/local/bin/
Congrats, you have added the watch command to your Mac OS X System.
Installing Watch in OS X with Homebrew or MacPorts
If you’re a user of HomeBrew or MacPorts, you can also install watch through those tools:
For Homebrew, install the watch command with:
brew install watch
For MacPorts, you can install watch with:
sudo port install watch
Both of these will also install watch onto the Mac, use whichever approach you are comfortable with. With either Homebrew or Macports, you can simply type ‘watch’ after the install has been completed to run the command.