1. Parameters:
-I: Ignore case
-C: Print the number of matching rows
-L: find included matches from multiple files
-V: Find rows that do not contain matches
-N: Print row and row labels that contain matches
2, RE (regular expression)
\ ignore the original meaning of special characters in regular expressions
^ matches the start line of the regular expression
$ matches the end line of a regular expression
\< starting from the line that matches the regular expression
\> to the end of the line that matches the regular expression
[] A single character, such as [a] that a meets the requirements
[-] range, such as [A-z], i.e. a,b,c to Z all meet the requirements
. All the individual characters
* All characters, length can be 0
3. Example
# Ps-ef | grep in.telnetd
Root 19955 181 0 13:43:53? 0:00 in.telnetd
# more Size.txt The contents of the size file
b124230
b034325
# More Size.txt | grep ' [A-b] ' range, such as [A-z], i.e. a,b,c to Z all meet the requirements
b124230
b044525
# More Size.txt | grep ' [A-b] ' *
b124230
b034325
# More Size.txt | grep 'B ' single character, if [a] is a compliance requirement
b124230
b034325
# More Size.txt | grep ' [BB] '
b124230
b034325
b103303
# grep ' Root '/etc/group
Root::0:root
Bin::2:root,bin,daemon
Sys::3:root,bin,sys,adm
Adm::4:root,adm,daemon
Uucp::5:root,uucp
Mail::6:root
Tty::7:root,tty,adm
Lp::8:root,lp,adm
Nuucp::9:root,nuucp
Daemon::12:root,daemon
# grep ' ^root '/etc/group matches the start line of the regular expression
Root::0:root
# grep ' UUCP '/etc/group
Uucp::5:root,uucp
Nuucp::9:root,nuucp
# grep ' \<UUCP '/etc/group
Uucp::5:root,uucp
# grep ' root$ '/etc/group matches the end line of the regular expression
Root::0:root
Mail::6:root
# More Size.txt | Grep-i ' B1. '-I: Ignore case
b124230
b103303
B103303
# More Size.txt | Grep-iv ' B1. '-V: Find rows that do not contain matches
b034325
a081016
# More Size.txt | Grep-in ' B1. "
1:b124230
# grep ' $ '/etc/init.d/nfs.server | Wc-l
128
# grep ' \$ '/etc/init.d/nfs.server | Wc–l ignores the original meaning of special characters in regular expressions
15
# grep ' \$ '/etc/init.d/nfs.server
Case "$" in
>/tmp/sharetab.$$
["x$fstype"! = Xnfs] &&
# more Size.txt
The test file
Their is files
The end
# grep ' the ' size.txt
The test file
Their is files
# grep ' \<the ' size.txt
The test file
Their is files
# grep ' the\> ' size.txt
The test file
# grep ' \<the\> ' size.txt
The test file
# grep ' \<[tt]he\> ' size.txt
The test file
Linux Command--grep command usage Daquan