Created
March 31, 2016 10:11
-
-
Save mattward/6bc2c1529937915434ffb196865d789a to your computer and use it in GitHub Desktop.
Count files in the given directories
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 | |
script_name=`basename $0` | |
if [[ "$1" == "--help" ]]; then | |
echo "Usage ${script_name} [subdirectory1 [subdirectory2]...]" | |
echo "Counts the files in the specified directories, or in all subdirectories if none specified" | |
exit 1 | |
fi | |
# Default to all subdirectories, or those specified | |
if [[ "$1" == "" ]]; then | |
directories=* | |
else | |
directories="$@" | |
fi | |
for dir in $directories; do | |
count=`find $dir -type f | wc -l` | |
echo "$count $dir" | |
done | sort -n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: