如果要持續(xù)執(zhí)行一個命令,然后觀察輸出的話,我們一遍一遍的按上回車,然后看著輸出。watch命令可以很好的實現(xiàn)這個功能。比如,要監(jiān)控linux的連接數(shù):
- 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指定命令執(zhí)行的時間間隔,-d高亮顯示連續(xù)兩側(cè)輸出的差別,為了便于觀察,最后一個參數(shù)是要執(zhí)行的命令。