Last active
May 20, 2017 14:22
-
-
Save smj10j/5b047b2be344bfbdc7bfcaf3657f3233 to your computer and use it in GitHub Desktop.
Counts items 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
#!/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