AI Crawler · Collection Records

Bot summary · Last 24 hours

watch — monitor repeated output

A tool that repeatedly runs a command at regular intervals and continuously displays changes on the screen.
Markdown source·Anything to add or correct?

💬 "watch command"

watch periodically re-executes a command and shows changes. It is convenient for observing progress.

The default interval is 2 seconds, and you can adjust it with -n.

  • Concept: Periodically refreshes and displays command output.
  • -n: Specifies the interval in seconds.
  • -d: Highlights changed parts.
  • Top: Shows the running command and the current time.

Commonly Used Options

OptionDescription
-n <seconds>Specifies the refresh interval
-dHighlights differences
-tHides the top header
-gExits when output changes (for scripts)

Three Essential Command Combinations

  • watch -n 2 'ss -lntp | grep :443' — Observe port 443 status
  • watch -d -n 1 'df -h /var' — Observe changes in disk usage
  • watch -n 5 'pgrep -c -f queue:work' — Observe changes in worker count

💬 "Tell me examples I can use even with an unprivileged account"

Here are common situations on live production servers, arranged in order.

Step 1 · Start Observing

Wrap the command you want to check with watch.


watch -n 2 'ss -lntp | grep :443'

Step 2 · Highlight Changes

Use -d to highlight differences.


watch -d -n 1 'df -h /var'

Step 3 · Exit

When you're done, press Ctrl+C to exit.


Ctrl+C

How It Is Used in Practice

1. Observing Connection Count During Deployment

Situation — You want to see how active connections change during deployment.


watch -n 2 "ss -s | grep estab"

Result — You can monitor changes in the active connection count in real time.

Point — Compare baseline values before and after deployment to judge sudden drops or spikes.

2. Checking Disk Growth Trend

Situation — You want to know how fast logs are filling up.


watch -d -n 5 'df -h /var && du -sh /var/log/nginx'

Result — The highlighted values let you immediately sense the growth rate.

Point — Use the growth rate to decide the log rotation interval.

Things to Watch Out For

  • If the interval is too short, it can cause load, so adjust -n.
  • Commands inside watch go through the shell, so be careful with quoting.
  • For automated decisions, use a condition-checking script rather than watch.

Actual Output Screen

This is the result of observing TCP connection status every 2 seconds.

!watch command execution result: repeated observation of connection status

Live production server


Source (HTML): https://games.aidebatehub.com/programs/linux/automation/watch.html This file is an auto-generated Markdown twin of the DevHub document.

Visitor Comments

Loading…
💬 Comments: 0 · Author type: human | Built: 2026-10-30T20:31:00+09:00