Linux view log command

1. cat command:

     Function: 1) Display the entire file.

                   Example: $ cat fileName

              2) Concatenate the file string and pass it to the basic output, such as combining several files into one file or outputting to the screen.

                   Example: $ cat file1 file2 > file

     Description: Concatenate the file string and transfer it to the basic output (screen or add > fileName to another file)
     cat parameter detailed explanation:
      -n or –number start from 1 to number all output
      lines- b or –number-nonblank is similar to -n, except that the blank line is not numbered
      -s or –squeeze-blank When encountering a blank line with more than two consecutive lines, it is replaced with a blank line of one line
      -v or –show -nonprinting

2. The more command:

     View the log in the form of a percentage.    

 

3. The less command:

     similar to the more function, except that less supports flipping through files before and after.

 

4. The head command:

     Function: View from the head of the text file. The head command is used to view the beginning of a text file.

     The example is as follows:
      head example.txt displays the first ten lines of the file example.txt;
      head -n 20 example.txt displays the first twenty lines of the file example.txt;
      head details:
      -n specifies how many lines of text you want to display.
      -n number This parameter option must be a decimal integer, which will determine the position in the file, in rows.
      -c number This parameter option must be a decimal integer, it will determine the position in the file, in bytes.

5. The tail command:

     Function: The tail command is used to display the last few lines of a text file.

     The examples are as follows:

     tail example.txt displays the last ten lines of the file example.txt;
      tail -n 20 example.txt displays the last twenty lines of the file example.txt;
      tail -f example.txt displays the last ten lines of the file example.txt Ten lines of content and after the file content is added, the newly added file content will be displayed automatically.

     tail -n 50 -f example.txt Display the last 50 lines of the file example.txt and automatically display the new file content after the file content increases.
      Note:
      The last command is very useful, especially when monitoring log files, to keep the newly added log information on the screen.

     Detailed explanation of tail:
     -b Number Reads the specified file starting from the 512-byte block position represented by the Number variable.
      -c Number Reads the specified file starting at the byte position represented by the Number variable.
      -f If the input file is a regular file or if the File parameter specifies FIFO (first in, first out),
      the tail command does not terminate after copying the last specified unit of the input file, but continues
      reading from the input file and copying additional units (when these units are available). If the File parameter is not specified,
      and standard input is a pipe, the -f flag is ignored. The tail -f command can be used to monitor the growth of a file being written by another process.
      -k Number Reads the specified file starting at the 1KB block position represented by the Number variable.
      -m Number Reads the specified file starting at the multibyte character position represented by the Number variable. Using this flag provides consistent results in both single-byte and double-byte character code set environments.
       -n Number Reads the specified file from the position of the first or last line, indicated by the sign (+ or - or none) of the Number variable, and shifted by the line number Number.
        -r Display output in reverse order from the end of the file. The default value of the -r flag is to display the entire file in reverse order. If the file is larger than 20,480 bytes, the -r flag only displays the last 20,480 bytes. The -r flag is only
    valid with the -n flag. Otherwise, it will be ignored.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326440625&siteId=291194637
Recommended