recursively find files by contents

Here's a script:

Alternatively here is a one shot command:

    
grep -rnw '/path/to/somewhere/' -e 'pattern'
    

doing this all the time

If you do, then you should add this to your bashrc:

    
# grep but recursive
grec() {
    if [ "$#" -lt 1 ]; then
        echo "usage: grec PATTERN [PATH]"
        return 1
    fi

    local pattern="$1"
    local path="${2:-.}"

    grep -RnI --color=auto "$path" -e "$pattern"
}
    

Note that I omitted w in the above command because a lot of the time we don't know what the full word is that we're looking for.


edit this page