watch: auto-repeat a command

terminalOften we need to run the same command repeatedly to check if the output is changing. watch can do that for you automatically. It has some useful options too.

-d: highlights the differences
-n: specify the update interval in seconds
-b: beep if the command has non-zero exit
-e: freeze on error

For example, to check the changing temperature of all my 4 CPUs per 2 seconds I use:

$ sudo watch -n 2 cat /sys/devices/system/cpu/cpu{0..3}/cpufreq/cpuinfo_cur_freq

Another usage can be checking the memory consumption:

$ watch free -m

RunĀ man watch for more information.

One thought on “watch: auto-repeat a command”

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s