tags:

views:

838

answers:

5

Hi,

I use following find command to find and show all files having the input text pattern.

find . -type f -print|xargs grep -n "pattern"

I have many project folders each of which has its own makefile named as 'Makefile'.(no file extension, just 'Makefile')

How do i use above command to search for a certain pattern only in the files named Makefile which are present in all my project folders?

-AD.

+2  A: 

-print is not required (at least by GNU find implementation). -name argument allows to specify filename pattern. Hence the command would be:

find . -name Makefile | xargs grep pattern

Eugene Morozov
+1  A: 
find . -type f -name 'Makefile' | xargs egrep -n "pattern"

use egrep if you have very long paths

Duplicate of : this

Egwor
+1  A: 

If you have spaces or odd characters in your directory paths youll need to use the null-terminated method:

 find . -name Makefile -print0 | xargs -0 grep pattern
Tom Ritter
+1  A: 

You can avoid the use of xargs by using -exec:

find . -type f -name 'Makefile' -exec egrep -Hn "pattern" {} \;

-H on egrep to output the full path to the matching files.

Grant Wagner
A: 

you can use ff command i.e ff -p .format. For eg ff -p *.txt

Akshay