Finding subdirectories inside all directories with the same name

find can do this all by itself:

find X -path '*/inc/*' -type d > list

Read the -path part of man find for more info.

As I mentioned quickly in a comment: if you store the directories line separated in a text file, directory names containing newlines won't be unambiguously representable. If you are certain that directories don't contain newlines, that's OK. Just a general remark.


Here's a handy one-liner:

find X -type d -name "inc" -exec sh -c 'find {} -type d' \; > list

It runs find on each of the first find results. The exec option can also take a minimal shell command, in which – as I said – {} is replaced with each directory of the first find.

The second find will, per your request, "list all subdirectories" of the first results, including the inc directory. If you don't want that itself in the output, let the second find at least output folders of depth 1.

find X -type d -name "inc" -exec sh -c 'find {} -mindepth 1 -type d' \; > list

We'll then just redirect the command's stdout into list.


Alright I have found the answer to simulate this nested find:

find X/ -type d | grep "/inc/" > list

Try this:

   find path-of-x -path '*/inc/*' -type d > list