Reputation: 1812
I have a weird problem on FreeBSD 8.4-STABLE with grep (GNU grep) 2.5.1-FreeBSD.
If I try to grep -Hnr searchstring
I didn't get any output, but grep is running said ps aux and is keep running until I kill the process.
If I copy a testfile in an empty directory and do
cat testfile | grep searchstring
it is working.
But if I try to
grep -Hnr searchstring
in that directory I also get no output, grep keeps running and running but didn't produce any matches.
Anybody knows how to solve this?
Upvotes: 1
Views: 353
Reputation: 263387
Though it doesn't seem to be documented, if you invoke grep
with the -r
option and no file or directory name arguments, it defaults to the current directory, almost as if you had typed grep -R pattern .
except that ./
does not appear in the output.
Apparently this is a fairly new feature.
If you do a recursive grep
in a directory with a lot of contents, it could simply take a long time -- perhaps forever if there are device files such as /dev/zero
that can produce infinite output.
Upvotes: 1
Reputation: 246992
Even though you gave -r
, you still have to give grep a file argument. Othersize, as you've discovered, it just sits there waiting for input on stdin.
You want
grep -Hnr searchstring .
# ....................^^
That will recursively find files under the current directory.
Upvotes: 4