$linuxjunkies
>

watch(1)

Execute a program periodically, full screen, showing output differences.

UbuntuDebianFedoraArch

Synopsis

watch [OPTION]... COMMAND

Description

Runs COMMAND repeatedly at specified intervals (default 2 seconds) and displays the full-screen output. Highlights changes between successive runs, making it useful for monitoring log files, system status, or long-running processes in real time.

Press 'q' to exit, 'Space' to refresh immediately, and 'e' to exit on command error. Useful alternatives to manually running commands with sleep loops.

Common options

FlagWhat it does
-n SECONDSSet interval between command executions (default 2 seconds)
-d, --differencesHighlight differences between successive outputs
-c, --colorInterpret ANSI color sequences in command output
-t, --no-titleTurn off the header showing interval, command, and time
-x, --execPass COMMAND to exec instead of sh -c (avoids shell interpretation)
-p, --preciseRun command every INTERVAL seconds exactly (compensates for command runtime)
-e, --erase-repetitionsRemove repeated lines in output
-w, --no-wrapTurn off line wrapping (useful for wide output)

Examples

Monitor a specific process every 1 second, highlighting changes

watch -n 1 'ps aux | grep myprocess'

Watch disk usage with differences highlighted every 2 seconds

watch -d df -h

Count established network connections every 5 seconds

watch -n 5 'netstat -an | grep ESTABLISHED | wc -l'

Display date and uptime without the header, updating every 2 seconds

watch -t 'date && uptime'

Monitor system journal with color support, 1-second updates

watch -c -n 1 'journalctl -n 20'

Check git repository status every 10 seconds during a build

watch -n 10 'git status'

Run command every 1 second precisely, compensating for execution time

watch -p -n 1 'echo $RANDOM'

Monitor memory usage without shell interpretation, every 2 seconds

watch -x -n 2 free -h

Related commands