There are two issues here. First, you cannot combine the -r
or -R
flags and also give target file names as arguments. The -r
/-R
turn on recursive search which means "search through all files in the given directories" so they will make grep
treat its argument as a directory to look for files in. Since there is no directory whose name matches the *.c*
glob, you get the error you show. As far as I can remember, this has always been the case, at least since I've been using Linux which has been close to 25 years now.
You can use globs as you want if you don't use the -r
/-R
flags, but you must quote them, this is essential. If you don't quote it, as you did, the glob will be expanded by the shell to any matching files and grep
won't see the glob but only the result of the shell's expansion of it, so only any files or directories in the current directory whose names match the glob.
Now, GNU grep
, the default on Linux, has a way to do what you want, but the syntax is different:
grep 44738 -r -l --include='*.h'
See man grep
:
--include=GLOB
Search only files whose base name matches GLOB (using wildcard
matching as described under --exclude). If contradictory
--include and --exclude options are given, the last matching
one wins. If no --include or --exclude options match, a file
is included unless the first such option is --include.