0

I submitted the following commands through the cmd window on a Windows 11 machine:

grep -r --include=*.c "return" 
grep -r --include="*.c" return
grep --recursive --include=*.c return

None of these commands returned. A very similar question here in SuperUser showed exactly the first command, except with a different search pattern, that allegedly worked.

If I submit the following command while in the directory right above the source files, you can see that an error occurs:

C:> grep -r --include=*.c "return" *.c
grep: *.c: No such file or directory

I have also tried other variations. The grep command does NOT seem to recurse through the directories.

Is there something wrong with the syntax? Have I found a bug? I kind of need it to work.

2
  • A shot in the dark: are your files *.C maybe? What if you use --include="*.[Cc]"? Commented Mar 17, 2023 at 22:31
  • Kamil, no, all are lower case. Thanks anyway. If I do the command from within the directory where the files live, it works fine.
    – D. Scruggs
    Commented Mar 19, 2023 at 23:14

1 Answer 1

0

I eventually found an answer to my question. The thing that was needed was a place to start, which I unwisely assumed would be the directory you are in. So, the command would need to look as follows:

grep -r --include=*.c "return" .

or

grep -r --include=*.c "return" C:\Users\MyHomeDirectory\SourceFiles

As far as I can tell, there is nothing that says to put the starting location at the end of the line. If it in in the text produced by "grep --help", I can't find it.

I hope someone, someday, finds this helpful in the future.

1
  • Your question explicitly mentions GNU. For GNU grep -r the default file operand is .. This means the first command in your question should be equivalent to the first command in your answer. If your grep is really GNU grep then maybe you have found a bug indeed. Commented May 13, 2023 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .