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 Fletcher16 Jan 2025
get IP address from terminal OSX
When troubleshooting network issues or configuring devices, knowing your IP address can be essential. Whether you're connected via Wi-Fi, Ethernet, or tethering through a mobile provider, macOS offers powerful built-in tools to quickly identify your IP address. Here's a practical guide tailored to...