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