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 find keywords and the information before and after them in Linux log

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Editor to share with you how to find keywords in the Linux log and the information before and after, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

In our daily work, we often need to view logs, for example, we can view logs in real time through tail commands, or we can view log information through commands such as cat.

But what we want to discuss now is how to filter out what we want through keywords from the log, there are many ways, today we mainly use the cat command to learn.

Suppose there is a log file hrun.log, and the keyword for the query is "New user":

View logs according to keywords

Cat hrun.log | grep "New user"

View the last 10 lines of log according to keywords

Cat hrun.log | grep "New users"-A 10

View the first 10 lines of log according to keywords

Cat hrun.log | grep "New users"-B 10

View the first and last 10 lines of the log according to the keyword, and show the line number

Cat-n hrun.log | grep "New users"-C 10

View the first 50 lines of the log

Cat hrun.log | head-n 50

50 lines after viewing the log, and show the line number

Cat-n hrun.log | tail-n 50

Description:

After-An indicates the keyword, After

-B indicates the keyword before Before

-C indicates before and after the keyword, Context

The above is all the contents of the article "how to find keywords and the information before and after them in the Linux log". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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

Servers

Wechat

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

12
Report