Transferred from: http://151wqooo.blog.51cto.com/2610898/1162118
If you want to find "hello,world!" in the current directory String, you can do this:
Grep-rn "hello,world!" *
*: represents all files in the current directory, or it can be a file name
-R is recursive lookup
-N is the line number displayed
-R Find all files containing subdirectories
-I ignores case
Here are some interesting command-line arguments:
Grep-i pattern Files: Search by case-insensitive. The default case is case-sensitive,
Grep-l pattern Files: Lists only the matching file names,
Grep-l pattern Files: Lists mismatched file names,
Grep-w pattern files: matches only the entire word, not part of the string (such as matching ' magic ', not ' magical '),
Grep-c number pattern files: matching contexts display [number] lines, respectively,
grep pattern1 | PATTERN2 files: Displays rows that match pattern1 or pattern2.
grep pattern1 Files | grep pattern2: Displays rows that match both PATTERN1 and pattern2.
Here are some special symbols for searching:
\< and \> each mark the beginning and end of the word.
For example:
grep man * will match ' Batman ', ' manic ', ' man ', etc.
grep ' \<man ' matches ' manic ' and ' man ', but not ' Batman ',
grep ' \<man\> ' matches only ' man ', not ' Batman ' or ' manic ' and other strings.
' ^ ': refers to a matching string at the beginning of the line,
' $ ': refers to a matching string at the end of the line,
2,xargs with grep lookup
Find-type f-name ' *.php ' |xargs grep ' Grouprecord '
Linux finds strings in files