I have bunch of wordpress sites that are hosted in shared hosting environment. As with every wordpress site there are "uploads" directory. I would like to search for potentially malicious files that are within those folders regularly but i dont want to ofcourse do it one by one.

So question is how can i search all "uploads" directories for a file with extension ".php"

For example:

find . -type d -iname "uploads"

gets me all the "uploads" folders in my root directory but i also want to search within those director


It's possible to pipe the output from your command to another, but you can search for both criteria at once, using grep and Regular Expressions:

find . -type f | grep -i "/uploads/.*\.php$"

How it works:

  • find . -type f lists all files in the current directory and its subdirectories.

  • grep -i "/uploads/.*\.php$" filters the output:

    • -i makes the search case-insensitive

    • /uploads/.*\.php$ is the regular expression a line has to match in order to get displayed

      • /uploads/ php are exactly that

      • .* is any number of occurrences of any type of characters

      • \. is a literal .

      • $ signals the end of the line

You can achieve the same result with

find . -type f -iregex ".*/uploads/.*\.php"

but the syntax is a hassle if you know Regular Expressions from grep, Perl, PHP, JavaScript, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.