0

I want to find all files in all subdirectories which has a name ExampleDir

eg.

+ ParentDirA
   + ChildDirA
     - file1.txt
   + ExampleDir
     - file2.txt
+ ParentDirB
   + ChildDirB
     - file3.csv
   + ExampleDir
     - file4.csv

Executing command should return: file2.txt and file4.csv

I have tried the following:

find . -type d -name "ExampleDir" | xargs find -type f
find . -type d -name "ExampleDir" -exec find -type f {} \;
find . -type d -name "ExampleDir" -exec find -type f {} +

They all return:

find: paths must precede expression

If I were to go down this route (which I think is logical) I would have to find out how to pipe the path to the find command.

Is there a better way?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

2 Answers2

0

I found my answer over at: Make xargs pass as first parameter

find . -type d -name "ExampleDir" | xargs -I {}  find {} -type f
0

Consider simplifying things with GNU find's -path extension:

find . -type f -path "*/ExampleDir/*"
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255