Use watch to repeat a diagnostic command and see how its output changes over time. This article explains how to monitor Linux resource information at a chosen interval and highlight differences between updates.
Start and stop monitoring
Open a terminal or connect to your Linux server using SSH. Run:
watch df -hBy default, watch reruns the command every two seconds and displays the output in the terminal. Press Ctrl + C to stop it. Updates are periodic snapshots, not continuous event monitoring.
Choose an interval and highlight changes
Check disk usage every five seconds and highlight output differences:
watch -n 5 -d df -hUse read-only diagnostic commands and choose an interval appropriate to their cost. Watch repeatedly executes the command; frequent directory scans or scripts can add load, and commands that change data will repeat those changes.
Monitor other information
Show currently logged-in users:
watch whoShow memory information in mebibytes:
watch free -mRepeat a pipeline by quoting the whole command so it runs inside watch:
watch 'ls -1 /path/to/directory | wc -l'Replace the example directory with your target. This gives a simple count of visible entries, including subdirectories; it is not a reliable count of every file. Hidden entries are excluded and names containing newlines can affect the result.
Useful options
| Option | Purpose |
|---|---|
-n seconds | Sets the update interval. |
-d | Highlights changes between updates. |
-t | Hides the header showing the interval, command and time. |
-c | Interprets colour sequences emitted by the command. |
The terminal shows only the output that fits its display. Inspect full output separately when you need a complete result.
If watch is not installed
On Debian or Ubuntu, install the procps package with administrative permission:
sudo apt update
sudo apt install procpsOn Red Hat Enterprise Linux, install procps-ng using the distribution’s package manager:
sudo dnf install procps-ngIf installation fails, check your distribution’s repositories and package availability. For monitoring filesystem events instead of repeated command output, see how to watch a directory for new file creation in Linux.