用 watch -d 定时重跑命令并高亮变化
watch 按间隔反复运行命令,-d 会高亮两次刷新之间的差异——一个简易的实时监控面板。
运行 `watch -d -n 2 free -h` 每 2 秒刷新一次内存使用并以高亮显示变化,按 Ctrl+C 或 q 退出。
01命令
命令
$ watch -d -n 2 free -h02作用说明
watch 会接管终端并清屏,按 -n 指定的间隔(默认 2 秒)反复运行给定命令,把任何一次性命令变成实时监控。-d 高亮自上次刷新以来发生变化的内容,`-d=cumulative` 则持续高亮所有曾经变化过的部分。注意引号:整条管道都要传给 watch,例如 `watch -n 5 'df -h / | tail -1'`。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- watch(1) - execute a program periodically依据: watch runs command repeatedly, showing its output and errors; -d, --differences highlights the changes; -n, --interval seconds specifies the update interval.
最后验证: 2026-09-17 · 分类: 系统与设置