Article From:https://www.cnblogs.com/blackpepper/p/9970705.html

grep

If you want to find the “hello, world!” string in the current directory, you can do this:

$ grep -rn "hello, world!" *

-r recursive lookup
-n set number

Other parameters
-i ignore case
-R Find all files containing subdirectories
-l List only matching filenames
-L List mismatched file names
-w Match only the whole word, not part of the string
-C number Matched contexts show [number] rows separately
grep pattern1 | pattern2 files :Display rows that match pattern1 or pattern2
grep pattern1 files | grep pattern2 :Displays rows that match both pattern 1 and pattern 2.

Special symbols for search:
\< Mark the beginning and end of the word separately.

  • For example:
  • grep man * It matches `Batman’, `manic’, `man’, etc.
  • grep ‘\< man’ * Match’manic’and’man’, but not’Batman’.
  • grep ‘\< man\> ‘ Match only’man’instead of other strings such as’Batman’ or’manic’.

‘^’:Refers to a matched string at the beginning of the line.
‘$’:Refers to a matched string at the end of a line.

xargs cooperate with grep search”

find -type f -name '*.cpp' | xargs grep 'GroupRecord'

The above command means to find all. CPP suffixes and files containing GroupRecord strings on the current path


Post Views: 3

Leave a Reply

Your email address will not be published. Required fields are marked *