Tips from RHCEs

Featured Article: The Watch Command

by Richard Keech

Many Linux commands provide a snapshot of a system's status, for example, ifconfig, df, route, etc. But often times, an administrator needs a real-time view like the top command instead of the ordinary ps command.

With "watch", a standard Linux utility from the procps package, you can pass an entire command string, with its own arguments. For example:

#ifconfig eth0
#watch ifconfig eth0

Providing a new sample every two seconds, an administrator is then able to monitor the interface's packet and byte counts as they change in real time. Obviously, this can prove to be an invaluable troubleshooting aid in numerous scenarios.

Taking this further, it is possible to leverage watch to highlight inter-frame differences. In other words, data that changes between one snapshot and the next will be shown in reverse video. Simply type the following:

#watch --differences ifconfig eth0
If sampling every two seconds is too slow, and once every second is required, then do this:
#watch -n 1 ifconfig eth0

I'm sure you get the idea--simple but effective. The bottom line is that watch is a valuable utility for a number of different purposes.