findstring

I have this little library of scripts and configuration files for my Unix environment that I've carried with me across different systems, employers, and jobs. I've had versions of .bashrc, .vimrc, and various utility scripts for years; many have been with me since college. Some have been modified or replaced as my needs or the tools I use change, but they are always first things I copy over whenever I get a new login.

One of these essential tools is a simple bash script called "findstring"; it returns the names of any files in a selected path that contain a given search term. I originally used it when working on some cross-platform C++, using it to find out what files used a given function or where a certain class was defined. Use of the script is simple:

findstring search path

where "search" is the string you're looking for, and the (optional) path is where to begin the search; if not specified, it defaults to the current directory. The entire script is below -- let me know if it's useful to you, or if you have suggestions for improvement.

#!/bin/bash
# Usage: findstring search path
# prints files in path containing string search (case insensitive)

# If second argument is omitted, default to current directory
if [ -z $2 ]
then
searchPath="."
else
searchPath=$2
fi

find $searchPath -type f -exec grep -i -l "$1" \{\} \;