1 | awk '{c[$1]++;}END{for(k in c){print k": "c[k];}}' /var/log/nginx/myalert_access.log |
统计IP访问次数
示例1
myalert_access日志格式如下:
1 | 116.7.8.112 - - [14/Jun/2020:18:08:06 +0000] "GET / HTTP/1.1" 302 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-" |
统计:
1 | awk '{c[$1]++;}END{for(k in c){print k": "c[k];}}' /var/log/nginx/myalert_access.log |
示例2
日志:1
Nov 25 13:33:03 VM_0_13_centos sshd[9327]: Invalid user ftp_user from 1.213.195.154 port 37113
统计:1
2
3
4
5[root@VM_0_13_centos ~]# awk '{a[$1]+=1;}END{for(i in a){print a[i]" "i;}}' /var/log/secure
1532 Sep
12542 Nov
3895 Oct
107725 Aug
关联查询
从 ll
命令的结果筛选出Documents Downloads Pictures的行:
1 | [root@kafka-1 ~]# ll |
从文件 score
中查找a c e的记录:
1 | [root@localhost code]# cat score |
列出已挂载的磁盘
1 | [root@kafka-1 ~]# lsblk |