Publishing System Settings Logout Login Register
How to search for specific text within your website's PHP files using SSH
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on April 5th, 2011
1068 views
Unix

spen.png

Here's a quick little tip for anyone that needs to plow through a zillion PHP files to find a specific line of code or a specific keyword.   I recently needed to scan the entire P2L folder for a specific word within any PHP files in the main public_html and subfolders.  The alternative would be to download everything to your local PC and then run a search locally on your PC.  That's fine and dandy if you have a small site that would only take seconds to transfer, but it's a different story when you have dozens of folders and subfolders and hundreds of pages.

So, let's put the magic of Linux to work shall we?  Open up Putty or whatever SSH program you use and log in and make your way to the public_html folder of the account you want to search.

Here's the command you want to run:

grep -r -i -l "keyword" *

Hit enter and the quary will run... be patient as it will take some time to complete.  It will list any files found that contain your keyword as the query runs.  Here's a breakdown of the command flags used:

-r recursive (will search folder and subfolders)

-i case insensitive (ignores UPPERCASE or lowercase)

-l list only (displays names of files found only)

Hope that helps! 

Have a comment or question? Please click on the comment icon at the top of this tutorial to post a message or to rate my tutorial. Want to write your own tutorials? You can publish and host it all on the Pixel2life Publishing System!

Enjoy!
Dan

Premium Publisher
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Faken

Dan Richard is the founder of the [url="http://www.pixel2life.com"]Pixel2life Tutorial Search Index[/url] and writes articles on web design and administration.
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top