I want to use grep where paths are arbitrary depth under the directory /path/to/dir and has the file name foo. I thought that the wildcard for arbitrary depth is **, and I triedgrep some_pattern /path/to/dir/**/foobut it seems to be matching only files where the ** part represents a single directory depth like/path/to/dir/bar/fooHow can I match paths for arbitrary depth that is under the directory /path/to/dir and has the file name foo?
Wildcard for arbitrary depth
wildcards;recursive
Use zsh. In the zshexpn(1) man page, Section Recursive Globbing:A pathname component of the form '(foo/)#' matches a path consisting of  zero or more directories matching the pattern foo.As a shorthand, '**/' is equivalent to '(*/)#'; note that this therefore  matches files in the current directory as well as subdirectories.[...] This form does not follow symbolic links; the alternative form '***/'  does, but is otherwise identical.This also means that ** doesn't include hidden directories (whose name starts with a dot) by default. If you want to match them, either set the GLOB_DOTS option or use the D glob qualifier:grep some_pattern /path/to/dir/**/foo(D)With bash, you need to explicitly set the globstar option to make ** work:shopt -s globstar