How to list (for two given directories) the directories with the same names and the relative paths under the trees.

advertisements

For selected two directories list the directories with the same names and relative paths under the trees. Do not nest calls find.

I dont even know how to start it. Should be some loop or only find command?


Given the directories a and b, here's another way of looking at it:

(cd a && find -type d ; cd ../b && find -type d) | sort | uniq -d

If you only want the top level directories listed, adding a grep to the pipeline would remove all subdirectories:

(cd a && find -type d ; cd ../b && find -type d) | sort | uniq -d | grep '^[^/]*/[^/]*$'

Slightly easier to read:

(cd a && find -type d ; cd ../b && find -type d) \
  | sort \
  | uniq -d \
  | grep '^[^/]*/[^/]*$'