Doubt in find command

Hi All,

I wanted to list all the files in the current directory which contains the pattern "error". I tried the following grep command

grep -i 'error' *.*

but i got the error message "ksh: /usr/bin/grep: 0403-027 The parameter list is too long."

Any idea why the grep didn't work?
Note: There are hundreds of files which contains this pattern.

I used find command to achieve the same result.

find . -type f -exec grep -i "error" {} \;
find . -type f -exec grep -i "error" /dev/null {} \;

The first command displays me the lines from all files which contains the pattern "error". But it doesn't append the filename in the front.

But the second command gave me the same result with directory name and filename appended in the beginning of each line?

Any idea why both the above find commands work differently?

Not sure if the length makes a difference. You might want to see this post - Command line buffer limit? and Grep line length constraint problem - help!

The 2 find commands work differently as
the second passes 2 files to grep for
each invocation, in which case grep outputs
the filenames to distinguish. Yes it's a hack.

A better/more efficient option is to pass
as many filenames as possible to grep
to minimise the number of times it is invoked.
xargs is the tool you want for this:

find . -type f -print0 | xargs -r0 grep -F error

Thank you Vino and pixelbeat !!!