Created
August 30, 2020 04:52
-
-
Save pn11/c7ee296fe6d63d33ab6ce4ef13334f30 to your computer and use it in GitHub Desktop.
Count files in a directory recursively with Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/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" | |
done | |
} | |
count_files $1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment