Skip to content

Instantly share code, notes, and snippets.

@Gen2ly
Created June 2, 2012 12:32
Show Gist options
  • Save Gen2ly/2858162 to your computer and use it in GitHub Desktop.
Save Gen2ly/2858162 to your computer and use it in GitHub Desktop.
Search file(s) for keyword
#!/bin/bash
# Search file(s) for keyword
# Display usage if no parameters given
if [[ -z "$@" ]]; then
echo -e " ${0##*/} <string> <file/path> - search recursively for keyword in files"
exit
fi
if [ -z "$2" ]; then
loc=$(pwd)
else
loc="$2"
fi
echo " Searching..."
grep -ilr "$@" "$loc" 2>&1 | grep -v "No such" | grep -v "Permission denied" | sed "s:^\.::g" | sed "s:$(pwd)::g" | sort | uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment