Linux Find String in Folder

Linux Find String in Folder

In our examples, we assume, that we want to find the name of the network card “eno16777728” in /etc folder recursively.

This example search “eno16777728” in /etc folder (-r means recursive, -n means print line number):

grep -nr "eno16777728" /etc

In next example, we would like to add ignore case with “i” option:

grep -inr "eno16777728" /etc

If you are not super user, it is good idea to suppress error messages with “s” option:

grep -insr "eno16777728" /etc

In examples mentioned before, searched string could be also a part some string. In next example, we would like to find “eno16777728” as whole word only (w option):

grep -winsr "eno16777728" /etc

The alternative way is use find and exec option:

find /etc -type f -exec grep -il 'eno16777728' {} \;

In this case option exec executes grep command for each founded file. In {} is a list of founded files.

Leave a Comment