Home > How-Tos > watch


January 4th, 2009

I only came across this command fairly recently. It’s a simple command, but immensely useful.

The watch command is used to run a given command at a predefined interval, and to monitor the output in real-time until the watch command is terminated. When run, it initially only displays the first output of the given command, and then only updates it if something in the output changes.

For example to have a constantly up-to-date listing of a directory, just run

watch ls

Or similarly to have a list of who is logged onto your system, just run

watch who

These two examples are very simple, but they can be made as complex as you like.

A number of options can be used:

  • ‘-d’ or ‘–differences’ will briefly highlight what has changed in the output
  • ‘–cumulative’ will make the differences remain displayed
  • ‘-n seconds‘ or ‘–interval=seconds‘ will allow the interval between program runs to be set to something other than it default of two seconds
Categories: How-Tos Tags: ,
Comments are closed.