Install Watch Command on OS X

Aug 22, 2010 - 15 Comments

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.

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 transfering 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 comand 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”
Screen shot 2010-06-09 at 8.25.23 PM

Download the “watch” command from Terminal.app
We are using “curl” a command line “broswer”
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.
./watch

Install “watch”
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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: chrisk in Command Line, Mac OS X, Tips & Tricks

15 Comments

» Comments RSS Feed

  1. Greg says:

    Thanks, very useful.

  2. This would be perfect for using with GeekTool!

  3. Testie says:

    GeekTool?

  4. nissan says:

    This is nice one.

  5. laJalame says:

    sudo port install watch

    :-)

  6. up0 says:

    This is a life-saver!!! I’ve been running mac and Linux all this time and even I didn’t know about ‘watch’… I’ve been looking for a real-time display app… something like htop/top but for other app on the shell.

  7. Fink provides `watch’ and a bunch of other useful command line utilities. See http://en.wikipedia.org/wiki/Fink and http://www.finkproject.org/

  8. Matthias says:

    ehh, download a file from somewhere you haven’t even mentioned before in the post and make it executable, then run it. It’s like the world’s most straight forward virus. I know, it probably isn’t, but one wouldn’t know either way.

    You’d probably be safer with macports or fink.

  9. [...] useful when combined with the Unix watch command (if you’re on OS X, you may have to install it manually), which reruns the command periodically so you can see how things are changing in [...]

  10. Mark says:

    Am I mistaken or is there no possibility to use the pipe with this ‘watch’? I tried “ls -hal | grep something” and it returned “h | grep command not found”.

  11. JDogg says:

    Use single or double quotes to surround your watch command.

    watch “ls -hal | grep something”

  12. braz says:

    Very helpful, thanks. However, the install command does not appear to work for me. The directory is not recognized.

  13. Zeke says:

    or you compile it yourself…

    http://procps.sourceforge.net/procps-3.2.8.tar.gz
    make watch PKG_LDFLAGS=-Wl

    why the hassle? the precompiled binary is not working on legacy power pc systems…

  14. Tom says:

    Great little tech note, thanks!

  15. Sam Bowne says:

    On OS X 10.8.2, there is no /usr/local/bin directory. Putting it in /usr/bin instead works.

    Thanks for this!

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates