Skip to content

Instantly share code, notes, and snippets.

@veewee
Last active August 29, 2015 14:04
Show Gist options
  • Save veewee/11859e7cf2364bf7b718 to your computer and use it in GitHub Desktop.
Save veewee/11859e7cf2364bf7b718 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# ./filecount-stats [dir1] [dir2] ...
#
TOTAL_FILES=0
TOTAL_LINES=0
for DIR in "$@"
do
echo "Reading $DIR"
DIR_FILES=$(tree "$DIR" | wc -l)
DIR_LINES=$(find "$DIR" -type f -exec wc -l {} \; | awk 'BEGIN{total = 0} {total += $1} END{print total}')
TOTAL_FILES=$(expr $TOTAL_FILES + $DIR_FILES)
TOTAL_LINES=$(expr $TOTAL_LINES + $DIR_LINES)
done
echo "Total Files: $TOTAL_FILES"
echo "Total lines: $TOTAL_LINES"
echo "Avg lines per file: $(expr $TOTAL_LINES / $TOTAL_FILES)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment