christian christian - 4 months ago 9
Linux Question

Recursively find all php files not starting with a comment

Is there any useful combination of commands (sed/grep/find etc.) I can use for detecting .php files not starting with a comment? I could write a little script of course, but I'd rather use shell commands.

Matching pattern:

<?php
/*


I'd like searching in the contents of the file, not the file names.

I have to deal with a hacked website where code-injection follows a certain pattern.

<?php $code....
/*


or

<?php
$code....
/*

Answer

Using gnu grep you can use this recursive search:

grep -Ervlz $'^[[:space:]]*<?php\n/\*' --include='*.php'