Count lines of code in a Django Project Count lines of code in a Django Project django django

Count lines of code in a Django Project


Yep:

shell]$ find /my/source -name "*.py" -type f -exec cat {} + | wc -l

Job's a good 'un.


You might want to look at CLOC -- it's not Django specific but it supports Python. It can show you lines counts for actual code, comments, blank lines, etc.


Starting with Aiden's answer, and with a bit of help in a question of my own, I ended up with this god-awful mess:

# find the combined LOC of files# usage: loc Documents/fourU py htmlfunction loc {    #find $1 -name $2 -type f -exec cat {} + | wc -l    namelist=''    let i=2    while [ $i -le $# ]; do        namelist="$namelist -name \"*.$@[$i]\""        if [ $i != $# ]; then            namelist="$namelist -or "        fi        let i=i+1    done    #echo $namelist    #echo "find $1 $namelist" | sh    #echo "find $1 $namelist" | sh | xargs cat    echo "find $1 $namelist" | sh | xargs cat | wc -l}

which allows you to specify any number of extensions you want to match. As far as I can tell, it outputs the right answer, but... I thought this would be a one-liner, else I wouldn't have started in bash, and it just kinda grew from there.

I'm sure that those more knowledgable than I can improve upon this, so I'm going to put it in community wiki.