Find Regextype non recursive

I'm trying to isolate some PHP infected files which includes 8 alphanurical chars from the /home directory and recursively.

I'm able to have them located once I'm on the directory with the command:

find ./ -regextype posix-egrep -regex ^./[a-zA-Z0-9]{8}\.php$

Or

find ./ -regextype posix-egrep -regex '^./[a-zA-Z0-9]{8}\.php$'

But as soon as I try from another directory:

 find /home -regextype posix-egrep -regex '^./[a-zA-Z0-9]{8}\.php$'

It comes without any results. I have tried to add the flag -L (--follow) but it comes without any results and there are many. file system loop errors.

I have read many answers online which seems to be related on glob and find works. I tried different solutions such as :

find . -type f -print | egrep '^./[a-zA-Z0-9]{8}\.php$'

Ideally the output should be the full path regardless of depth so I may quickly delete them all.


The main point is that find command regex needs to match the entire path with the file name. So, if there is are other folder/directory names before the file name, you need to consume them, too.

Besides, [a-zA-Z0-9] is better replaced with [[:alnum:]]:

find /home -regextype posix-egrep -regex '^.*/[[:alnum:]]{8}\.php$'

Actually, ^ is redundant here:

find /home -regextype posix-egrep -regex '.*/[[:alnum:]]{8}\.php$'

will work, too.