Being able to search for a string of code across multiple files for wordpress development (or any code) is extremely useful. Especially jumping into a theme someone else built. This is the bash function I use.

This command will search all the .php files in the directory you’re in, and all directories below for the string class=”widget-area”. It outputs the entire line that the string is on and the name of the file.

Usage: mfind filetype string

mfind .php 'class="widget-area"'

Running this from inside the stock wordpress twentyeleven theme returns this.

				<div class="widget-area" role="complementary">
./showcase.php
	<div id="first" class="widget-area" role="complementary">
	<div id="second" class="widget-area" role="complementary">
	<div id="third" class="widget-area" role="complementary">
./sidebar-footer.php
		<div id="secondary" class="widget-area" role="complementary">
./sidebar.php

The actual function is stored in my .bash_profile and looks like this. The function name “mfind” could be named anything you like.

function mfind () {
        find . -type f -name \*$1 -exec grep $2  {} \; -print
        }