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?

0

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

find . -type f -path "*/ExampleDir/*"
0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.