Linux view the log file

1. tail command: start looking from the end of the text file for the end of a few lines of text files

     tail  -n filename to specify how many rows to be displayed    

     tail -f filename  real-time display file contents default to the last 10 lines, representing an increase of parameter -n 10

     50 -f -n tail filename  real-time display 50 lines of the file contents

 

2. Search the log near the keyword 

most commonly used:

cat -n filename | grep "keyword"

 

Other cases:

cat filename | grep -C 5 'keywords' (display logs that match the string line and around 5 lines)

cat filename | grep -B 5 'keywords' (matching string and display the first 5 rows)

cat filename | grep -A 5 'keys' (5 lines, and the string matching)

Guess you like

Origin www.cnblogs.com/nemowang1996/p/11368532.html