2 ms·
The only flag I'd say I want 99% of the time is -E (same as calling egrep) because extended regular expressions are what you almost always want. A sibling comm
by ben509 6y ago
The only flag I'd say I want 99% of the time is -E (same as calling egrep) because extended regular expressions are what you almost always want.
A sibling comment suggested -i, other useful flags are -w (find whole words) and -C (change the amount of context around matches), but I don't think I always use those.
A handy function for searching a tree:
greptree() {
find "$1" -name "$2" -type f -exec egrep "$3" '{}' +
}
greptree . '*.java' 'foo[123]'
That would search all java files in the current tree. One thing people often don't know is that -exec ... {} + in modern 'find' works like piping to xargs.
All that said... when I'm searching a tree, I can usually use 'git grep'.