I'm on RHEL 7. This works for me:
find . -path "*/foo/*" ! -path '*/foo/*/*' -type f
Note the DOT before the -path. (Or substitute your path there, such as /home/$USER)
The DOT says "Start looking in the current directory"
the -path says "Look for anything, followed by a sub-directory named foo, followed by anything" except for directories nested under "foo".
The -type f says give me only the files in a matching directory.
Looks
Looks like
-path "*/foo/*" ! -path '*/foo/*/*'
Doesn't get everything as it misses things like ./a/foo/b/foo/c. Not elegant
If you can guarantee that file and directory names won't contain newline characters, but it worksyou could post-process the output with awk like:
find . -path "*/foo/*" -type f | awk -F'F/' '{if (match$'$(NF-1),"foo")) print $0}' == "foo"'