Categories
Linux Server Administration Tips

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.

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.

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

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.

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.

@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.

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.