Last active
December 20, 2015 10:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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