Right now I do this a lot:
find * | grep py$ | xargs grep foo
I recall there is some util that does this with way less typing, but which?
UPDATE: I prefer to use the Bash shell if possible.
Right now I do this a lot:
find * | grep py$ | xargs grep foo
I recall there is some util that does this with way less typing, but which?
UPDATE: I prefer to use the Bash shell if possible.
You may find your shell helps you. For instance, in zsh, you can do
grep foo **/*.py
provided the number of .py files doesn't exceed the maximum number of arguments allowed for a command (64k?). Note you can qualify the file globbing e.g.
grep foo **/*.py(mh-5)
which will give you everything modified in the last 5 hours.
zsh has recursive globbing, so you can do
grep foo **/*.py
Look ma, no find :)
UPDATE: Oh, also if you do something a lot it doesn't hurt to alias or write a function for it of course
It's called grep *wink* :-)
All py in current directory
grep -R foo *.py
All files in current and any sub-directory
grep -R foo .
I use something very much like your find/grep pair a lot, although with even more conditions -- excluding files in .svn directories, for example. I do this so much I just made scripts around these invocations, so I can call "src-grep ..." and have it do basically what you're doing here. (Then I added an optional extension for a number of context lines to pass to the grep -C flag, if supplied, and a separate version to grep the results for definition statements.)
This is more useful and faster than recursive grep for me.