Linux log query skills

Large log files find log
    split command to split log files
   
split -1000 xxx.log newlog

    Then
    combine the inquiry warning and other information
   
cat start.log | grep WARNING

    Regular expression query information
   
cat start.log | grep [0-9][0-9]

-Reference :
1.tail (used to display the content at the end of the specified file)
tail [ -f ] [ -c Number | -n Number | -m Number | -b Number | -k Number ] [ File ]
    Parameter explanation:
        -f the The parameter is used to monitor File file growth.
        -c Number Reads the specified file from Number byte positions
        -n Number Reads the specified file from Number line positions.
        -m Number Read the specified file from the Number multi-byte character position. For example, if your file contains Chinese characters, if you specify the -c parameter, it may cause truncation, but using -m will avoid this problem.
        -b Number Reads the specified file from the 512-byte block position represented by Number.
        -k Number Reads the specified file from the 1KB block position represented by Number.
    Example:
       
tail -f start.log

    You can view the last few lines of the residual log, you can also query the log in real time, and finally ctrl+c ends

2. more (you can view the content of the file by page, and also support functions such as direct line jumping)
more [-dlfpcsu ] [- num ] [+/ pattern] [+ linenum] [file ... ]
    Parameter explanation:
        +n start display from the nth line
        -n ​​define the screen size to n lines
        +/pattern Search for the string before each file is displayed ( pattern), then start to display
        -c from the top two lines after the string, then display
        -d to prompt "Press space to continue, 'q' to quit (press space to continue, press q to quit)", Disable the bell function
        -l ignore Ctrl+l (form feed) characters
        -p Form the file by clearing the window instead of scrolling, similar to the -c option
        -s Display consecutive blank lines as one line
        -u Put The underline in the file content removes the
        common operation commands:
        Enter N lines down, need to be defined. The default is 1 line
        Ctrl+F Scroll down one screen
        Spacebar Scroll down one screen
        Ctrl+B Return to the previous screen
        = Output the line number of the current line
        : f Output the file name and the line number of the current line
        V Call the vi editor
        ! Command Call the Shell, and execute the command
        q to exit the more
    instance:
       
more +12 start.log

    Query the log

3.cat after 12 lines (usually used to display file content, or to connect several files to display, or to read and display content from standard input, it is often used in conjunction with redirection symbols.)
    Parameter explanation:
        -A , --show-all is equivalent to -vET
        -b, --number-nonblank number of non-blank output lines
        -e is equivalent to -vE
        -E, --show-ends show $
        -n at the end of each line, --number Number all output lines, start from 1 to number all output lines
        -s, --squeeze-blank If there are more than two consecutive blank lines, replace them with a blank line
        -t and -vT Equivalent
        to -T, --show-tabs Display tab characters as ^I
        -u (ignored)
        -v, --show-nonprinting Use ^ and M- quoting, except for LFD and TAB
    instances
       
cat start.log

    Display start.log
4.less (log view and search)
    parameter explanation:
        -b <buffer size> Set the size of the buffer
        -e When the file is displayed, leave automatically
        -f Force to open special files, such as peripheral device code, Directories and binary files
        -g only mark the last keyword searched
        -i ignore case when searching
        -m display percentages similar to more commands
        -N display the line number of each line
        -o <file name> put the output of less in the specified Save it in the file
        -Q Do not use warning sound
        -s Display continuous blank lines in one line
        -S If the line is too long, the excess part will be discarded
        -x <number> Display the "tab" key as the specified number space

    Common operation commands:
        j - to move forward one line
        k - move backward one line
        G - move to last line
        g - move to first line
        q/ZZ - exit less command
        /string: function to search down "string"
        ? string: search up "character" string" function
        n: repeat the previous search (related to / or ?)
        N: repeat the previous search in reverse (related to / or ?)
        b turn back one page
        d turn back half a page
        h display the help interface
        Q exit
        the less command u Scroll forward half a page
        y Scroll forward one line
        Spacebar scroll one line
        Enter key Scroll one page
        [pagedown]: Scroll down one page
        [pageup]: Scroll up one page
        ctrl + F - move forward one screen
        ctrl + B - go up Move backward one screen
        ctrl + D - move half screen forward
        ctrl + U - move half screen backward

        v - edit current file with configured editor
        h - show help for less
        &pattern - show only lines matching the pattern, not Entire file
        When viewing large files with less, you can mark any position, you can navigate to the text position marked with a specific mark by command:
        ma - use a to mark the current position of the text
        'a - navigate to the

    instance at marker a
      
less start.log


5.vi
    common operation commands:
        h: move the cursor one character to the left
        l: move the cursor one character to the right
        space: move the cursor one character to the right
        Backspace: move the cursor one character to the left
        k or Ctrl+p: move the cursor up a line
        j or Ctrl+n : Move the cursor down one line
        Enter : Move the cursor down one line
        w or W : Move the cursor right one word to the prefix
        b or B : Move the cursor left one word to the prefix
        e or E : Move the cursor right one word to the end of the word
        ) : Cursor Move to the end of the sentence
        ( : move the cursor to the beginning of the sentence
        }: move the cursor to the beginning of the paragraph
        {: move the cursor to the end of the paragraph
        nG: move the cursor to the beginning of the nth line
        n+: move the cursor down n lines
        n-: move the cursor up n lines
        n $: move the cursor to the end of the nth line
        H: move the cursor to the top line of the screen
        M: move the cursor to the middle line of the screen
        L: move the cursor to the last line of the screen
        0: (note the number zero) move the cursor to the beginning of the current line
        $: cursor move to end of current line
    Example
      
we start.log


6. spilt
split [-n] file [name]
parameter explanation: -n: specify the length of each file to be truncated
, if not specified, the default is 1000 lines The initial letter of the file, if not specified, defaults to x, that is, the file name of the file generated after truncation is xaa, xab....until xzz instance



split -50 start.log start_child


Generate: start_childaa start_childab....

7.grep
grep [options]
    parameter explanation
        -c: only output the count of matching lines.
        -I: Case insensitive (only applies to single characters).
        -h: Do not display file names when querying multiple files.
        -l: When querying multiple files, only output file names that contain matching characters.
        -n: Display matching lines and line numbers.
        -s: Do not display error messages for nonexistent or no matching text.
        -v: Display all lines that do not contain matching text.
        The main parameters of pattern regular expression:
        \: Ignore the original meaning of special characters in the regular expression.
        ^: Matches the starting line of the regular expression.
        $: Matches the end line of the regular expression.
        \<: Starts on a line matching the regular expression.
        \>: to end of line matching regular expression.
        [ ]: A single character, such as [A] that A meets the requirements.
        [ - ]: Range, such as [AZ], that is, A, B, C up to Z all meet the requirements.
        . : All single characters.
        * : There are characters, the length can be 0.
    example
       
history | grep cp

        Query the usage history of the cp command
      

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327046346&siteId=291194637
Recommended