Flipkart

Wednesday, June 2, 2010

Finding a file with particular content

Ever known that you had written a function for something, but can't remember which file it was in?
  1. grep -iR myFunction ./  
"grep" is a program for printing out lines that match a particular pattern. You can provide it with some switches, like the "-i" for making it case-insensitive, and "-R" for making it recursive in my example. Then provide a pattern, and the path to search in (here I'm searching the current directory with "./"). This example will show the filename and the line in that file for any matches it finds to "myfunction" (case-insensitve because of the "-i").

If your projects are Subversion working copies, you may find that it's annoying to see results from the ".svn" directories. To exclude particular directories from the search, use the "--exclude-dir=" switch, for example "--exclude-dir=.svn".

No comments:

Post a Comment