Linux运维常用命令
tingting 2016-12-17 5566 查看 0评论 公开 原文 举报 取精添加收藏 自己的小网站跑在阿里云的ECS上面,偶尔也去分析分析自己网站服务器日志,看看网站的访问量。看看有没有黑阔搞破坏!于是收集,整理一些服务器日志分析命令,大家可以试试!1、查看有多少个IP访问:
- awk '{print $1}' log_file|sort|uniq|wc -l
PS: wc -l 看看有多少行
2、查看某一个页面被访问的次数:
- grep "/index.php" log_file | wc -l
3、查看每一个IP访问了多少个页面:
- awk '{++S[$1]} END {for (a in S) print a,S[a]}' log_file > log.txt
- sort -n -t ' ' -k 2 log.txt # 配合sort进一步排序
4、将每个IP访问的页面数进行从小到大排序:
- awk '{++S[$1]} END {for (a in S) print S[a],a}' log_file | sort -n
5、查看某一个IP访问了哪些页面:
- grep ^111.111.111.111 log_file| awk '{print $1,$7}'
6、去掉搜索引擎统计的页面:
- awk '{print $12,$1}' log_file | grep ^\"Mozilla | awk '{print $2}' |sort | uniq | wc -l
7、查看2015年8月16日14时这一个小时内有多少IP访问:
- awk '{print $4,$1}' log_file | grep 16/Aug/2015:14 | awk '{print $2}'| sort | uniq | wc -l
8、查看访问前十个ip地址
awk '{print $1}' |sort|uniq -c|sort -nr |head -10 access_log
uniq -c 相当于分组统计并把统计数放在最前面
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<a href="http://www.lai18.com/content/,%20url%7D%3C/pre%3E%3Cbr/%3E%3Cbr/%3E9%E3%80%81%E8%AE%BF%E9%97%AE%E6%AC%A1%E6%95%B0%E6%9C%80%E5%A4%9A%E7%9A%8410%E4%B8%AA%E6%96%87%E4%BB%B6%E6%88%96%E9%A1%B5%E9%9D%A2%3Cbr/%3E%3Cbr/%3E%3Cpre%20class='brush:bash;'%3Ecat%20log_file%7Cawk%20'%7Bprint%20$11%7D'%7Csort%7Cuniq%20-c%7Csort%20-nr%20%7C%20head%20-10%20cat%20log_file%7Cawk%20'%7Bprint%20$11%7D'%7Csort%7Cuniq%20-c%7Csort%20-nr%7Chead%20-20%20awk%20'%7Bprint%20$1%7D'%20log_file%20%7Csort%20-n%20-r%20%7Cuniq%20-c%20%7C%20sort%20-n%20-r%20%7C%20head%20-20%20# 访问量最大的前20个ip</pre><br/><br/>10、通过子域名访问次数,依据referer来计算,稍有不准<br/><br/><pre class='brush:plain;'>cat access.log | awk '{print $11}' | sed -e ' s/http:\/\///' -e ' s/\/.*//' | sort | uniq -c | sort -rn | head -20</pre><br/><br/>11、列出传输大小最大的几个文件<br/><br/><pre class='brush:plain;'>cat <a href=" http:="" www.access.log"="" target="_blank" style="color: rgb(0, 166, 124); text-decoration: none;">www.access.log" target=_blank>, url}
- cat access.log | awk '{print $11}' | sed -e ' s/http:\/\///' -e ' s/\/.*//' | sort | uniq -c | sort -rn | head -20
- <a href=", url}</pre><br/><br/>9、访问次数最多的10个文件或页面<br/><br/><pre class='brush:bash;'>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 # 访问量最大的前20个ip</pre><br/><br/>10、通过子域名访问次数,依据referer来计算,稍有不准<br/><br/><pre class='brush:plain;'>cat access.log | awk '{print $11}' | sed -e ' s/http:\/\///' -e ' s/\/.*//' | sort | uniq -c | sort -rn | head -20</pre><br/><br/>11、列出传输大小最大的几个文件<br/><br/><pre class='brush:plain;'>cat <a href=" http:="" www.access.log"="" target="_blank">cat [url=http://www.access.log]www.access.log</a> |awk '($7~/\.php/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -100
- cat [url=http://www.access.log]www.access.log |awk '($10 > 200000 && $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100
- cat <a href="http://www.access.log" target="_blank">www.access.log</a> |awk '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100
- cat <a href="http://www.access.log" target="_blank">www.access.log</a> |awk '($NF > 60 && $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100
- cat <a href="http://www.access.log" target="_blank">www.access.log</a> |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
- netstat -an | grep ESTABLISHED | wc -l
- ps -ef|grep httpd|wc -l
- netstat -nat|grep -i "80"|wc -l
- netstat -na|grep ESTABLISHED|wc -l
- netstat -nat||grep ESTABLISHED|wc
- cat access.log |grep '04/May/2012'| awk '{print $11}'|sort|uniq -c|sort -nr|head -20
- cat access_log | awk '($11~/\www.abc.com/){print $1}'|sort|uniq -c|sort -nr
- cat linewow-access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10
- cat log_file | egrep '15/Aug/2015|16/Aug/2015' |awk '{print $1}'|sort|uniq -c|sort -nr|head -10
- cat log_file | egrep '15/Aug/2015|16/Aug/2015' | awk '{if($7 == "/index.php?g=Member&m=Public&a=sendValidCode") print $1,$7}'|sort|uniq -c|sort -nr
- cat log_file |awk '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100
- cat access.log |awk '($NF > 60 && $7~/.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100
- cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}'