Linux View Log Common commands __linux

Source: Internet
Author: User
1. View Log common commands tail:-n is the display line number; the equivalent of the NL command; tail-100f test.log Real-time monitoring of 100-line logs

Tail-n test.log Query Log The last 10 lines of the tail;

Tail-n +10 test.log to query all logs after 10 rows;

Head

Contrary to the tail, tail is the number of rows after the log; examples are as follows:

Head-n test.log Query log file in the first 10 lines of log;

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

Cat

TAC is the reverse view, is the cat word reverse write;

Cat-n test.log |grep Log of "debug" query Keywords


2. Application Scene One: by line number View---Filter the log near the key word

1 cat-n test.log |grep "Debug" to get the line number of the key log

2 cat-n test.log |tail-n +92|head-n 20 Select the middle line where the keyword is located. Then look at the logs for the first 10 and 10 lines of this keyword:

Tail-n +92 indicates that the log after 92 rows is queried

Head-n 20 means to check the previous 20 records in the previous query results.


3. Application Scenario Two: query log based on date

Sed-n '/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p ' Test.log

Special Note: The above two dates must be the log printed in the log, otherwise invalid;

First grep ' 2014-12-17 16:17:20 ' test.log to determine if the time point in the log


4. Application scenario Three: Log content is very much, print on the screen is not convenient to view

(1) using the more and less commands,

such as: Cat-n test.log |grep "Debug" |more so that pagination printing, by clicking the Space bar page

(2) Use >xxx.txt to save it to a file, and then you can pull down this file to analyze

such as: Cat-n test.log |grep "Debug" >debug.txt



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.