- 列出當天通路次數最多的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
selectonly these fields; also print any line that contains no
delimiter character, unless the -s option is specified
表示列印第一部分,就是ip
uniq 是将重複行去掉, -c表示前面加上數目,
sort -rn 就是按照數字從大到小排序,
head -20取前面20行
- 檢視當天有多少個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
- 将每個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}'