The Linux watch command

Sometimes you need to run a particular command several times. For example, if you observed a problem with the server, and there is reason to believe that their cause lies in the memory capacity or the operations of input and output. Also this can be useful for tracking changes to directories. In these and other cases come to the aid of the watch.

By default, the linux watch command is included in almost all Linux distributions. Its purpose is to run user specified command after a certain period of time, and to print the output of this command in the terminal window. Work watch can be compared with the work of the tail, with the only difference that the source output is not a log file, and the other team.

The watch command in Linux

The syntax and options

The syntax of the watch command is very simple:

watch option comandantedavid

The list of options is small, but they are sufficient for the effective use of teams:

  • -d (–differences) — is used to allocate the data in the command output that are different from the previous one.
  • -n (–interval seconds) — allows you to set the desired interval run the command.
  • -t (–no-title) — turns off the display of headers.
  • -b (–beep) — if the command fails, an audible chime will sound.
  • -e (–errexit) — if an error occurs, the output will be frozen, the watch will stop working when pressing keyboard shortcuts.
  • -g (–chgexit) — on the condition that the output of the command will show the changes.
  • -c (–color) — interpretered the sequence of colors and styles ANSI.
  • -x (–exec) — the command will be passed to the interpreter sh using shell dash. If you are using the full version of writing (–exec) command will be executed in exec.

Examples of usage watch

The easiest way to demonstrate the work of the team watch, watching as the computer uses RAM:

watch free -m

In this case, was not used command options watch, but by running the free command I had to add the-m parameter, which is responsible for displaying of free RAM. So, too, can and should be done to get the desired result.

Not to remember what was the previous output and does not monitor changes on their own should give this job to the-d option. It highlights the information that is different from the previous one:

watch-d date

On each of the screenshots in the top row is the inscription “Every 2.0 s”. It means that the program is restarted every 2 seconds. This interval is set by default but can be changed using the-n option.

watch-n5-d 'cat /proc/loadavg'

Please note that the value n cannot be less than 1. The upper limit is not limited.

If you need to obtain on the terminal screen have more space for useful data, it is possible to remove the title information. To do this, use the-t option.

watch-t df

The refresh interval command options and the current date are not displayed anymore.

With regard to exit watch, then he is pressing Ctrl+C or Ctrl+z Until you use one of these combinations, the command will be executed with the specified parameters.


The linux watch command is a simple and effective tool for anyone involved in server administration. However, ordinary users can find a use for it. If you have any questions regarding the use of the watch on computers running the Linux operating system, ask them in the comments.


(Visited 4 times, 1 visits today)