3 ms·
What's a reasonable grep alias I should add to my .bashrc?
by maest 6y ago
What's a reasonable grep alias I should add to my .bashrc?
- opan 6y agoI have `gi` aliased to `grep -i`.
- ben509 6y agoThe 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'.
- blibble 6y agogrep -P to use pcre (i.e. what everyone knows)
- xorcist 6y agogrep -r --exclude-dir=.git --exclude-dir=.svn --color=auto