David Oceans
David Oceans

Reputation: 37

How search specify file but you don't know in with path folder is (in bash)?

I can find the content in all files called values.yaml with

find . -name values.yaml | xargs grep -Re port -e target --color

But I would like only find the values.yaml in folders called "stage", so path/bla/bla/stage/values.yaml

I have my best approach with that

find ./*/*/*/stage/ -name values.yaml | xargs grep -Re port -e target --color

The problem is the stage folder sometimes are in level 4, someone in level 3 or 5, etc... I would like do something like that, but doesn't work

find ./**/stage/ -name values.yaml | xargs grep -Re port -e target --color

There are any way to do it regardless of the level where the stage folder is located?

Thank you very much!

Upvotes: 0

Views: 166

Answers (4)

Paul Hodges
Paul Hodges

Reputation: 15273

Ok, caveat scriptor: one test worked great, a different one never came back. I suspect the bad one is specific to something on my laptop, but do your own testing and don't waste time on something that's too slow.

That said:

shopt -s globstar
grep -Re port -e target --color ./**/stage/**/values.yaml

Upvotes: 0

William Pursell
William Pursell

Reputation: 212248

It's probably easiest to use -regex:

find . -regex '.*/stage/.*values.yaml'

Or, more accurately:

find -E . -regex '.*/stage/?.*/values\.yaml'

Upvotes: 1

choroba
choroba

Reputation: 241848

You can tell find to match the path:

find -path '*/stage/*' -name values.yaml

Upvotes: 2

David Oceans
David Oceans

Reputation: 37

Maybe on this way?

find . -name stage -type d -exec find {} -name values.yaml \; | xargs grep -Re port -e target --color

Upvotes: 0

Related Questions