grep print lines matching a pattern printing line matching mode
grep This command is used to query and match a string in a text file
Example grep ' root '/etc/passwd This command is used to match the line that contains the root string in the passwd file
[[email protected] ~]# grep ' root '/etc/passwd
Root:x:0:0:root:/root:/bin/bash
Operator:x:11:0:operator:/root:/sbin/nologin
Parameters
-I ignores case (that is, the case will be matched to match the string)
--color This parameter is to highlight the matching string (user-friendly)
-V Reverse match, meaning that the string displayed is not matched to the row
-O displays only the matched string
Regular Expressions REGEXP (REGular expression)
Metacharacters
. The decimal point is used to denote a single character
Number of characters
* An asterisk matches any number of previous characters
. * These two symbols combine to represent any length of any character
? A question mark indicates that a previous character is matched one or 0 times
Linux grep and Regular Expressions (notes)