Three commands for viewing logs in Linux and logs in linux
First: View logs of real-time changes (more memory-consuming)
Most commonly used:
Tail-f filename (the last 10 rows by default, which is equivalent to adding the parameter-n 10)
Ctrl + c is the exit command
Other cases:
Tail-n 20 filename (display the last 20 rows of filename)
Tail-n + 5 filename (the file is displayed starting from row 5th)
Type 2: Search logs near keywords
Most commonly used:
Cat-n filename | grep "keyword"
Other cases:
Cat filename | grep-C 5 'keyword' (display the line matching the string in the log and the first and last five rows)
Cat filename | grep-B 5 'keyword' (show matching strings and the first five rows)
Cat filename | grep-A 5' keyword '(the matching string and the last 5 rows are displayed)
Third: Enter edit search: vi (vim)
1. Enter the vim editing mode: vim filename
2. enter "/keyword" and press enter to search
3. Find the next one and press "n ".
Exit: Press ESC, and then enter the number. vi will wait for us to enter the command at the bottom of the screen.
Wq! Save and exit;
Q! Do not save and exit;
Other cases:
/KeywordsNote: forward lookup: Press n to move the cursor to the next matching position.
?KeywordsNote: For reverse search, press shift + n to move the cursor to the next qualified