Linux View Log commands

Source: Internet
Author: User

Log file storage logs are very large, we can not use VI directly into the log, we need the Linux command to complete our viewing tasks
Log location:/var/log/message information and error log after system startup is one of the most frequently used logs in red Hat Linux/var/log/secure Security-related log information/var/log/maillog mail-related day Logging Information/var/log/cron log information related to timed tasks/var/log/spooler log messages related to UUCP and news devices/var/log/boot.log Daemon start and stop related log message 123456 78
    • tail  

      parameter: 
      Tail [-f] [-c number |-N number |-M number |-B number |-K number] [File] 
      Parameter explanation : 
      -F This parameter is used to monitor file growth.  
      -C number reads the specified file from the number byte location  
      -N number reads the specified file from the number line position.  
      -m number reads the specified file from a multiple-byte character position, for example, your file assumes that you include Chinese characters, assuming that specifying the-c parameter may result in truncation, but using-m avoids the 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.  
      file name of the object to specify the action of
      the above command, which involves number, assuming not specified, displays 10 rows by default. Number is preceded by a sign that indicates whether the offset is calculated from the top or from the tail.  
      Tail can run files are generally below/usr/bin/.
Example: 1, tail-f filename Description: Monitor the tail content of the filename file (the default 10 lines, equivalent to increase the parameter-n 10), refresh appears on the screen.  Exit, press CTRL + C.  2. Tail-n FileName Description: Displays the last 20 lines of the filename. 3. TAIL-R-N FileName Description: Reverse shows the last 10 lines of filename. 123456789
    • Head

Head only shows the first 10 rows of head-n test.log query log file in the previous lines.  Head-n -10 test.log query log file except for all other logs in the last 10 lines; 12345
    • Grep

grep [options]   main parameter:   [options] Main parameter:   -c: Output only the count of matching rows.   -i: does not distinguish between large   lowercase (applies to single-character only).   -h: File name is not displayed when querying multiple files.   -l: Only file names that contain matching characters are output when querying multiple files.   -n: Displays the matching line and the   line number.   -s: does not display error messages that do not exist or have no matching text.   -v: Displays all lines that do not contain matching text.   pattern Regular Expression main parameter:  :  ignores the original meaning of special characters in regular expressions.   ^: Matches the start line of the regular expression.   $:  matches the end line of the regular expression. &NBSP;&NBSP;<: Start with a line that matches the regular expression   style.   >: End of line to match regular expression.   [ ]: A single character, such as [a], a meets the requirements  . &NBSP;&NBSP;[&NBSP;-&NBSP;]: range, such as [A-z], that is, A, B, C until Z all meet the requirements  .   . : all the individual characters. &NBSP;&NBSP;&NBSP;-&NBSP: There are characters, the length can be 0. 1234567891011121314151617181920 
    • Sed

Use the SED command sed-n ' 5,10p ' filename so you can view only the lines 5th through 10th of the file. 12
    • Cat

Cat has three main functions:   1. Displays the entire file at once. $ cat filename  2. Create a file from the keyboard. $ cat > filename      can only create new files and cannot edit existing files.   3. Merge several files into one file:   $cat  file1 file2 > file   parameters:  -n  or  --number  by  1  starts with the number of lines for all outputs   -b  or  --number-nonblank  and  -n  similar, except for blank lines not numbered    -s  or  --squeeze-blank  a blank line that is substituted for one row, or  --, when a row is encountered with more than two consecutive lines   -v  or show-nonprinting   example:   the file contents of  textfile1  add line number after input  textfile2  this file    cat -n textfile1 > textfile2   put  textfile1  and  textfile2 The contents of the   file are appended to  textfile3  after the line number (blank lines are not added).   cat -b textfile1 textfile2 >> textfile3   Throw the Test.txt file into the trash, and assign a null value test.txt  cat /dev/null > /etc/test.txt    Note: > means to create a,>> that is appended. No, please.To get mixed up.   123456789101112131415161718192021
    • TAC (Reverse list)

The TAC is writing cat back, so his function is in contrast to cat, which is displayed continuously on the screen from the first line to the last line, while the TAC is displayed on the screen in reverse from the last line to the first line! 12
    • Mixed Use commands

A. Tail web.2016-06-06.log-n 300-f Check the bottom is the latest 300 logs and refresh B in real time. grep ' Nick ' |  Tail web.2016-04-04.log-c 10 View characters ' Nick ' before and after 10 log records, uppercase C C. Cat-n test.log |tail-n +92|head-n tail-n +92 means that after querying 92 rows, the log head-n 20 indicates that the first 20 records are checked in the previous query results.


Linux View Log commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.