Examples
Quote a command that has a pipeline/wildcard (
watch 'ss | grep x'), otherwise|and*apply towatchitself, not the command.
Repeats a command every N seconds on one screen; without quotes, a pipeline goes to the shell, not the command.
watch -n1 -d 'command'
every second, highlight changes
watch cat /proc/mdstat
progress (RAID/jobs)
watch 'ss -tlnp | grep :80'
quotes for the pipeline!
watch -g cmd
exit when the output changes
watch -c 'docker ps'
with color
watch repeats a command every N seconds and shows the fresh result on
the same screen — handy for watching a process (a RAID rebuild, a queue,
a file's size).
Always quote a command that has a pipeline or a wildcard (|, *) —
otherwise the shell parses them before watch even runs, instead of the
repeated command doing so. By default watch strips ANSI color from the
output; -c turns it back on for commands that color their own text.
| Option | What it does | Example |
|---|---|---|
-n SECONDS |
Interval between runs in seconds; fractional values like 0.5 are allowed. | watch -n1 'ss -tlnp | grep :80' |
-d |
Highlight what changed compared to the previous output. | watch -d free -h |
-g |
Exit as soon as the command's output changes. | watch -g 'systemctl is-active nginx' |
-e |
Stop if the command exits with a non-zero status. | watch -e 'curl -sf http://localhost/healthz' |
-c |
Interpret ANSI color codes in the command's output. | watch -c 'docker ps' |
-t |
Hide the header showing the command name and time. | watch -t 'df -h' |
Nothing found. Try a shorter query.
Quote a command that has a pipeline/wildcard (
watch 'ss | grep x'), otherwise|and*apply towatchitself, not the command.
Wrap the whole command in quotes: watch 'cmd | grep x'. Without quotes,
the shell parses |/* before watch even sees them.
By default watch strips ANSI color. Turn it on: watch -c 'cmd' (if the
command colors its own output).
For logs, tail -f (see files-basics) or journalctl -f (see
journalctl) are better; watch is for a "snapshot of state", not a
stream.
watch -g cmd exits once the output changes (handy as "wait until
ready"); watch -e cmd stops if the command errors out.
Found an inaccuracy? Report an error in the article