Linux Find command grep and less

Source: Internet
Author: User

New learned a less command. Take a look at some tutorials, give you options and explanations directly, and read too hard to remember them well. I'll just talk about using it.

First, there are times when you want to query a log at a point in time, or see an exception for an operation. At this point, you need to search the full log. Introduce the simple usage of less.

First step, less view file

 Less  Log file name

1, this time, use the key combination

Shift + G

You can navigate to the end of the file.

At the end of the file, use the key combination (starting at the end to retrieve the string that you entered later)

shift +?

Then enter the query criteria, either a time string or a keyword, such as the log has a print userid, then enter the problematic UserID, detect all the logs that have the UserID appear.

Using the Y key, you can navigate up to

2, if not positioned to the end, use the combination key (retrieved from the beginning of the file)

shift +/

Then, enter the string you want to query.

Using key combinations

Shift + N

Look down to the next keyword.

Of course, direct enter is also possible.

This makes it easy to locate the log based on the point in time. Or find out if something went wrong, depending on the query you want.

Another grep command, simply put,

View the log (see where a string appears):

grep -i  ' search content  ' log file name '

Interview also encountered, asked to query the number of occurrences of a file string, the command is as follows, with the-C option:

Grep-c ' Search content ' log file name '

Linux Find command grep and less

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.