Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Execute a command in a regular interval - watch Linux command

Date: 2009-01-04 00:00:00 -0400

If you anytime need to execute a command once and again and again, you can use watch and tell it to execute the Linux command in a give interval.

The syntax of the command is:

watch [option(s)] command

The default interval of execution of the given command is two (2) seconds, but you define a different interval using the option -n.

Here are two useful uses of watch.

watch -n 5 free -m

Which will show you the use of memory each five seconds.

watch -n 30 vnstat -h

Which will show you the bandwidth used hourly, read more about vnstat.

You can also make watch to highlight any change it detect between two screens of output.

watch -n 30 -d vnstat -h

And if you want to maintain the highlight on, add =cummulative to the -d option, like this:

watch -n 30 -d=cummulative vnstat -h

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.