Counting files in a Folder at the Linux Command Line

This command combines ls (directory list) with wc (word count) command to count the number of files in a directory.  I just used it to count over 100k files in a directory and it ran pretty fast, under a second.

ls -1 | wc -l

Output + time

time ls -1 | wc -l
101000

real 0m0.662s
user 0m0.616s
sys 0m0.039s

Leave a Reply

Your email address will not be published. Required fields are marked *