-
-
Save TheRakeshPurohit/d499b12a91f18a4dfcf9e7c51fd6e320 to your computer and use it in GitHub Desktop.
Count the number of files in a directory
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
# This works even with really weird filenames like $'--$`\! *@ \a\b\e\E\f\n\r\t\v\\\"\' ' | |
file_count() | |
{ | |
if [ ! -e "$1" ] | |
then | |
exit 1 | |
fi | |
local -i files=$(find "$(readlink -f -- "$1")" -type f -print0 | grep -cz -- -) | |
echo $files | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment