Shell+linux Command Implementation log Analysis _linux Shell

Source: Internet
Author: User

The IP that lists the most visited times of the day
command:

Copy Code code as follows:
Cut-d--F 1/usr/local/apache2/logs/access_log |uniq-c | Sort-rn | Head-20

Principle:
Copy Code code as follows:

       cut
       -D,--delimiter=delim
               Use Delim instead's TAB for field delimiter
          &nb sp;   represented by-split, then-F 1
       F,--fields=list
     ;          Select only this fields;  also print any contains  No
              delimiter character, unless the-s option is specified
           means print first part , that is, the IP
 uniq is the duplicate row is removed,-c means the front plus number,
       sort-rn is sorted by number from large to small,
&nbs p;      head-20 Take the front 20 lines

The last printed result is probably this:
Copy Code code as follows:
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

The following are shell usages of some of the other analysis logs:

1, see how many IP access on the day:

Copy Code code as follows:
awk ' {print $} ' log_file|sort|uniq|wc-l

2. View the number of times a page has been visited;

Copy Code code as follows:
grep "/index.php" Log_file | Wc-l

3, see how many pages per IP access:

Copy Code code as follows:
awk ' {++s[$1]} end {for (a in S) print A,s[a]} ' log_file

4, each IP access to the number of pages from small to large sort:

Copy Code code as follows:
awk ' {++s[$1]} end {for (a in S) print S[a],a} ' log_file | Sort-n

5, look at an IP access to which pages:

Copy Code code as follows:
grep ^111.111.111.111 log_file| awk ' {print $1,$7} '

6, remove the search engine statistics on the day of the page:

Copy Code code as follows:
awk ' {print $12,$1} ' log_file | grep ^\ "Mozilla | awk ' {print $} ' |sort | Uniq | Wc-l

7, view June 21, 2009 14 o'clock in the one hours of the number of IP access:

Copy Code code as follows:
awk ' {print $4,$1} ' log_file | grep 21/jun/2009:14 | awk ' {print $} ' | Sort | Uniq | Wc-l

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.