Path: utzoo!attcan!uunet!know!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.shell Subject: Re: Leaf directories (Re: Why is find so slow) Message-ID: <9959@jpl-devvax.JPL.NASA.GOV> Date: 13 Oct 90 21:07:53 GMT References: <15052@hydra.gatech.EDU> <26981@mimsy.umd.edu> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 26 In article <26981@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes: : In article flee@guardian.cs.psu.edu (Felix Lee) writes: : >Leaf directories are directories with no subdirectories. A leaf : >directory has a link count <= 2. : : It is easier than that (and harder than this, which leaves out error : checking): : : d = opendir(dir); : fstat(dirfd(d), &st); : nsubdirs = st.st_nlink - 2; : while ((dp = readdir(d)) != NULL) { : if (need_stat_anyway || nsubdirs > 0) { : get_stat(dir, dp->d_name, &st); : if (S_ISDIR(st.st_mode)) : nsubdirs--; : } : ... : } If find is done this way, it would behoove us to sort subdirectories before filenames in each directory so that nsubdirs goes to 0 as soon as possible. Larry Wall lwall@jpl-devvax.jpl.nasa.gov