Linux rgrep command
The Linux rgrep command is used to recursively search for strings that match a pattern in files.
The rgrep command works similarly to grep; it searches for files whose contents contain a specified pattern. If a file's contents match the specified pattern, rgrep displays the line containing the pattern by default.
Syntax
rgrep [-?BcDFhHilnNrv][-R<范本样式>][-W<列长度>][-x<扩展名>][--help][--version][范本样式][文件或目录...]
Parameter descriptions:
- -? Display descriptions of patterns and examples.
- -B Ignore binary data.
- -c Count the number of lines matching the pattern.
- -D Debugging mode: only list the directories the command searches, without reading file contents.
- -F By default, rgrep ignores symbolic links; with this option, rgrep reads the contents of the original file that the link points to.
- -h Highlight the strings that match the pattern.
- -H List only the strings matching the pattern, rather than displaying the whole line.
- -i Ignore differences in character case.
- -l List the names of files whose contents match the specified pattern.
- -n Before displaying each line that matches the pattern, mark it with its line number.
- -N Do not process recursively.
- -r Process recursively, handling all files and subdirectories under the specified directory.
- -R
This parameter has an effect similar to specifying "-r", but it only targets files whose names match the pattern. - -v Invert the search.
- -W
Limit the number of characters that a line containing a matching string must have. - -x
Only process files whose names match the specified extension. - --help Online help.
- --version Display version information.
Example
To find files in the current directory whose sentences contain the string "Hello", use the following command:
rgrep Hello *
The search results are as follows:
$ rgrep Hello * #在当前目录下查找句子中包含“Hello”字符串的文件
testfile_1:Hello 95 #testfile_1中包含“Hello”字符串的句子
testfile_2:Hello 2005 #testfile_2中包含“Hello”字符串的句子
Linux Command Reference