Home > Package & System Management > watch

watch: Monitor command output periodically

The watch command executes a specified command periodically and displays its output in full screen. It is useful for real-time monitoring of system logs, process status, file changes, and more.

Overview

The watch command refreshes and displays the output of a specific command periodically in the terminal. By default, it updates every 2 seconds and offers various options such as setting the interval and highlighting changes.

Key Features

  • Real-time monitoring
  • Periodic automatic updates
  • Highlighting changes
  • Full-screen display of command output

Key Options

Execution Control and Display

Generated command:

Try combining the commands.

Description:

`watch` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Basic Usage (Every 2 Seconds)

watch 'ls -l'

Refreshes and displays the file list in the current directory every 2 seconds.

Monitor Disk Usage Every 5 Seconds

watch -n 5 'df -h'

Checks disk usage (df -h) by updating every 5 seconds.

Monitor Log File with Highlighted Changes

watch -d 'tail -n 10 /var/log/syslog'

Monitors the last 10 lines of a log file, highlighting new content as it's added.

Real-time CPU Usage Monitoring (No Title)

watch -t 'cat /proc/loadavg'

Checks the system's load average (loadavg) in real-time without the title.

Monitor Network Connection Status

watch -n 1 'netstat -tulnp'

Monitors currently open network ports and connection status every 1 second.

Tips & Precautions

The watch command is very useful for understanding system status in real-time.

Useful Combinations

Commonly used watch command combinations.

  • watch -d 'ls -l' (Real-time file change monitoring)
  • watch -n 1 'ps aux | grep [c]ommand' (Monitor specific process status)
  • watch -d 'ip a' (Detect network interface status changes)
  • watch -n 1 'free -h' (Real-time memory usage monitoring)

Precautions

Since watch repeatedly executes commands, be careful not to use commands that consume excessive system resources. In particular, commands with heavy network requests or disk I/O can cause system load.


Same category commands