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