linux find string in folder

Answer

In our examples, we assume, that we want to find name of 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

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 list of founded files.

Was this information helpful to you? You have the power to keep it alive.
Each donated € will be spent on running and expanding this page about UNIX Shell.