I want to find all PHP scripts that are inside a directory named web
. In particular, I'm interested in any files named index.php
in any of these directories.
I know that I can use sudo find / -type d -name "web"
to list all the directories, and then I can use sudo find <directory path> -type f -name "*.php"
for each of the output paths, to see if it contains a PHP script.
But is there a way to do this in one line and two nested find commands: one find command used to get the paths to the web
directories, and the second to use each of those directories in turn as the root for finding a file whose name matches the pattern *.php
?
You don't need to call
find
twice if you use the-path
option instead of-name
:Specifically for every file
index.php
located under a directory namedweb
:This command should achieve that:
Tested on this tree:
Result: