Skip to content

Instantly share code, notes, and snippets.

@spudfkc
Last active December 20, 2015 10:30
Show Gist options
  • Save spudfkc/6115730 to your computer and use it in GitHub Desktop.
Save spudfkc/6115730 to your computer and use it in GitHub Desktop.
Looks for occurrences of a string in all files in the specified directory (defaults to current) For best results put in ~/.bashrc
findString() {
if [ -z "$1" ]
then
echo "usage: findString "string" [whereToLook]"
return 1
fi
if [ -z "$2" ]
then
wheretolook=$(pwd)
else
wheretolook=$2
fi
echo "looking for $1 in $wheretolook"
FILES=$(find $wheretolook -type f -name "*")
for FILE in $FILES
do
tput bold
tput setaf 4
grep -ls "$1" "$FILE"
tput sgr0
grep -ns "$1" "$FILE"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment