turn from: http://151wqooo.blog.51cto.com/2610898/1162118
If you want to find “Hello, World!” String in the current directory, you can do this:
grep -rn “hello,world!” *
*: Represents all files in the current directory, or it can also be a file name
-r is recursive search
-N is a display line number
-R Find all files include subdirectory
-I Llelacule
The following is some interesting command line parameters:
GREP -i Pattern Files: Search for a small and lowercase. By default, distinguishment of cowlash,
GREP -L Pattern Files: Only list the matching file name,
Grep -l Pattern Files: List the name name that does not match,
GREP -W Pattern Files: Only match the entire word instead of a part of the string (such as matching ‘Magic’, not ‘Magical’),
GREP -C Number Pattern Files: The matching context displays [Number] line respectively,
Grep Pattern1 | Pattern2 Files: Show the line that matches Pattern1 or Pattern2,
GREP Pattern1 Files | Grep Pattern2: Show the line that matches both pattern1 and Pattern2.
Here are some special symbols for search:
\ <and \> The start and end of the words are marked respectively.
For example:
GREP Man * will match ‘Batman’, ‘Manic’, ‘Man’, etc.
GREP ‘\ <Man’ * matching ‘manic’ and ‘man’, but not ‘Batman’,
GREP ‘\ <Man \>’ Only matching ‘man’, not other string such as ‘Batman’ or ’Manic’.
‘^’: The matching string is at the beginning of the line,
‘$’: The matching string is at the tail,
2, XARGS cooperate with GRP search
find -type f -name ‘*.php’|xargs grep ‘GroupRecord’