--递归查找目录下含有该字符串的所有文件
grep -rn "data_chushou_pay_info" /home/hadoop/nisj/automationDemand/
--查找当前目录下后缀名过滤的文件
grep -Rn "data_chushou_pay_info" *.py
--当前目录及设定子目录下的符合条件的文件
grep -Rn "data_chushou_pay_info" /home/hadoop/nisj/automationDemand/ *.py
--结合find命令过滤目录及文件名后缀
find /home/hadoop/nisj/automationDemand/ -type f -name '*.py'|xargs grep -n 'data_chushou_pay_info'
final: [
find/home/hadoop/nisj/automationDemand/-type f – the name ‘*. Py’ | xargs grep -n ‘data_chushou_pay_info’ span> 】 compared to meet the requirements of the query.
Grep
* : represents all files in the current directory, or a file name
-r is a recursive lookup
-n is the display line number
-r find all files contain subdirectories
-i ignores case
interesting command-line argument:
grep-i pattern files: search case-insensitive. The default case is case sensitive
grep-l pattern files: only the filenames that match are listed, not the path
grep-l pattern files: lists file names that do not match
grep-w pattern files: match whole words only, not parts of strings (for example, match ‘magic’ rather than ‘magical’)
grep-c number pattern files: the matched context displays [number] lines, respectively
grep pattern1 | pattern2 files : displays rows matching pattern1 or pattern2
grep pattern1 files | grep pattern2 : displays lines matching both pattern1 and pattern2
some special symbols for searching:
\< And \ & gt; Mark the beginning and end of each word.
such as:
grep man * will match ‘Batman’, ‘manic’, ‘man’, etc
grep ‘\< Man ‘* matches’ Manic’ and ‘man’, but not’ Batman ‘.
grep ‘\< man\> ‘matches only’ man ‘and not’ Batman ‘or’ manic ‘and other strings.
‘^’ : refers to the beginning of the matched string line
‘$’ : refers to the end of the matching string
Read More:
- Linux shell RM deletes all. O suffix files in the subdirectory
- Linux find file text command (find | grep)
- Several methods of deleting all empty lines in text under Linux
- The template tags of all vscode Vue files report errors in red~
- Delete files with specified suffix in specified folder under Linux
- Java – read all the files and folders in a certain directory and three methods to get the file name from the file path
- Python TypeError: not all arguments converted during string formatting [Solved]
- Leetcode 34 finds the first and last position of an element in the sorted array (medium)
- Error in installing torch vision or pilot on Linux or Jetson nano: the headers or library files could not be found for JPEG
- Error: Projects must list all files or use an ‘include‘ pattern.
- Linux use ls to view the file color is all white solution, and Linux file color introduction
- Removing duplicate lines from Linux shell files
- error: goland –build constraints exclude all Go files
- Error messages of copying files to Linux system by PSCP in Windows operating system
- A repeated string is composed of two identical strings. For example, abcabc is a repeated string with length of 6, while abcba does not have a duplicate string. Given any string, please help Xiaoqiang find the longest repeated substring.
- Linux Tomcat accessing files on the server
- The too many open files solution appears in stream classes such as files.list
- Find files with suffix. Sh under Linux
- Add executable permissions to Linux files
- After JQ gets the tag element itself, it gets its own HTML text format (find only finds one level of child elements)