Files in Unix file systems have a link count which indicates how many
names point to the same inode. Directories in Unix filssytems have a
.. entry which functions as a hard link to the parent directory
and a . entry which functions as a link to the directory itself.
The .. entry of the root directory also points to the root.
This means that find
can deduce the number of subdirectories a
directory has, simply by subtracting 2 from the directory’s link
count. This allows find saving stat
calls which would
otherwise be needed to discover which directory entries are
subdirectories.
File systems which don’t have these semantics should simply return a
value less than 2 in the st_nlinks
member of struct stat
in response to a successful call to stat
.
If you are building find
for a system on which the value of
st_nlinks
is unreliable, you can specify
--disable-leaf-optimisation
to configure
to prevent this
assumption being made.