You have to specify the directory too as the last argument:
grep -r -F "string to search" /path/to/dir
Or if you want to search in current directory, write .
as the target directory:
grep -r -F "string to search" .
If you don't specify a directory, grep
will try to search in the standard input, but recursive search does not make sense there - that's why you get that warning.
The manpage for grep
says that:
Not all grep implementations support -r and among those that do, the behaviour with symlinks may differ.
In this case, you can try a different approach, with find
and xargs
:
find /path/to/dir -name '*.*' -print0 | xargs -0r grep -F "string to search"
Again, you can write .
as the directory parameter (after find
) if you want to search in the current directory.
Edit: as @EdMorton pointed out, the -F
option is needed for grep
if you want to search for a simple text instead of a regular expression. I added it to my examples above as it seems you are trying to search for PHP snippets that may contain special characters, which would lead to a different output in regexp mode.
pattern
in all HTM/HTML files in current directory, usegrep "pattern" *htm*
string
in all files in current directory, usegrep "string" *