Shell分析日志文件高效命令,超级好用!

自己的小网站跑在阿里云的ECS上面,偶尔也去分析分析自己网站服务器日志,看看网站的访问量。看看有没有黑客搞破坏!于是收集,整理一些服务器日志分析命令,大家可以试试!

Shell 分析日志文件高效命令,超级好用!

1、查看有多少个IP访问:

awk '{print $1}' log_file|sort|uniq|wc -l登录后复制

grep "/index.php" log_file | wc -l登录后复制

awk '{++S[$1]} END {for (a in S) print a,S[a]}' log_file > log.txt sort -n -t ' ' -k 2 log.txt # 配合sort进一步排序登录后复制

awk '{++S[$1]} END {for (a in S) print S[a],a}' log_file | sort -n登录后复制

grep ^111.111.111.111 log_file| awk '{print $1,$7}'登录后复制

awk '{print $12,$1}' log_file | grep ^"Mozilla | awk '{print $2}' |sort | uniq | wc -l登录后复制

awk '{print $4,$1}' log_file | grep 16/Aug/2015:14 | awk '{print $2}'| sort | uniq | wc -l登录后复制

awk '{print $1}' |sort|uniq -c|sort -nr |head -10 access_log登录后复制

cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10 cat access.log|awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}登录后复制

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登录后复制

cat access.log | awk '{print $11}' | sed -e ' s/http:////' -e ' s//.*//' | sort | uniq -c | sort -rn | head -20登录后复制

cat www.access.log |awk '($7~/.php/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -100登录后复制

cat www.access.log |awk '($10 > 200000 && $7~/.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100登录后复制

cat www.access.log |awk '($7~/.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100登录后复制

cat www.access.log |awk '($NF > 60 && $7~/.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100登录后复制

cat www.access.log |awk '($NF > 30){print $7}'|sort -n|uniq -c|sort -nr|head -20登录后复制

ps -ef | awk -F ' ' '{print $8 " " $9}' |sort | uniq -c |sort -nr |head -20登录后复制

对比httpd.conf中MaxClients的数字差距多少

netstat -an | grep ESTABLISHED | wc -l登录后复制

ps -ef|grep httpd|wc -l 1388登录后复制

netstat -nat|grep -i "80"|wc -l 4341登录后复制

netstat -na|grep ESTABLISHED|wc -l 376登录后复制

netstat -nat||grep ESTABLISHED|wc登录后复制

19、输出每个ip的连接数,以及总的各个状态的连接数

netstat -n | awk '/^tcp/ {n=split($(NF-1),array,":");if(n 60 && $7~/.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100登录后复制统计网站流量(G)

往期精彩

登录后复制登录后复制

Shell 分析日志文件高效命令,超级好用!

喜欢本文的朋友们,欢迎长按下图,关注订阅号Linux中文社区

收看更多精彩内容