Common command methods for finding file contents in Linux
Find the line matching the specified string from the file contents:
$ grep "string found" file name
Example: Looking for the. In file containing the specified string in the first level folder in the current directory
grep "Thermcontact" /. In
Find the line that matches the regular expression from the file contents:
$ grep–e "Regular expression" file name
Find is case insensitive:
$ grep–i "string found" file name
To find the number of matching rows:
$ grep-c "string found" file name
Find rows that do not match the specified string from the file contents:
$ grep–v "string found" file name
Example
From the root directory, look for all text files with a. log extension and find the line that contains "ERROR"
/-type-name"*.log"|"ERROR"
Find all text files with an. in extension starting from the current directory and find the line containing "Thermcontact"
"*.in"| xargs grep "thermcontact"
Ubuntu searches files by file content