Linux rgrep Command
The Linux rgrep command is used to recursively search for strings that match a specified pattern in files.
The rgrep command functions similarly to the grep command, searching for files that contain specified pattern templates. If the content of a file matches the specified pattern template, the rgrep command by default will display the line containing the pattern template.
Syntax
rgrep [-?BcDFhHilnNrv][-R<pattern>][-W<column length>][-x<extension>][--help][--version][pattern][files or directories...]
Parameter Explanation:
-? Displays the explanation of pattern templates and examples.
-B Ignores binary data.
-c Counts the number of lines that match the pattern template.
-D Debug mode, only lists the directories searched by the command, without reading the file contents.
-F When encountering symbolic links, rgrep by default ignores them. With this parameter, the rgrep command reads the contents of the original file pointed to by the link.
-h Highlights the strings that match the pattern template.
-H Only lists the strings that match the pattern template, rather than displaying the entire line.
-i Ignores the difference between uppercase and lowercase characters.
-l Lists the names of files whose contents match the specified pattern template.
-n Before displaying the line that matches the pattern template, indicates the line number of that line.
-N Does not perform recursive processing.
-r Performs recursive processing, handling all files and subdirectories under the specified directory.
-R<pattern> This parameter is similar to the "-r" parameter, but only focuses on files whose filenames match the pattern template.
-v Inverts the search.
-W<column length> Limits the column where the string matching the pattern template must be located, specifying the number of characters.
-x<extension> Only processes files whose filenames match the specified extension.
--help Online help.
--version Displays version information.
Example
To find files in the current directory that contain the string "Hello", you can use the following command:
rgrep Hello *
The search results are as follows:
$ rgrep Hello * # Searches for files in the current directory containing the string "Hello"
testfile_1:Hello 95 # Sentence in testfile_1 containing the string "Hello"
testfile_2:Hello 2005 # Sentence in testfile_2 containing the string "Hello"