How to monitor command output periodically

How to monitor command output periodically

Checking on a task or process’ output can be simplified using the Linux watch command.

Tags: command line Linux watch


  • Access to the Linux command line


When access to the command line is achieved, you will need to have a command you wish to monitor. This can be any Linux command or executable. For example, if you want to check a file’s contents, you could use:

watch -n 12 --differences=cumulative “cat /folder/file.txt | grep status”

The previous command will monitor the file.txt’s output fullscreen. Any tasks that need to be performed in parallel can be in a separate shell. The watch command is monitoring lines in the file that contain the word “status.” The cat command’s output is piped to grep so lines that contain “status” are matched. When multiple commands are used, it is necessary to enclose them in quotes.

The watch command above is executing the commands in quotes every 12 seconds, specified by the -n argument. Differences in output every 12 seconds can be highlighted using the -d argument. If you prefer for the highlighting to remain in between watch refreshes, you can use: --differences=cumulative. This may be necessary if highlighting will be lost before it can be inspected or if the output refresh rate is too fast.

More Information

  • Type man watch from the Linux command line.