Tips for analyzing program logs on linux/unix

Source: Internet
Author: User
Tags ultraedit
When our application runs on linux, many colleagues are afraid of command line operations. therefore, to analyze the program logs on linux, the FTP + Ultraedit method is used. This method is not convenient, not real-time enough, and not professional enough. If hundreds of megabytes or even GB of log files are encountered, the efficiency of this analysis method is also very high.

When our application runs on linux, many colleagues are afraid of command line operations. therefore, to analyze the program logs on linux, the FTP + Ultraedit method is used. This method is not convenient, not real-time enough, and not professional enough. If hundreds of megabytes or even GB of log files are encountered, the efficiency of this analysis method is also very high, especially when tracing logs need to be implemented.

 

So I will summarize several common commands used to analyze program logs in linux and their combined use, hoping to help you.

 

Instructions:

More:
Purpose: this command prints the content of a file from the front to the back to the terminal screen each time.
Usage:

More filename

After a screen is displayed, a blank space is displayed. press enter to flip a line down. q exits.

 

Cat:
Purpose: this command is used to combine the content of multiple files and print them to the standard output. However, the most common usage is to display the content of a file, however, when the file size is large, the screen will scroll quickly and the valid information cannot be viewed. we recommend that you use more.
Usage:

Cat filename

 

Grep:
Purpose: print the lines in a file or standard input that match the specific mode. This command is the most effective method for retrieving specific information from the log file.
Usage:

1. Basic usage
Grep pattern filename
For example:
Grep "error" catalina. out
You can display all rows containing errors in the tomcat log catalina. out.

2. use a regular expression
Grep-e "pattern" filename
For example:
Grep-e "[eE] rror" catalina. out
You can display all rows containing error or Error in the tomcat log catalina. out.

3. common options
-Case insensitive for I matching
-N: displays the row number in the original file before the row is printed.

-V: This option is used to flip the default grep behavior and print the rows that do not contain the specific mode.

 

Wc:
Purpose: count the number of lines, words, and segments in the file.
Usage:

Wc filename

For example:
[Service @ localhost threshold] $ wc nohup. out
9761028 76738200 1672741676 nohup. out
The three numbers from top to bottom are the number of rows, the number of words, and the number of bytes.

 

The commonly used parameter of this command is-l, which can count only the number of rows
[Service @ localhost threshold] $ wc-l nohup. out
9761028 nohup. out

 

Head:
Purpose: display the first N lines of the file
Usage:

Head-num filename

For example:
Head-100 catalina. out
Display the first 100 rows of catalina. out

 

Tail:
Purpose: display the last N lines of the file, or display the added content in the file in real time.
Usage:

1. display the last N lines of the file
Tail-num filename
For example:
Tail-100 catalina. out
The last 100 rows of the catalina. out file are displayed.

2. added content in the real-time display file
Tail-f filename
For example:
Tail-f catalina. out
Executing this command does not directly return the command line, but prints newly added content in the log file in real time. This feature is very effective for viewing logs. To terminate the output, press Ctrl + C.

 

Related Article

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.