How to Find File Contents 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 case-insensitive to

search :
$ grep -i "string to be searched for" filename to

find matching lines:
$ grep -c "string to be searched for " filename Find lines


from file contents that do not match the specified string:
$ grep -v "string being searched for" filename Find all text files with a .log extension starting


from the root directory, and find those containing "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=326244166&siteId=291194637
Recommended