Basic usage
watch command
watch ls -la
Update interval
# Every 2 seconds (default)
watch -n 2 command
# Every 5 seconds
watch -n 5 df -h
# Every 0.1 seconds
watch -n 0.1 command
Highlight differences
watch -d command
watch --differences command
Cumulative highlights
watch -d=cumulative command
Precise interval
watch -p -n 1 command
No title
watch -t command
Exit on change
watch -g command
# Exits when output changes
Common use cases
Monitor disk space
watch -n 5 df -h
Watch processes
watch -n 1 'ps aux | grep process'
watch -n 1 'ps aux --sort=-%mem | head -20'
Monitor network
watch -n 1 ss -tuln
watch -n 1 'netstat -tuln | grep LISTEN'
System resources
watch -n 1 free -h
watch -n 1 'cat /proc/loadavg'
File changes
watch -n 1 ls -lh file.txt
watch -n 1 'wc -l logfile.log'
Docker containers
watch -n 2 docker ps
watch -n 1 'docker stats --no-stream'
Git status
watch -n 5 git status
watch -n 10 'git log --oneline -5'
Kubernetes
watch -n 2 kubectl get pods
watch -n 1 'kubectl top nodes'
Advanced examples
Multiple commands
watch 'uptime; free -h; df -h /'
With pipes
watch 'ps aux | grep nginx | wc -l'
Colored output
watch --color 'ls --color=always'
Beep on change
watch -b -n 1 command
Monitor log file
watch -n 1 'tail -20 /var/log/app.log'
Comparison with alternatives
# watch (periodic execution)
watch -n 1 command
# while loop (shell script)
while true; do clear; command; sleep 1; done
# tail -f (for log files)
tail -f file.log
Tips
# Use quotes for complex commands
watch 'ps aux | grep nginx'
# Clear screen between runs (alternative)
while sleep 1; do clear; date; ps aux | grep nginx; done
# Save to log
watch -n 60 'date >> /tmp/watch.log; df -h >> /tmp/watch.log'