Ubuntu: How to count the number of Files in a Directory via the Terminal CodeUnit 18 JUL 2011

In order to count the number of files in a directory or folder in Ubuntu via the terminal, it is a simple matter of using the ls listing command with a numeric 1 switch and then piping its result to the line count function wc. In practice, this would retrieve the number of files in the current working directory (non recursive):

ls -1 | wc -l

If you say need a recursive count of all the files under the current working directory, simply run:

find . -type f | wc -l


Related Posts:

About Craig Lotter

Software developer, husband and dad to two little girls. Writer behind An Exploring South African. I don’t have time for myself any more.

  • super tips this are very informative 

  • When using the terminal to navigate your way through your Ubuntu or any other Linux distro, it is actually pretty easy to quickly see how big a particular 

  • Wim Feijen

    Thanks for the tip Craig! 

    To just count files of a certain type, f.e. .png, I used:

    find . -type f | grep .png | wc -l

    • John

      you can also use:
      find. -iname *.png | wc -l

  • Thang

    Thank you so much for your sharing!