Find in PHP files

Often, I search for a function, most likely a wordpress function, within the PHP files. It is usually done within wordpress themes that contains a few other files too, particularly minified CSS file that results in seeing the entire minified CSS file in the output of the search result. This is pretty annoying to say the least.

Now, I started using an alias that finds only the PHP files and then pass the result to a grep command to find only what I really need. Here’s the alias…

alias findinphp='find * -type f -name '*.php' -print0 | xargs -0 grep -inr'

I could have used the built-in -exec option too. However, it doesn’t play well when we search thousands of files. Moreover, using xargs is safe and faster.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s