列出當(dāng)天訪問次數(shù)最多的IP
命令:cut -d- -f 1 /usr/local/apache2/logs/access_log |uniq -c | sort -rn | head -20
原理:
cut
-d, --delimiter=DELIM
use DELIM instead of TAB for field delimiter
表示用-分割,然后-f 1
-f, --fields=LIST
select only these fields; also print any line that contains no
delimiter character, unless the -s option is specified
表示打印第一部分,就是ip
uniq 是將重復(fù)行去掉, -c表示前面前面加上數(shù)目,
sort -rn 就是按照數(shù)字從大到小排序,
head -20取前面20行
最后打印的結(jié)果大概是這樣:
217 192.114.71.13
116 124.90.132.65
108 192.114.71.13
102 194.19.140.96
101 217.70.34.173
100 219.235.240.36
以下是其他一些分析日志的shell用法:
1、查看當(dāng)天有多少個(gè)IP訪問:awk '{print $1}' log_file|sort|uniq|wc -l2、查看某一個(gè)頁(yè)面被訪問的次數(shù);grep "/index.php" log_file | wc -l3、查看每一個(gè)IP訪問了多少個(gè)頁(yè)面:awk '{++S[$1]} END {for (a in S) print a,S[a]}' log_file4、將每個(gè)IP訪問的頁(yè)面數(shù)進(jìn)行從小到大排序:awk '{++S[$1]} END {for (a in S) print S[a],a}' log_file | sort -n5、查看某一個(gè)IP訪問了哪些頁(yè)面:grep ^111.111.111.111 log_file| awk '{print $1,$7}'6、去掉搜索引擎統(tǒng)計(jì)當(dāng)天的頁(yè)面:awk '{print $12,$1}' log_file | grep ^\"Mozilla | awk '{print $2}' |sort | uniq | wc -l7、查看2009年6月21日14時(shí)這一個(gè)小時(shí)內(nèi)有多少IP訪問: awk '{print $4,$1}' log_file | grep 21/Jun/2009:14 | awk '{print $2}'| sort | uniq | wc -l
聯(lián)系客服