Common command methods for finding file content in Linux

A common command method for finding the contents of a file in Linux.  

Find lines matching a specified string from the contents of a file:

$ grep "string to be searched for"
Example of file name: find the .in file containing the specified string in the first level folder of the current directory
grep "thermcontact" */*.in

finds a match with a regular expression from the content of the file line:
$ grep -e "regular expression" filename

search is case insensitive:
$ grep -i "searched string" filename

search matched lines:
$ grep -c "searched string " filename


finds lines from the file content that do not match the specified string:
$ grep -v "string being searched for" filename


starts from the root directory to find all text files with a .log extension, and finds that contain "ERROR" The line
find / -type f -name "*.log" | xargs grep "ERROR"
Example: Find all text files with .in extension starting from the current directory and find the line containing "thermcontact"
find . -name "*.in" | xargs grep "thermcontact"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326441005&siteId=291194637