Thursday, 12 July 2007

Shell: Find all files recursively with "pattern"

Below is the single command to find all files recursively for a particular pattern.
Here find command is executing the grep and passing file name with path where curly braces ({}) are placed.

$ find . -type f -exec grep -il "pattern" {} \;

Here grep command is searching for the pattern in all the files given as argument, but files are given by find command using back tic(``)

$ grep -il "pattern" `find . -type f`

Below command is very much useful when number files to search in exceeds 256.
xargs will give 10 files at a time to grep.

$ find . -type f|xargs grep -il "pattern"

1 comment:

Guna Sekaran said...

Hi Khaliq,

How are you? Hope you remember me..I am Guna and I worked with you in i2 tech