Three commands for viewing logs in Linux and logs in linux

Source: Internet
Author: User

Three commands for viewing logs in Linux and logs in linux

First: View logs of real-time changes (more memory-consuming)

Most commonly used:

Tail-f filename (the last 10 rows by default, which is equivalent to adding the parameter-n 10)

Ctrl + c is the exit command

 

Other cases:

Tail-n 20 filename (display the last 20 rows of filename)

Tail-n + 5 filename (the file is displayed starting from row 5th)

 

Type 2: Search logs near keywords

Most commonly used:

Cat-n filename | grep "keyword"

   

Other cases:

Cat filename | grep-C 5 'keyword' (display the line matching the string in the log and the first and last five rows)

Cat filename | grep-B 5 'keyword' (show matching strings and the first five rows)

Cat filename | grep-A 5' keyword '(the matching string and the last 5 rows are displayed)

 

Third: Enter edit search: vi (vim)

1. Enter the vim editing mode: vim filename

2. enter "/keyword" and press enter to search

3. Find the next one and press "n ".

Exit: Press ESC, and then enter the number. vi will wait for us to enter the command at the bottom of the screen.

Wq! Save and exit;

Q! Do not save and exit;

 

Other cases:

/KeywordsNote: forward lookup: Press n to move the cursor to the next matching position.
?KeywordsNote: For reverse search, press shift + n to move the cursor to the next qualified

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.