shell分析nginx日志的一些指令

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

前言

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
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: nginxshell