find

find is a command used to search for files on unix filesystems.

Search for a file

This is an example of the basic functionality of the find command.

find /location -type f -name filename.sh

Passing the results to exec

Additional bash commands can be added to the find command to be execed on the results. In this example lets count all non-comment lines of ruby in a directory recursively

find . -type f -name *.rb -exec cat {} \; | grep -vE "^([[:space:]]+)?\#" | wc -l

Print list of file extensions

This will print a count of each type of file extension in a given directory tree

find . -type f -name '*.*' | grep -Eo "\.{1}[^.]*$" | sort | uniq -c | sort -n