shell 之 Nginx:统计 nginx 日志里访问次数最多的前 10 个 IP

[root@localhost sa]# cat /var/log/nginx/access.log |cut -d " " -f 1 |sort |uniq -c |sort -nr |head -n 10

        30  172.16.39.211
        29  172.16.39.216
        27  172.16.39.215
        27  172.16.39.212
        26  172.16.39.213
        26  172.16.39.131
        26  172.16.39.132
        26  172.16.39.133
        25  172.16.39.134
        21  172.16.39.138

使用 awk 命令过滤:

[root@localhost sa]# cat /var/log/nginx/access.log |awk -F ' ' '{print $1}' |sort |uniq -c |sort -nr |head -n 10

        30  172.16.39.211
        29  172.16.39.216
        27  172.16.39.215
        27  172.16.39.212
        26  172.16.39.213
        26  172.16.39.131
        26  172.16.39.132
        26  172.16.39.133
        25  172.16.39.134
        21  172.16.39.138

posted @ 2024-07-01 10:18  CharyGao  阅读(22)  评论(0)    收藏  举报