Before I resort to writing Python to do this - there must be a way in bash with find or similar tools. I want to search a tree, and find all files whose name matches a pattern, that are in a directory matching another pattern. For example: all files named foo_[0-9][0-9] in a dir named bar_[0-9]. So, I want all these files found (from the current dir):



2 Answers 2


For this case, you can use the -path <pattern> option, similar to the -name option of find:

find . -path "*bar_[0-9]/foo_[0-9][0-9]"
  • Sorry, doesn't work. Actually, how do I find any dirs named bar_[0-9], forget about the file part? I can't find a "find . -path" way that works.
    – D Strozzi
    May 11, 2022 at 22:43
  • Then you can try "*bar_[0-9]*foo_[0-9][0-9]". See man find , that / is not treated specially for this pattern. But you have not said that in the question, it curently says: all files named foo_[0-9][0-9] in a dir named bar_[0-9]
    – thanasisp
    May 11, 2022 at 22:45
  • Oops, you were right, I messed up. Thanks for the help!
    – D Strozzi
    May 11, 2022 at 22:52

In bash (and other shells with similar functionality) you could use globstar

shopt -s globstar nullglob

printf '%s\n' **/bar_[0-9]/foo_[0-9][0-9]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .