1, to display its contents
vi file.txt view the contents of the file
ctrl + d: a half turn to the end of the file screen
ctrl + u: to turn the first half screen file
ctrl + f: a turn to the end of the file screen
ctrl + b: first turned to the document a screen
/ xxxx: look down, input / xxxx, carriage return, find
xxxx:? look up
n: find records that contain keyword down, scroll, locate the cursor to the corresponding position
N: look up, i.e., input N + Shift
2, by keyword search log
CAT file.txt | grep 'Exceptions'
CAT -n file.txt | grep' Exceptions': search results are displayed line number
cat file.txt | grep -n -B5 -A5 ' exceptions ': shows the keywords corresponding to N lines in the log before and after recording, and the line numbers
cat -n file.txt | grep' exceptions' > log_exceptions.txt: redirected to the search results log_exceptions.txt, the file in the same directory
cat - n file.txt | grep 'at' | less:
screen to view the current log in, use the Enter or down arrows control file display (small size) of the screen line by line, with a space to turn the screen (large size)
has been flashing in the lower left corner the cursor, enter q, enter exit
cat -n file.txt | grep 'at' | more:
screen to view the current log in, use the Enter or down arrows control file display (small size) of the screen line by line, with a space to turn the screen (large size)
turn to file the tail end of the event automatically, exit
3, the cursor is displayed and hide the cursor
echo -e "\ 033 [25h? ": display cursor
echo -e "\ 033 [25l? ": hide the cursor
4, query logs within a time frame
-n Sed '/ 2019-11-05 22:46:04 /, / 2019-11-05 22 is: 46 is: 09 / P' file.txt
Sed -n '/ 2019-11-05 22 is: 46 is: 04 / , / 2019-11-05 22: 46: 09 / p 'file.txt | grep' DEBUG '
the above query time, log contains the keyword
sed -n' / 2019-11-05 22: 46 : 04 / , / 2019-11-05 22: 46: 09 / p 'file.txt | grep -n -B5 -A5' DEBUG '
query time within the above range, the log contains the keyword, and display the records corresponding to N lines of the log before and after
5 , view real-time log
tail -f file.txt
6, tail in blocks view the log
tail -n 10 file.txt: query log tail of the last 10 lines of the log
tail -n +10 file.txt: beginning of the file, the query log after all the 10 lines
head -n 10 file.txt: the first 10 lines of the log file query head
head -n -10 file.txt: Polling in addition to all other logs of the last 10 lines