watch Command in Linux: Executing Commands Periodically
Linuxcommands
Imagine you want to monitor a situation by running a command periodically.
You can use bash history and manually run the program as many times as needed, or use the watch command in Linux.
The watch command in Linux executes a command periodically, allowing you to observe how the program's output changes over time.
If no interval is specified, watch uses 2 seconds by default.
The most common options are:
- -d Shows the differences between updates;
- -n X Sets the interval to X seconds;
- -t Disables the header;
- -g Exits when the command output changes;
In this example watch can be used to monitor TCP connections:
$ watch -n 1 ss -tEvery 1,0s: ss -t Sun Sep 15 21:37:32 2019State Local Address:Port Peer Address:PortESTA 127.0.0.1:http 127.0.0.1:39608ESTAB 127.0.0.1:39608 127.0.0.1:http
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Liked it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.