From: http://www.9usb.net/200902/linux-grep.html
1. Search for a file with the string 'Magic 'in the Linux/DOC' directory: $ grep magic/usr/src/Linux/doc /*
Sysrq.txt: * how do I enable the magic sysrq key?
Sysrq.txt: * how do I use the magic sysrq key? The 'sysrp.txt 'file contains this string. The sysrq function is discussed. By default, 'grep' only searches for the current directory. If the directory contains many subdirectories, 'grep' is listed as follows:
Grep: Sound: is a directory, which may make the output of 'grep' hard to read. There are two solutions:
Search for subdirectories: grep-R
Or ignore the subdirectory: grep-D Skip. If there are many outputs, you can use the pipeline to transfer them to 'sha'. Read:
$ Grep magic/usr/src/Linux/documentation/* | less
In this way, you can read more conveniently. Note that you must provide a file filtering method (* for searching all files *). If you forget, 'grep' will wait until the program is interrupted. If this happens, press <Ctrl C> and try again. The following are some interesting command line parameters:
Grep-I pattern files: searches case-insensitive. Case Sensitive by default,
Grep-l pattern files: only names of matched files are listed,
Grep-l pattern files: Lists unmatched file names,
Grep-W pattern files: match only the entire word, not a part of the string (for example, match 'Magic ', not 'magical '),
Grep-C number pattern files: the matching context displays the rows of [number,
Grep pattern1 | pattern2 files: displays the rows matching pattern1 or pattern2,
Grep pattern1 files | grep pattern2: displays rows that match both pattern1 and pattern2. Here are some special symbols used for search:
\ <And \> respectively indicate the start and end of a word.
For example:
Grep man * matches 'Batman ', 'manic', 'Man ', etc,
Grep '\ <man' * matches 'manic 'and 'man', but not 'Batman ',
Grep '\ <man \>' only matches 'man ', not other strings such as 'Batman' or 'manic.
'^': Indicates the first row of the matched string,
'$': Indicates the end of a matched string,