分类: 系统运维
2015-09-08 11:28:08
netstat -n | awk '/^tcp/{print $5}' | awk -F: '!/^::/{print $1}' | sort | uniq -c | sort -rn | awk 'BEGIN{printf "%-10s%s\n","ConNum","IP"}{printf "%-10s%s\n",$1,$2}'
netstat -n 拒绝显示别名,能显示数字的全部转化成数字
'/^tcp/{print $5}' 打印以tcp开头行的第5列
awk -F: '!/^::/{print $1}' 以:作为分隔符,且去掉::,打印第一列
uniq -c 在输出行前面加上每行在输入文件中出现的次数
sort -rn 逆序,以数值来排序
awk 'BEGIN{printf "%-10s%s\n","ConNum","IP"}{printf "%-10s%s\n",$1,$2}' 开头增加一行ConNum IP,"-"左对齐,"10s"字符串占用10列