Ubuntu – Recursive grep fails for *.c files

grep

I tried to recursively search a pattern in all the .c files in the following way

> grep -lr search-pattern *.c

But got this as the output

> grep: *.c: No such file or directory

When I use this:

> grep -lr search-pattern *

I get plenty of . c files in the directories with the pattern.

What is wrong with the earlier expression?

Best Answer

I suggest to use the --include option of grep:

grep -lr --include='*.c' search-pattern .