1. View Log common commands tail:-n is the display line number, equivalent to the NL command; examples are as follows:
tail-100f Test.log Real-time monitoring of 100 rows of logs
Tail-n test.log query log at the end of the last 10 lines;
Tail-n +10 test.log Query all logs after 10 lines;
Head
Contrary to tail, tail is the number of rows of logs after the look, examples are as follows:
Head-n test.log Query log file in the first 10 rows of logs;
Head-n -10 test.log query log file except for all other logs in the last 10 lines;
Cat
TAC is in reverse view, is the cat word anti-write;
cat-n test.log |grep "Debug" Query keyword log
2. Application Scenario One: View by line number---filter out logs near keywords
1) cat-n test.log |grep "Debug" to get the line number of the critical log
2) cat-n test.log |tail-n +92|head-n 20 Select the middle row where the keyword is located. Then look at the first 10 lines of this keyword and the next 10 lines of logs:
Tail-n +92 indicates a log after querying 92 rows
Head-n 20 indicates that the first 20 records are checked in the previous query results.
3. Scenario two: Querying logs by 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 printed in the log log, otherwise invalid;
First grep ' 2014-12-17 16:17:20 ' test.log to determine if there is a point in the log
4. Application Scenario Three: The log content is very much, printing on the screen is not easy to view
(1) using the more and less commands,
such as: Cat-n test.log |grep "Debug" |more so that the page printing, by clicking the Space bar to page
(2) Save it to a file using >xxx.txt, then you can pull down this file to analyze
such as: Cat-n test.log |grep "Debug" >debug.txt
Linux View Log Common commands