Linux: count number of files in a directory
Posted: October 31st, 2007 | Author: steve | Filed under: linux |The following command will print the number of files in the current directory:
ls | wc -l
The ‘ls’ command prints the directory listing. The output of ls is piped into the wc command by the inclusion of the ‘|’. Finally, the ‘wc’ command performs a word count on the directory listing it was given, and because ls outputs each filename as a word, you get the number of files in the directory.



Thank you man!
your solution works great.
Unfortunately this wont work on directories with a lot of files in them; you’ll get the “Argument list too long” error…