Skip to content

Watch command on Linux (runs the program recursively)

Imagine that you want to monitor a situation by running a command periodically.

You can use bash’s history and manually run the program as many times as necessary, or use the watch command on Linux.

The watch command in Linux executes a command periodically, which allows you to observe how the program’s output changes over time.

If no interval is entered, the watch uses 2 seconds as default.

The most common options are:

  • -d Shows the differences between updates;
  • -n X Defines the interval in X seconds;
  • -t Disables the header;
  • -g Terminates execution when the command output changes;

In this example the watch can be used to monitor TCP connections:

$ watch -n 1 ss -t <br></br>Every 1,0s: ss -t Sun Sep 15 21:37:32 2019 <br></br>State Local Address:Port Peer <br></br>Address:ESTA Port 127.0.0.1:http 127.0.0. 1:39608

ESTAB 127.0.0. 1:39608 127.0.0.1:http Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share