Who Watches Watch?
The watch command is one of those little gems that often gets overlooked and has its functionality duplicated by a custom tool; just slower and more complicated. At its most basic watch runs the specified command every two seconds until interrupted, a simple example that shows the current directories content is given below, this will show any changes in either the size or timestamp of the contents.
watch ls -ahl
Watch excels in showing real-time differences, by supplying either ‘-d’ or the long option ‘–differences’ any changes will be marked on screen using inverse colours. Running this command on two separate machines allows you to easily drill down on any changes taking effect, a good example is when comparing two MySQL slaves with a command like this:
watch -d -n 1 mysqladmin ext
In most cases this is ideal however only the changes from the most recent iteration are shown, if you want any changes since the command began to stay highlighted then you need either of the following cumulative flags:
watch -d=cumulative <i>command</i>
watch --differences=cumulative <i>command</i>