Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check logs in Linux system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor will show you how to view the log in the Linux system. The knowledge points in the article are introduced in great detail. Friends who feel helpful can browse the content of the article with the editor, hoping to help more friends who want to solve this problem to find the answer to the problem. Let's follow the editor to learn more about "how to check the log in the Linux system".

Bug viewing log information is the best way to find problems when there is a development project, and get used to setting logs at business key points.

View logs commonly used commands tail:

-n is the display line number; equivalent to the nl command; examples are as follows:

Tail-100f test.log real-time monitoring 100 lines of logs

Tail-n 10 test.log query the log of the last 10 lines at the end of the log

Tail-n + 10 test.log query all logs after 10 lines

Head:

In contrast to tail, tail refers to the number of lines of log after reading, while head refers to the number of lines of the first line of the log file. The example is as follows:

Head-n 10 test.log query the first 10 lines of logs in the log file

Head-n-10 test.log query log file all logs except the last 10 lines

Cat:

Tac is viewed in reverse order, which is the reverse of cat words. Examples are as follows:

Cat-n test.log | grep "debug" query keyword log (commonly used! ~)

Vim:

1. Enter vim editing mode: vim filename 2, enter "/ keyword", press enter key to find 3, find the next one, press "n" to exit: after pressing the ESC key, and then enter the: number, vi will wait at the bottom of the screen for us to enter the command wq! Save exit Q! Do not save exit

List several common application scenarios ⬇⬇⬇:

View log application scenario 1: view by line number: filter out the log near the keyword

(1) cat-n test.log | grep "debug" to get the line number of the key log

(2) cat-n test.log | tail-n + 92 | head-n 20 Select the middle line where the keyword is located. Then check the log of the first 10 lines and the last 10 lines of this keyword:

Tail-n + 92 represents the log after 92 lines of the query

Head-n 20 means to check the first 20 records in the previous query results.

View log application scenario 2: query log based on date

(1) sed-n'/ 2014-12-17 16 purse 17 purl 20 lemme lemme 2014-12-17 16 purse 17 purl 36 lemon p 'test.log

Special note:

The above two dates must be the logs printed in the log, otherwise they are invalid

First grep '2014-12-17 16-16-14-17-17-17-17-17-17-16-17-17-17-17-16-17-17-17-16-17-17-17-16-17-12-16 to determine whether there is this time point in the log

View log application scenario 3: the log contains a lot of content, so it is not easy to view it when printed on the screen, paging / saving files

(1) use the more and less commands

For example: cat-n test.log | grep "debug" | more is printed in pages. Turn the page by clicking the spacebar.

(2) use > xxx.txt to save it to a file, and then you can pull down the file for analysis.

For example: cat-n test.log | grep "debug" > debug.txt

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

Thank you for your reading, the above is "how to check the log in the Linux system" all the content, learn friends to hurry up to operate it. I believe that the editor will certainly bring you better quality articles. Thank you for your support to the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report