Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Selecting leaf directories only

On Wed, Feb 07, 2001, Andrej Borsenkow wrote about "RE: Selecting leaf directories only":
> > 
> > Isn't it true that the link count of leaf directories is exactly 2?
> > Therefore I would try **/*(/l2) .
> > 
> Yep. Now that's real black magic :-)

Just watch out - the fact that the number of links of a directory is 2 plus
the number of its subdirectories, is true only on standard Unix filesystems.
If you mount a filesystem through SMB, or a CD-ROM, for example, it is no
longer true.

A relevant quote from the GNU find(1) manual that discusses this issue:
              Do not optimize by assuming that  directories  con­
              tain  2  fewer  subdirectories than their hard link
              count.   This  option  is  needed  when   searching
              filesystems  that do not follow the Unix directory-
              link convention, such as CD-ROM or MS-DOS  filesys­
              tems or AFS volume mount points.  Each directory on
              a normal Unix filesystem has at least 2 hard links:
              its  name  and  its  `.'  entry.  Additionally, its
              subdirectories (if any) each  have  a  `..'   entry
              linked to that directory.  When find is examining a
              directory, after it has statted 2 fewer subdirecto­
              ries than the directory's link count, it knows that
              the rest of the entries in the directory  are  non-
              directories  (`leaf'  files in the directory tree).
              If only the files' names need to be examined, there
              is  no  need to stat them; this gives a significant
              increase in search speed.

Nadav Har'El                        |    Wednesday, Feb 7 2001, 14 Shevat 5761
nyh@xxxxxxxxxxxxxxxxxxx             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Why do doctors call what they do
http://nadav.harel.org.il           |practice? Think about it.

Messages sorted by: Reverse Date, Date, Thread, Author