DEV Community

Michael Saparov
Michael Saparov

Posted on

watch — underrated Linux command

Many Linux users write small scripts to monitor system state — CPU usage, disk space, open connections, and more.
But there is a much simpler tool built into most Linux systems: watch.
It allows you to run any command repeatedly and see the output update in real time.

Basic usage

The syntax is simple:

watch command
Enter fullscreen mode Exit fullscreen mode

By default, the command runs every 2 seconds.

Example: monitoring the mail queue

watch mailq
Enter fullscreen mode Exit fullscreen mode

This refreshes the list of outgoing messages every two seconds so you can see the mail queue shrink or grow in real time.

Example: watching network connections

watch ss -tuln
Enter fullscreen mode Exit fullscreen mode

This is useful when debugging network services or checking if a port becomes active.

Example: monitoring processes

watch "ps aux | grep nginx"
Enter fullscreen mode Exit fullscreen mode

This lets you observe whether a process starts, stops, or changes.

Changing the interval

You can change the refresh interval with -n.

watch -n 1 mailq
Enter fullscreen mode Exit fullscreen mode

This runs the command every 1 second.

Highlighting differences

One of the most useful options is -d, which highlights changes between updates.

watch -d netstat -tuln
Enter fullscreen mode Exit fullscreen mode

This makes it much easier to see what changed since the previous refresh.

Conclusion

watch is a small but powerful tool.
It can turn almost any command into a simple real-time monitoring dashboard without writing scripts.
Sometimes the best tools in Linux are also the simplest.

Top comments (0)