Linux rgrep command
The Linux rgrep command is used to recursively search for strings that match the specified condition in files.
The function of the rgrep command is similar to that of the grep command. It can search for files whose content contains a specified template pattern. If a file's content matches the specified template pattern, the rgrep command will display the line containing the template pattern by default.
Syntax
rgrep [-?BcDFhHilnNrv][-R<范本样式>][-W<列长度>][-x<扩展名>][--help][--version][范本样式][文件或目录...]
Parameter description:
- -? Display the description of the template pattern and examples.
- -B Ignore binary data.
- -c Count the number of lines that match the template pattern.
- -D Debug mode, only lists the directory list searched by the command without reading file contents.
- -F When a symbolic link is encountered, rgrep ignores it by default. With this parameter, the rgrep command will read the content of the original file pointed to by the link.
- -h Mark the strings that match the template pattern.
- -H Only list the strings that match the template pattern, rather than displaying the entire line.
- -i Ignore the difference in character case.
- -l List the file names whose content matches the specified template pattern.
- -n Before displaying the line that matches the template pattern, mark the line number of that line.
- -N Do not process recursively.
- -r Process recursively, handling all files and subdirectories under the specified directory.
- -R<template pattern> This parameter has a similar effect to the "-r" parameter, but only processes files whose file names match the template pattern.
- -v Reverse the search.
- -W<line length> Limit the number of characters that the line containing the string matching the template pattern must have.
- -x<extension> Only process files whose file names match the specified extension.
- --help Online help.
- --version Display version information.
Examples
To search for files containing the string "Hello" in the current directory, 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”字符串的句子Other Extensions
Linux Command Reference