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”

Leave a Reply

Your email address will not be published. Required fields are marked *