Get the App
SLTechnology News&Howtos  ›  Servers  › 

How does linux view logs

Shulou Source: shulou.com Published: 2022-06-02 00:25:03 09月23日 Update

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!

Tags: Keywords keywords logs commands situations articles input code cursors content real-time commonly used conditions changes search move not much memory parameters place Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Microsoft Shulou Technology macOS MariaDB