Linux watch command cheatsheet
Ever wish you could just run a command and keep seeing it update automatically as things change? That is exactly what the watch command does on Linux
Here are useful examples of the watch command 😎👆
Find high-res pdf ebooks with all my Linux related infographics at https://study-notes.org
Using the Linux watch command has been a game-changer in my daily system management tasks. One of the biggest advantages is how it automates monitoring by repeatedly running commands and updating the output on your terminal, which helps you spot issues quickly without manual intervention. For example, when troubleshooting a sluggish system, I regularly use watch with the command `ps -eo pid,comm,%cpu --sort=-%cpu | head` to see which processes are hogging the CPU. This real-time insight lets me decide whether to kill a process or investigate it further. Another favorite is tracking disk space with `watch -n5 df -h`, which refreshes every 5 seconds and helps me detect if any mounted filesystems are filling up. This is especially crucial on servers handling lots of file writes. Network monitoring is streamlined using `watch -n1 ss -tuna` to watch TCP and UDP socket activity. This comes in handy when diagnosing network connectivity or suspicious traffic. I’ve also found it invaluable for container management with `watch -n2 docker ps` which refreshes the list of running Docker containers, allowing me to respond promptly to container crashes or unexpected stops. One tip worth sharing is customizing the refresh interval using the -n option based on how fast you want updates. For highly dynamic data, a 1-second interval is ideal, but for slower-changing metrics, longer intervals reduce system load. Overall, the watch command is a simple yet powerful utility for anyone managing Linux systems. It transforms static commands into a dynamic monitoring tool, which is often the difference between proactive system management and reactive troubleshooting.
