As a backend programmer, you deal with Linux in many places. If you don’t know how to read Linux logs, you are very likely to be ridiculed by colleagues and interviewers, so it is very important to master one or several methods of viewing logs. There are many commands for viewing logs in Linux: tail, cat, tac, head, echo, etc. This article only introduces several commonly used methods. 1. tail This is the way I view it most often.
Usage is as follows:
It is usually used in conjunction with grep, for example:
If the amount of data to be queried at one time is too large, you can turn the pages to view it, for example:
2. head Head is the opposite of tail. It reads the first few lines of log.
For other parameters of head, refer to tail 3. cat cat displays the first line to the last line on the screen To display the entire file at once: $ cat filename Create a file from the keyboard: $cat > filename Merge several files into one: $cat file1 file2 > file can only create new files, cannot edit existing files. Append the contents of one log file to another: $cat -n textfile1 > textfile2 Clear a log file: $cat : >textfile2 Note: > means create, >> means append. Don't get confused. For other parameters of cat, refer to tail 4. more The more command is a text filter based on the vi editor. It displays the contents of text files page by page in full screen mode and supports keyword positioning operations in vi. There are several built-in shortcut keys in the more list, the commonly used ones are H (get help information), Enter (scroll down one line), Space (scroll down one screen), Q (exit command). The more command reads the file from front to back, so the entire file is loaded at startup. This command displays one screen of text at a time, stops when the screen is full, and a prompt message appears at the bottom of the screen, giving the percentage of the file that has been displayed so far: –More– (XX%)
5. sed This command can search for a specific section of the log file, based on a time range, and can be queried by line number and time range. By line number sed -n '5,10p' filename This way you can view only lines 5 to 10 of the file. By time period sed -n '/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p' test.log 6. less When querying logs with the less command, the general process is as follows
Common command parameters:
Generally, I check the logs and apply other commands
Linux log file description
The above is all the content compiled by the editor of 123WORDPRESS.COM. I hope it can help everyone. You may also be interested in:
|
<<: Detailed explanation of desktop application using Vue3 and Electron
>>: How to install MySQL database on Ubuntu
Install postcss-pxtorem first: npm install postcs...
This article uses examples to describe how to cre...
<br />This is not only an era of information...
This article uses vue, and adds mouse click event...
Table of contents Scene Introduction Plugin Imple...
Table of contents 1. New usage of watch 1.1. Watc...
Effect The effect diagram is as follows Implement...
Let's first talk about the value of web front...
I was in a meeting when a colleague called to rep...
Table of contents 1. Let’s start with the conclus...
Table of contents JSON.parse JSON.parse Syntax re...
In the past, I only knew how to use the name attri...
I recently discovered a pitfall in regular expres...
In the front-end design draft, you can often see ...
Table of contents 1 Node.js method of sending ema...