Skip to content

Instantly share code, notes, and snippets.

@smj10j
Last active May 20, 2017 14:22
Show Gist options
  • Save smj10j/5b047b2be344bfbdc7bfcaf3657f3233 to your computer and use it in GitHub Desktop.
Save smj10j/5b047b2be344bfbdc7bfcaf3657f3233 to your computer and use it in GitHub Desktop.
Counts items in a directory
#!/usr/bin/env bash
shopt -s dotglob
function filecount {
DIR=$(dirname "${1:-.}/nonexistentfile")
for item in "${DIR}"/*; do
COUNT=$(($(find "${item}" | wc -l)-1))
if [[ $COUNT -gt 0 ]]; then
echo "${COUNT}: ${item}";
fi
done
}
filecount "$@" | sort -h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment