Fast way to find the number of files in one directory on Linux -


I'm exploring a faster way to find the number of files in a directory on Linux.

Any solution that takes linear time in the number of files in the directory is not acceptable (such as "LCE-wc -l" and similar things) because it is a prohibited form of time long Lega (files in tens or maybe millions of directories).

I'm sure the number of files in the directory should be stored in the filesystem structure (ndode perhaps?) As a simple number, store directory entries as part of the data structure - I How can I go to number?

EDIT: If the filesystem is EX3, there is no portable way to do this, then I am ready to do something special for EX3.

Why should a figure structure have a number? A tree does not need to know its shape in o (1), unless it is a requirement (and to provide it, more locking and possibly a performance hurdle may be required).

I do not mean the meaning of the tree

EDIT: Ext2 stores it as a linked list.

Modern ext3 tools

Saying that / bin / ls does a lot more than the count, and in fact all the inode scans use Opendir () and readdir () Write your own program or script.

From:

  #include & lt; Stdio.h & gt; # Include & lt; Sys / types.h & gt; # Include & lt; Dirent.h & gt; Int main () {int count; Structure DIR * D; If ((D = opendir (".") = Null) {for (count = 0; readdir (d)! = NULL; count ++); closedir (d);} Printf ("\ n% d" Count); return 0;}  

Comments