Skip to content

Instantly share code, notes, and snippets.

Created Aug 30, 2020
What would you like to do?
Count files in a directory recursively with Bash
# For Mac (Homebrew), use aliases below
#alias find=gfind
#alias sed=gsed
function count_files () {
num_files=$(gfind "$1" -maxdepth 1 -type f | wc -l)
echo "$1 ${num_files}"
find "$1" -maxdepth 1 -type d | tail -n +2 | while read line; do
count_files "$line"
count_files $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment