User login

How to grep through insanely nested folders to find a string

Agaric forever owes a huge debt of gratitude (and a drink or something) to jmorahan, IRC hero.

I think I have a menu_rebuild that's being called way too often. What is the unix command for looking through everything in a whole nested directory, from Drupal root on down? grep something something menu_rebuild something something?
(please don't tell me to 'man grep' -- that's what I did and why what little I knew about how to use it has been lost, as evidenced by this query)

jmorahan
grep -nHR menu_rebuild /path/to/drupal/root

ben-agaric
WOW! jmorahan, thank you!
(and there are way too many modules that use menu_rebuild ;-)

Note that we should have been able to figure out that command from man grep. We'll analyze what n, H, and R are later.

This is superior to other solutions on Agaric's site because it doesn't care what level the files it looks through are on, it doesn't care how deeply nested things are. On the other hand it doesn't exclude SVN, but it's awesome, and even possible to remember:

grep -nHR sought_string /path/to/root/directory

Update: As of 2008 August, Druplicon in irc.freenode.net's #drupal has it's own take on grep:

grep -R -B2 -A3 "string to find" /folder/to/search/recursively/* (where -Bn and -An are how many lines to display -Before and -After)

Resolution

Searched words: 
man grep wrong: grep * menu_rebuild

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.