Algorithm of find command

Hi folks

I'm new here in this forum and hope to find someone who can help me.

I couldn't find a solution already posted in the forum.

Does anyone know what algorithm the shell command find uses? It looks like Top-Down but I need to be 100% sure. So can anyone confirm that?

Thx for your help

I would say it is top-down, depth first, (i.e. not breadth first). If you do a simple find without options, then once it encounters a directory it starts to explore it and if it encounters a subdirectory there, it will do that one first etc... until it reaches the bottom and then it will go sideways and up again..

e.g.:

find . -print|more
.
./.bash_logout
./.bash_profile
./.bashrc
./.gconf
./.gconf/desktop
./.gconf/desktop/gnome
./.gconf/desktop/gnome/accessibility
./.gconf/desktop/gnome/accessibility/keyboard
./.gconf/desktop/gnome/accessibility/keyboard/%gconf.xml
./.gconf/desktop/gnome/accessibility/%gconf.xml
./.gconf/desktop/gnome/%gconf.xml
./.gconf/desktop/gnome/font_rendering
./.gconf/desktop/gnome/font_rendering/%gconf.xml

etc..

find uses ftw() or more likely ntfw(). Read the man page on those functions.

Unix "find" does work broadly as described (by Scrutinizer) above but does not sort the input or output.
It's not even in inode number order.

Try this on a mature tree:

find . -exec ls -id '{}' \;

The stategy is altered by "-depth" parameter:

find . -depth -exec ls -id '{}' \;

Thank you for your answers. I'm going to read the man pages and write my report.