How to count files (get the number of files) under a directory in Linux?

Just perform this command under the directory:

find . -type f | wc -l

and you will get the total number of files under it (recursively). Simply copy and paste that to do the trick.

Or if you just need to count the files directly under the current directory:

ls -f | wc -l

Which is a lot faster than the previous solution.

This should also work on all *nix OS.

13 thoughts on “How to count files (get the number of files) under a directory in Linux?”

  1. I will try this command later when I switched to Linux. I am still in exploration stage in Ubuntu and I am having difficulty every now and then that is why I tend to go back to Windows when I am rushing up something.

  2. Hi! Are you interested in getting a banner/ header/ logo/ template/ business cards/ mascot designs / directory or article submissions, for your site for no money, in return we require text links from your site https://www.kavoir.com. Approaching you through this form since I could not find out the email address. Please get back to me if you are interested.

  3. @Hans

    While many agree that learning new things is exciting, refreshing and often bringing new perspectives, it’s in nature a cost.

    Every new approach comes with a cost, to adopt it or not is the question of cost-effectiveness.

  4. I am going to switch to linux in a few days, most likely sometime before Christmas! I will surely have to save this code somewhere. This will make life much easier. Thanks for the quick tip!

    Thank You,

  5. Unfortunately this wont work on directories with a lot of files in them; you’ll get the “Argument list too long” error…

  6. @Chris
    I used it under a directory with around 18,000 gif images and it didn’t show up the error. What’s the rough number of files you have?

  7. Thank you for this tip. At some point I also needed to count files in all subdirectories as well, so I found this solution, may be it will be useful for somebody else:

    ls -laR | wc -l

Comments are closed.

Scroll to Top