Cleaning up your code: Find All Source Files with “TO-DO” comments in Linux Shell

Keeping track of your TO-DO‘s is not always easy!

Especially if your using mostly plaintext editors for coding your scripts and programs. It’s a good habit to clean up your source code every once in a while and do what you intended with the TODO remark in the first place. Most modern IDE’s have this TO-DO finding feature already integrated, however, sometimes you can work faster using plaintext editors (and also leave a big mess behind :-) ).

For the same messiness I often exert myself, I created this short script to help me clean up the source code, implement the “dummy functions” and not to forget what I need TO-DO!

Basic Syntax

./todofind [directory=.]

Example of Usage

todofind /home/invision/project/

Sample output:

Total: 15 TO-DO(s) in 9 files


You can view or download the script here:

Or obtain it via shell:

wget -qO- > todofind
chmod +x todofind


# search TODO comments in source code
while getopts "h?" opt; do
    case "$opt" in
                echo "Script for enlisting all files" \
                "and lines with TODO keyword (for source code)"
        echo "Usage:"
        echo "$0"
        exit 0


extensions="php html xml js css sh h c cpp java pl py";

for ext in $extensions ;
        find $(pwd)/ -name "*.$ext" >> $temp 2> /dev/null;


while read file
        cat $file \
                | grep -swiE 'todo|to-do|to do' \
                > $greptemp 2> /dev/null; found=$?

        todocount=$(cat $greptemp | wc -l);
        if [ $found -eq 0 ] ; then
                echo $file
done < $temp ;

echo "Total: $totalcount TO-DO(s) in $filecount files";

rm $temp
rm $greptemp

Linux Shell / Bash Scripting, Tutorials | Posted on July 3, 2013 by .

About Kristijan Burnik

Kristijan Burnik is a Programmer and Web Developer specializing in Server-side and Client-side Technologies and Application Development on Linux Servers and Windows Desktop . Also has experience in Networking, Desktop application development as well as Android mobile application development . Experienced in Programming Languages like Java, C, C++, C#, PHP, Javascript, MySQL and somewhat in other languages like Bash, Perl & Python. Sometimes he works as a Graphical Designer for digital production as well as for printing and advertising. He dedicates his spare time writing Tech Articles on his blog in order to share his work with others, as well as to document his projects for his own use. He's also an Educator & Mentor in field of Algorithms and Programming to young programmers in Zagreb, Croatia.

Leave a Reply