tags:

views:

109

answers:

3

How can you run the following in Grep?

grep "TODO" *
grep "TODO" */*
grep "TODO" */*/*
grep "TODO" */*/*/*
grep "TODO" */*/*/*/*

I run unsuccessfully

grep -r "TODO"

I get what I want by ack-grep by ack-grep TODO.

+3  A: 

If you want to grep recursively, use -R/-r and a path:

grep -R "TODO" .

So either you're missing the path (.) or I misunderstand your question.

Michael Haren
+3  A: 

Let the shell do the work:

grep "TODO" **/*
RichieHindle
This work in Zsh, but not in Bash 3.2, Ubuntu.
Masi
+3  A: 

find . -exec grep -H TODO {} +

William Pursell
+1 for introducing me to `find`'s *plus* operator - thanks!
RichieHindle
Beware that + is not standard, and not all find implementations support it. You can always use \;, but it will be less efficient. (More subprocesses will be spawned.)
William Pursell
This seems to run lots of `grep` processes... might be slow.
liori
@liori: That's the point of the plus operator - see the manual: http://unixhelp.ed.ac.uk/CGI/man-cgi?find
RichieHindle
Ah, yes, always forgetting that it differs from \;.
liori
`-H` seems to be extraneous in Ubuntu's default installation, since it prints the filename for me without it too.
Masi