Skip to content

Instantly share code, notes, and snippets.

@l0b0
Created November 26, 2010 14:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save l0b0/716802 to your computer and use it in GitHub Desktop.
Save l0b0/716802 to your computer and use it in GitHub Desktop.
Count the number of files in a directory
# 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