Skip to main content

How to count the number of files in a directory.  At some point you'll have a directory or directories that you need to know the number of files in them.  On Linux, the list command (ls) is piped with the wc -l command.

ls | wc -l

This command works great if all the files are located in one directory.  What about if you have multiple directories.  Then you will need to use the find command piped with the wc command

find <directory> -type f | wc -l

This command only files the files and not the directories.  Perfect for me.  But if you also need to count with directories

find <directory> | wc -l

 

Related articles

Andrew Fletcher18 Mar 2024
Resolving CVE-2022-48624 less issue
To resolve the CVE-2022-48624 vulnerability on Ubuntu using Nginx, it's crucial to understand that the issue lies within the "less" package, not Nginx itself. The vulnerability affects "less" before version 606, where close_altfile in filename.c in less omits shell_quote calls for LESSCLOSE,...