如果要持续执行一个命令,然后观察输出的话,我们一遍一遍的按上回车,然后看着输出。watch命令可以很好的实现这个功能。比如,要监控linux的连接数:
- watch -n 2 -d 'netstat -est | grep est'
输出:
- Every 2.0s: netstat -est | grep est Mon Mar 19 10:46:03 2012
-
- 12784 connections established
- 556 packets rejects in established connections because of timestamp
- 2015 congestion windows fully recovered without slow start
- 9672 congestion windows partially recovered using Hoe heuristic
- 20983 congestion windows recovered without slow start by DSACK
- 22010 congestion windows recovered without slow start after partial ack
-n指定命令执行的时间间隔,-d高亮显示连续两侧输出的差别,为了便于观察,最后一个参数是要执行的命令。