两种方法:
- awk 统计
$ ss -a|grep '^tcp'|awk '{ ++State[$2] } END { for (i in State) print i,State[i] }'
LISTEN 60
ESTAB 712
TIME-WAIT 1668
- sort + uniq 统计
$ ss -a|grep '^tcp'|awk '{print $2}'|sort|uniq -c|sort -rn
1471 TIME-WAIT
713 ESTAB
60 LISTEN