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.

Syntax:

watch [options] command

Options:

  • -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.

    Example:

    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.

    Example:

    watch -n 1 free -m

  • -p, –precise: This option make watch attempt to run command every interval seconds.

    Example:

    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.
    .

    Example :

    watch -t free -m

  • -b, –beep: This option will give beep if the command has a non-zero exit.

    Example:

    watch -b free -m

  • -e, –errexit : This option will freeze the updates on command error, and exit after a key press.

    Example:

    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 -h

  • watch -v : This option will display the version information and exit.
    watch -v



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.