watch command in Linux with Examples
watch command in Linux is used to execute a program periodically, showing output in fullscreen. This command will run the specified command in the argument repeatedly by showing its output and errors. By default, the specified command will run every 2 seconds and watch will run until interrupted.
watch [options] command
- -d, –differences: This option highlights the differences between successive updates. The options will be going to read the optional argument which changes highlight to be permanent, allowing the user to see what has changed at least once since the first iteration.
watch -d free -m
- -n, –interval seconds: This option will specify update interval. The command will not be going to allow quicker than the 0.1-second interval, in which the smaller values are getting converted.
watch -n 1 free -m
- -p, –precise: This option make watch attempt to run command every interval seconds.
watch -p free -m
- -t, –no-title : This option is used to turn off the header showing the interval, command, and the current time at the top of the display. It will also turn off the following blank line.
watch -t free -m
- -b, –beep: This option will give beep if the command has a non-zero exit.
watch -b free -m
- -e, –errexit : This option will freeze the updates on command error, and exit after a key press.
watch -e free -m
- -g, –chgexit : This option will exit when the output of command changes.
- -c, –color : This option interprets ANSI color and style sequences.
- -x, –exec : This option command given to sh -c which means that you may need to use extra quoting just to get the desired effect.
- watch -h : This option will show the help message and exit.
- watch -v : This option will display the version information and exit.