Find the number of files in a directory

Is there any method in Linux to calculate the number of files in a directory (that is, immediate children) in O(1) (independently of the number of files) without having to list the directory first? If not O(1), is there a reasonably efficient way?

I'm searching for an alternative to ls | wc -l.

25
задан Mechanical snail 23 August 2012 в 01:40
поделиться