Posts Tagged ‘grep’

recursively search a certain file for certain text (linux)

July 1st, 2009 by Sameer | No Comments | Filed in Hosting

Have you ever tried to do a recursive linux search for a text string inside a particular file? For example
grep -r "mail" *.php
and then it fails because the current folder doesn’t have any php files in it?

Here is how you can achieve a search inside all .htaccess files for the text php_flag

find -iname .htaccess | while read line; do grep --with-filename "php_flag.*" $line; done

This below line will search all .PHP files for a common hack script

find -iname *.php | while read line; do grep --with-filename "eval (base64_decode('aWYoIWlzc2V0KCR" $line; done

If that gives you too much output, here is a search that will only display the filenames

find . -name "*.php" | while read line; do grep --files-with-matches --with-filename "base64_decode('aWYoIWlzc2V0KCR" $line; done

Tags: ,