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 does linux view logs

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Xiaobian to share with you how to view linux logs, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

Three commands for linux to view logs: 1. View logs that change in real time, with code [tail -f filename];2. Search logs near keywords, with code [cat -n filename]| grep "keyword"];3. Enter edit search.

There are three commands for Linux to view logs:

The first one: View logs of real-time changes (compare memory)

Most commonly used:

tail -f filename (default last 10 lines, equivalent to adding parameter-n 10)

Ctrl+C is the exit tail command.

Other information:

tail -n 20 filename (display last 20 lines of filename)

tail -n +5 filename (displaying files starting at line 5)

Second: Search for logs near keywords

Most commonly used:

cat -n filename |grep "keyword"

Other information:

cat filename |grep -C 5 'keyword' (displays the line matching the string in the log and 5 lines before and after)

cat filename |grep -B 5 'keyword' (displays matching string and first 5 lines)

cat filename |grep -A 5 'keyword' (displays matching string and last 5 lines)

The third type: enter the editor to find:vi(vim)

1. Enter vim editing mode:vim filename

2, enter "/keyword", press enter key to find

3. Find the next one, press "n"

Exit: When you press ESC and then type: ,vi will wait at the bottom of the screen for us to enter a command

wq! Save exit;

q! Do not save exit;

Other information:

/Keyword Note: Forward search, press the n key to move the cursor to the next eligible place

? Key word note: reverse search, press shift+n key, move the cursor to the next eligible

That's all for linux how to view logs. Thanks for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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