[Bash shell] Find something in some files

Command “find” is one of the most powerful command in linux, here is an exmaple that allows list the files which contain something.

find . -name \*.[type of your files] -exec grep -q "[text that you want to search]" "{}" \; -print

For example, I have two shell files in my folder :

 
$ ll
drwxrwxr-x 3 bo bo 4096 juin 13 14:56 ./
drwxr-xr-x 16 bo bo 4096 juin 13 14:04 ../
-rwxrwxrwx 1 bo bo 2554 juin 12 18:05 first.sh*
-rwxrwxrwx 1 bo bo 1283 juin 12 16:10 second.sh*

And I want to find the string “spark” in these files

$ find . -name \*.sh -exec grep -q "spark" "{}" \; -print

And I got :

./second.sh