The best way to find directories that exactly match a string irrespective of the path

command linedirectoryfind

Suppose I have the directories:

/foo/
/A/B/C/foo/D/E/
/F/foo/G/H/foo/I/

How can get a result that lists all the directories whose basename exactly matches
a given string (for example foo in here)?

/foo/
/A/B/C/foo/
/F/foo/
/F/foo/G/H/foo/

Best Answer

You can use find:

$ find / -type d -name foo -print
Related Question