Linux grep command

Source: Internet
Author: User

1. What is the grep command
grep full Name Global search regular expression and print out of the line, fully search regular expressions and print out the lines
is a powerful text search tool.

2. Common usage
1) Search for files, print lines containing strings
To view files:

Search for rows that contain "root":

Show line number:

To set the color:

Search for rows that do not contain "root":

Search for lines that do not contain "root" and do not Contain "Nologin":

Use DMESG to list the information, and then use grep to filter the rows that contain "TCP":

Use DMESG to list the information, then use grep to filter the rows containing "TCP", the first two rows of the keyword, and the last three rows:

Search for files containing "Django" lines in the current directory:

Search for files with the "Django" line in the current directory and sub-directories:

The current directory and subdirectories search for files that contain "Django" lines, but do not display specific lines, only display files:

Regular searches for rows containing "Sy[ns]":

Regular reverse search "[^s]bin" is not preceded by the line of S:

Regular searches for "^root" lines starting with Root:

The regular search for "false$" ends with a false line:

Regular search for "^$" Blank lines:

The regular search "A.E" is in the middle of any byte line:

The regular search "A *" arbitrarily repeats the preceding bytes of the line:

The regular search "A.*o" is in the middle of any byte line:

The regular search for "s{2}" has only two lines of S:

The regular search for "w{2}" has more than two W rows:

The regular search "5+" has one or more 5 rows:

The regular search for "Am?e" has 0 or 1 m rows:

Regular Search "(MN) +" has more than 1 consecutive MN lines:

Search for rows that contain "am|nt" with AM or NT:

Linux grep command

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.