Answers:
在$ HOME / .bashrc文件中,添加:
export GREP_OPTIONS="-n --color"
这也适用egrep
于使用grep的别名。
更新:从grep 2.21开始不推荐使用GREP_OPTIONS,如果您使用此解决方案,则会看到以下警告:
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
编辑〜/ .bash_aliases添加一行内容:
alias grep='grep -n --color'
〜/ .bash_aliases由〜/ .bashrc自动包含(如果存在)
.profile
如果您希望它在所有shell中都能正常运行,而不仅仅是bash ,则添加该行。
find /usr/share -name '*.txt' |xargs grep testing