tail keyword query log

Reprinted from https://blog.csdn.net/weixin_41522735/article/details/103223998

Commonly used commands:

tail -f xxx.log ----refresh the latest log in real time
tail -100f xxx.log --------refresh the latest 100 lines of log in real time
tail -100f xxx.log | grep [keyword] --- ----Find the latest 100 lines that match the keyword
tail -100f xxx.log | grep '2019-10-29 16:4[0-9]' ------Find the latest 100 Lines in the time range of 2019-10-29 16:40-2019-10-29 16:49 tail
-1000f xxx.log | grep -A 5 [Keywords] --------- - View the rows matching the keyword among the latest 1000 rows plus the 5 rows after the matching row

tail -1000f xxx.log | grep -A 10 -B 1 [keyword] ----------View the latest 1000 lines that match the keyword plus 1 line before and 10 lines after the matching line

The above are some of the most commonly used parameters and commands for daily viewing of logs. The Linux commands involved are nothing more than tail and grep. Note that all the above commands are read from left to right. The command will first open the file before grep matching the keywords. So sometimes it's not that the matching conditions are written wrong, but that the number of rows you display is too few. The grep command did not match the content you showed. This is also where some people often wonder.

tail: used to view the contents of the file
-f loop reading
-q does not display processing information
-v displays detailed processing information
-c <number> the number of bytes displayed
-n <number of lines> displays the last n lines of the file
– pid=PID is used with -f, which means it will end after the process ID and PID die.
-q, --quiet, --silent never output the header of the given file name.
-s, --sleep-interval=S and -f Used together, it means sleeping for S seconds between each iteration.

grep: used to find strings that meet conditions in files.
-a or --text : Do not ignore binary data.
-A<display number of lines> or --after-context=<display number of lines>: In addition to displaying the column that conforms to the template style, and display the content after the line.
-b or --byte-offset: Mark the number of the first character of the line before displaying the line that matches the style.
-B<display line number> or --before-context=<display line number>: In addition to displaying the line that matches the style, the content before the line is displayed.
-c or --count: Count the number of columns matching the style.
-C<display line number> or --context=<display line number> or -<display line number>: In addition to displaying the line that matches the style, the content before and after the line is also displayed.
-d <action> or --directories=<action>: This parameter must be used when specifying directories rather than files to search, otherwise the grep command will report information and stop the action.
-e<template style> or --regexp=<template style>: Specify a string as the style for searching file content.
-E or --extended-regexp: Use extended regular expression style.
-f<rule file> or --file=<rule file>: Specify a rule file whose content contains one or more rule patterns, allowing grep to find file contents that meet the rule conditions. The format is one rule pattern per line.
-F or --fixed-regexp : Treat styles as a list of fixed strings.
-G or --basic-regexp :
-h or --no-filename: Do not indicate the file name to which the line belongs before displaying the line that matches the style.
-H or --with-filename: Indicates the file name to which the line belongs before displaying the line that matches the style.
-i or --ignore-case: Ignore differences in character case.
-l or --file-with-matches: List the file names whose file contents match the specified pattern.
-L or --files-without-match: List file names whose file contents do not conform to the specified pattern.
-n or --line-number: Before displaying the line that matches the style, indicate the column number of the line.
-o or --only-matching: Display only the matching PATTERN part.
-q or --quiet or --silent: Do not display any information.
-r or --recursive: The effect of this parameter is the same as specifying the "-d recurse" parameter.
-s or --no-messages: Do not display error messages.
-v or --revert-match : Display all lines that do not contain matching text.
-V or --version: Display version information.
-w or --word-regexp: Only display columns that match whole words.
-x --line-regexp: Only display columns that match all columns.
-y: The effect of this parameter is the same as specifying the "-i" parameter.
————————————————
Copyright statement: This article is an original article by CSDN blogger "Suifeng404" and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement when reprinting.
Original link: https://blog.csdn.net/weixin_41522735/article/details/103223998

Guess you like

Origin blog.csdn.net/ZHAI_KE/article/details/130827828