[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
Advertisements

2 comments on “[Bash shell] Find something in some files

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s