Search code examples
regexfindsubdirectorydepth

Using find to get files in subfolders with a specific name but unknown depth


I have a file structure like this:

/home/user/.m2/repository/../*SNAPSHOT/..

And I try to get all files in those SNAPSHOT folders, but they have a different depth. My command looks like this right now:

find /home/user/.m2/repository/*/*SNAPSHOT* -type f -name "*201[3-4]*"

but like this he only search for a depth of 1. What must I type for the * in my solution to get any depth of subfolders?

I tried to do some regex magic, but didn't find anything working :)

Anyone has something useful for me?


Solution

  • If I understood the question correctly, I think this should work for you:

    find /home/user/.m2/repository -path '*/SNAPSHOT/*' -type f -name '*201[3-4]*'
    

    Basically the trick is to use -path with find.