In Linux, you can use the grep command to view the content of the file. This command is used to find strings that meet the conditions in the file. It can find files that contain the specified template style. When the parameter is set to "-r " means traversing the directory layer by layer to search, the syntax is "grep -r -l "query content" file directory".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Find the content of a file
grep -r -l "查询内容" 文件目录
After getting the specific file name
Check the related content of a file
grep -rn "关键内容" 文件名
The Linux grep command is used to find strings that meet the conditions in the file.
The grep command is used to find files whose content contains the specified template style. If the content of a file is found to match the specified template style, the default grep command will display the column containing the template style. . If no file name is specified, or if - is given, the grep command reads data from the standard input device.
Syntax
grep [-abcEFGhHilLnqrsvVwxy][-A<显示行数>][-B<显示列数>][-C<显示列数>][-d<进行动作>][-e<范本样式>][-f<范本文件>][--help][范本样式][文件或目录...]
grep common parameter description
-e: Use regular search
-i : Case-insensitive
-v: Find lines that do not contain the specified content
-w: Search by word
-c: Count the number of matches
-n: Display the line number
-r: Layer by layer Traverse the directory to find
-A: Display the matching line and the following lines, such as: -A3, which means display the matching line and the following 3 lines
-B: Display the matching line and the number of lines before it, such as: -B3, which means display the matching line and the first 3 lines
-C: Display the number of lines before and after the matching line, such as : -C3, means displaying 3 lines before and after the batch line
--color: The matched content is highlighted
--include : Specify matching file types
--exclude: Filter file types that do not need to be matched
Examples are as follows:
The following are two examples of text url and url1
#Multiple file query
#Find files containing jd and http Lines
# Lines that do not contain jd
## Recommended learning:The above is the detailed content of How to check the contents of a file in Linux. For more information, please follow other related articles on the PHP Chinese website!