--- title: watch โ€” monitor repeated output date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: A tool that repeatedly runs a command at regular intervals and continuously displays changes on the screen. tags: program, Automation and scheduled tasks, watch --- **๐Ÿ’ฌ "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 | Option | Description | | --- | --- | | -n | Specifies the refresh interval | | -d | Highlights differences | | -t | Hides the top header | | -g | Exits 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](https://games.aidebatehub.com/assets/watch-demo.png) 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.