The last 10 lines tail -n 10 test.log query log tail of log;
tail -n +10 test.log query for all logs after 10 rows;
head:
With the tail is the opposite, tail is the number of lines in the log after watching; examples are as follows:
head -n 10 test.log query log file header 10 log lines;
head -n -10 test.log query log file in addition to all other logs the last 10 lines;
cat:
tac is the reverse view, is anti-cat word write; examples are as follows:
cat -n test.log | grep "debug" keyword query log
2. Application Scene One: by line number View --- filtered out near the keyword 'log
1) cat -n test.log | grep "debug" the key to get the log line number
2) cat -n test.log | tail -n +92 | middle of a line head -n 20 keywords you select and then view the log keyword before 1010 rows and rows after:
tail -n +92 indicates that the log after the query line 92
It said head -n 20 in front of the query result 20 before further investigation record
3. Application Scene 2: 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 printed in the Journal log out, otherwise invalid;
First grep '2014-12-17 16:17:20' test.log to determine if the time point of the log
4. Application Scene Three: log contents particularly large, is not convenient to view the print on the screen
(1) use of more and less commands,
Such as: cat -n test.log | grep "debug" | more This will print the page, next page by clicking the spacebar
(2)> xxx.txt save it to a file, when the file may pull Analysis
如:cat -n test.log |grep "debug" >debug.txt