Tuesday, August 30, 2016

Grep for a particular file type

Grep is great for searching recursively through a directory of source code, but it annoyingly wastes time looking at binary files and other file types that I am not interested in. When I am looking through some Java code for a reference to something like writeTextToLog(), I would ordinarily go to my top level directory and use

grep -r "writeTextToLog(" .

But this returns lots of binary target file results like this that clutter the screen and sit there chewing up time:

Grep for a particular file type

Grep is great for searching recursively through a directory of source code, but it annoyingly wastes time looking at binary files and other file types that I am not interested in. When I am looking through some Java code for a reference to something like writeTextToLog(), I would ordinarily go to my top level directory and use

grep -r "writeTextToLog(" .

But this returns lots of results like this that clutter the screen and sit there chewing up time: