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 -h

By 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 -h

Monitor other information

Show currently logged-in users:

watch who

Show memory information in mebibytes:

watch free -m

Repeat 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

OptionPurpose
-n secondsSets the update interval.
-dHighlights changes between updates.
-tHides the header showing the interval, command and time.
-cInterprets 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 procps

On Red Hat Enterprise Linux, install procps-ng using the distribution’s package manager:

sudo dnf install procps-ng

If 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.