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....
/*
Using gnu grep you can use this recursive search:
grep -rvlz $'^[[:space:]]*<?php\n/\*' --include='*.php'
This will detect all php files that start with a php tag;
find ./ -iname '*.php' | xargs head -v -n 1 | grep -B 1 '<?php'
-B 1: keep 1 line before the match so we get the filename.This is quick and dirty, you can get fancy to make the output nicer or make it more robust.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With