IT虾米网

shell分析nginx日志的一些指令

银河舰队 2022年11月07日 程序员 125 0

前言

nginx日志格式默认

shell指令

  • 查看有多少个IP访问:
awk '{print $1}' log_file|sort|uniq|wc -l 
  • 查看某一个页面被访问的次数:
grep "/index.php" log_file | wc -l 
  • 查看每一个IP访问了多少个页面:
awk '{++S[$1]} END {for (a in S) print a,S[a]}' log_file > log.txt 
# 配合sort进一步排序 
sort -n -t ' ' -k 2 log.txt 
  • 将每个IP访问的页面数进行从小到大排序:
awk '{++S[$1]} END {for (a in S) print S[a],a}' log_file | sort -n 
  • 查看某一个IP访问了哪些页面:
grep ^111.111.111.111 log_file| awk '{print $1,$7}' 
  • 查看2015年8月16日14时这一个小时内有多少IP访问:
awk '{print $4,$1}' log_file | grep 16/Aug/2015:14 | awk '{print $2}'| sort | uniq | wc -l 
  • 查看访问前10的IP:
awk '{print $1}' |sort|uniq -c|sort -nr |head -10 access_log 
  • 访问次数最多的10个文件或页面:
cat log_file|awk '{print $11}'|sort|uniq -c|sort -nr | head -10 
cat log_file|awk '{print $11}'|sort|uniq -c|sort -nr|head -20 
awk '{print $1}' log_file |sort -n -r |uniq -c | sort -n -r | head -20  

本文参考链接:https://www.cnblogs.com/XY-Heruo/p/15352919.html
评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

Java多线程中Lock锁如何使用