Find the number of files in a directory

Viewed 31680

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.

8 Answers

For the number of all file in a current directory try this:

ls -lR * | wc -l
Related