OK, how do I count files in a directory QUICK!!!

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: kitepilot@kitepilot.com
Date:  
To: Main PLUG discussion list
Old-Topics: OT: Why does my Google hosted email gets caught in others spam filters?
Subject: OK, how do I count files in a directory QUICK!!!
NAHW, that's easy:
ls|wc -l

Or I could, (couldn't I)
find . -type f|wc -l

There are other tricks, like:
du -a|wc -l

Etc, etc, etc...

There are also implications of depth, whether I want only files, and on, and
on, and on...

I'll keep it easy:
It is a directory that only contains files.
So, you'd say:
what's wrong with "ls|wc -l" ?

Well, here is the catch:
There are almost a million files in that directory.
And it gets worse:
This count has to be placed in a loop in a shell script to report a
second-to-second delta.

The truth is that find takes some 3 seconds to do the count.
What about ls without sorting?
That was almost 15 seconds.

Now, directories are files.
It would be great if I could "count lines" on that file or somehow
interrogate it "how many lines do you have?" without actually hitting the
filesystem for the count.
I'm considering writing a little C utility to do just that, but...
"struct stat" (my first shot) doesn't contain that information either.

Finally, the question is:
Is there a utility that would tell me QUICK a file count under a directory
(regardless of type)?

And if not, are there C/C++ system calls that would tell me that?
Thanks everyone! :)
Enrique A. Troconis
---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss