Linux Search Log Information

Source: Internet
Author: User

In the work we often have to find the problem through the log, but sometimes too many logs and do not know when the log is printed, then we can look at the method:

1. Enter the directory where the log files are stored

2. grep keyword * For example, to find more information about the order grep order * so that you can find out all the order information and which log file

or search Log keywords: cat-n server.log |grep ' keywords '

The line number where you get the ' keyword ' is 50 rows. At this point if I want to see the first 10 lines of this keyword and the last 10 lines of the log:

Cat-n Test.log |tail-n +40|head-n 20

Tail-n +40 indicates a log after querying 40 rows

Head-n 20 indicates that the first 20 records are checked in the previous query results.

3, vi xxx.log into the log file

/order so you can find the location of the order information in Xxx.log

4, the most basic command to find logs

Tail-n server.log query log at the end of the last 10 lines;

Tail-n +10 server.log Query all logs after 10 lines;

Head-n server.log query log file in the first 10 rows of logs;

Head-n -10 server.log query log file except for all other logs in the last 10 lines;

5, by Date: Need to find the log on the specified time end

Sed-n '/2018-06-06 11:30:20/,/2018-06-06 16:17:36/p ' Service.log

The above two date must be the log printed in the log, otherwise invalid.

1. For date printing, you can first grep ' 2018-06-06 16:17:36 ' service.log to determine if there is a point in the log to ensure that you can get the log

2. If we look for a lot of logs, printing on the screen is not easy to view, there are two ways:

(1) Use the more and less commands, such as: cat-n test.log |grep "keyword" |more so that the page printing, by clicking the Space bar to page

(2) using >xxx.txt to save it to a file, you can pull down this file analysis. For example:

Cat-n test.log |grep "keywords" >xxx.txt

Linux Search Log Information

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.