Did you know?
watch reruns any command every 2 seconds and shows the output full screen.
Add -d to highlight what changed between runs.
- Shell & terminal
- Last checked
Explained
Waiting for a disk to fill, a service to come up or a file to appear? Instead of pressing the up arrow and Enter over and over, let watch do it. It runs a command every 2 seconds by default and redraws the output in place:
watch -d -n 5 df -h
-n 5 sets the interval to 5 seconds and -d highlights the characters that changed since the last run, which makes small changes easy to spot. Press Ctrl+C to stop.
If the command contains pipes or redirections, put it in quotes so watch receives it as a whole:
watch -n 2 'ss -s | head -5'
A few more ideas: watch -n 1 'ls -lh /var/backups' to follow a backup, watch systemctl is-active nginx during a restart, or watch -g ls /tmp/ready.flag, where -g exits as soon as the output changes.
