Skip to content

Instantly share code, notes, and snippets.

@aprell
Created November 10, 2011 09:42
Show Gist options
  • Save aprell/1354509 to your computer and use it in GitHub Desktop.
Save aprell/1354509 to your computer and use it in GitHub Desktop.
Searches for a string in all files of a directory. Useful wrapper for grep.
#!/bin/bash
usage="Usage: findstring <string> [directory]"
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo $usage
exit 0
fi
if [ $# -eq 1 ]; then
dir=`pwd`
else
dir=$2
fi
echo "Searching for \"$1\" in $dir"
grep --recursive --color=auto --with-filename --line-number \
--binary-files=without-match "$1" $dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment