如果要持續執行一個命令,然后觀察輸出的話,我們一遍一遍的按上回車,然后看著輸出。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高亮顯示連續兩側輸出的差別,為了便于觀察,最后一個參數是要執行的命令。