Is there a way in linux to look through a directory tree for only those directories that are the ends of branches (I will call them leaves here), i.e., dircetories with no subdirectories in them? I looked at this question but it was never properly answered.
So if I have a directory tree
root/
├── branch1
│ ├── branch11
│ │ └── branch111 *
│ └── branch12 *
└── branch2
├── branch21 *
└── branch22
└── branch221 *
can I find only the directories that are the end of their branch (the ones marked with*), so looking only at the number of directories, not at the number of files? In my real case I am looking for the ones with files, but they're a subset of the 'leaves' that I want to find in this example.