__ _______________________ _________._________________________ \_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/ | __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_ | \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \ \___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ / \/ \/ \/ \/ \/ \/ \/

watch Cheatsheet

← Back to cheatsheets

← Home


watch executes a command repeatedly and displays the output fullscreen. Useful for monitoring system resources, processes, logs, and other changing data in real-time.


Basic Usage

  • watch <command> - Execute command every 2 seconds
  • watch -n <interval> <command> - Set update interval in seconds
  • watch -d <command> - Highlight differences between updates
  • watch -t <command> - No title bar
  • watch -b <command> - Beep on command exit
  • watch -e <command> - Exit on error

Display Options

  • watch -n <seconds> <command> - Update interval
  • watch -d <command> - Highlight differences
  • watch -d=cumulative <command> - Cumulative highlighting
  • watch -t <command> - Turn off header
  • watch -g <command> - Exit when output changes
  • watch -c <command> - Interpret ANSI color codes

Behavior Options

  • watch -b <command> - Beep if command has non-zero exit
  • watch -e <command> - Exit on error
  • watch -p <command> - Precise timing (attempts to run at exact intervals)
  • watch -x <command> - Execute command with execvp()

Common Examples

Basic Monitoring

watch date

Watch date update every 2 seconds.

Custom Interval

watch -n 1 date

Update every 1 second.

Highlight Differences

watch -d ls -l

Highlight changes in directory listing.

Monitor Processes

watch -n 1 'ps aux | grep process'

Monitor specific processes.

Monitor Disk Usage

watch -n 5 df -h

Monitor disk usage every 5 seconds.

Monitor Network

watch -n 1 'netstat -tuln'

Monitor network connections.

Monitor System Load

watch -n 1 uptime

Monitor system load average.

Monitor Memory

watch -n 1 free -h

Monitor memory usage.

Monitor Temperatures

watch -n 1 sensors

Monitor hardware temperatures in real-time.

No Title Bar

watch -t date

Display without header.

Exit on Change

watch -g 'ls file.txt'

Exit when file appears.


Tips

  • Use -n to set custom update intervals (can use decimals like 0.5)
  • Use -d to highlight what changes between updates
  • Use -t to remove the header for cleaner output
  • Use -g to exit when output changes (useful in scripts)
  • Use quotes for complex commands: watch -n 1 'command with args'
  • Combine with sensors to monitor temperatures: watch -n 1 sensors
  • Use -c to preserve ANSI colors in output
  • Use -p for precise timing when exact intervals matter
  • Press Ctrl+C to exit watch
  • Great for monitoring logs, processes, and system resources