What are the three commands to view logs in Linux?

coldplay.xixi
Release: 2021-01-21 15:24:24
Original
19243 people have browsed it

Three commands for viewing logs in Linux: 1. To view real-time changing logs, the code is [tail -f filename]; 2. To search for logs near keywords, the code is [cat -n filename |grep " Keyword "]; 3. Enter the edit search.

What are the three commands to view logs in Linux?


The operating environment of this tutorial: windows7 system, linux7.3 version, DELL G3 computer. This method is suitable for all brands of computers.

Three commands for viewing logs in Linux:

The first one: View real-time changing logs (more memory intensive)

The most commonly used:

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

  • Ctrl c is to exit the tail command

Other situations:

  • tail -n 20 filename (Display the last 20 lines of filename)

  • tail -n 5 filename (Display the file starting from line 5)

Second type: Search logs near keywords

The most commonly used:

cat -n filename |grep "keyword"

Other situations:

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

  • cat filename | grep -B 5 'Keyword' (display matching string and first 5 lines)

  • cat filename | grep -A 5 'Keyword' (display matching string and the next 5 lines)

Third method: Enter the edit search:vi(vim)

1. Enter vim editing mode: vim filename

2. Enter "/keyword" and press enter to find

3. To find the next one, press "n" You can

Exit: After pressing the ESC key and then entering the : sign, vi will wait for us to enter the command

  • wq at the bottom of the screen! Save and exit;

  • q! Exit without saving;

Other situations:

  • /Keyword Note: For forward search, press the n key to move the cursor to the next matching position

  • ?Keyword Note: For reverse search, press the shift n key to move the cursor to the next matching position Conditional

# Related learning recommendations:

linux video tutorial

The above is the detailed content of What are the three commands to view logs in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!