Skip to content

Instantly share code, notes, and snippets.

@MidnightLightning
Created August 22, 2011 14:15
Show Gist options
  • Save MidnightLightning/1162476 to your computer and use it in GitHub Desktop.
Save MidnightLightning/1162476 to your computer and use it in GitHub Desktop.
Count lines of text
#!/bin/bash
# Count lines of text files of specified file types:
# Base command from http://www.commandlinefu.com/commands/view/5518/count-lines-of-code-across-multiple-file-types-sorted-by-least-amount-of-code-to-greatest
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` match1 [match2, ...]"
echo "Search the current directory for files matching any of the 'match1', 'match2', etc. parameters, and count number of lines"
echo "Eg: `basename $0` '*.php' '*.html' '*.js' '*.css' # <-- Lines of code in a website"
exit
fi
extensions=$(printf " -iname '%s' -o" "$@")
extensions=${extensions:0:${#extensions}-3} # Trim trailing '-o'
#echo $extensions
cmd="find . \( ${extensions} \) -exec wc -l {} + | sort -n"
echo $cmd
eval $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment