首页 > 应用开发 > IT综合 > 【Shell】grep命令在结果集中显示绿色的字符
2.要达到grep命令在结果集中显示绿色的字符的效果,仅仅需要做如下两个环境变量的设置即可
export GREP_OPTIONS='--color=always'
export GREP_COLOR='1;32'
3.解释一下
export GREP_OPTIONS='--color=always'
效果是:grep到的关键字以默认的红颜色来显示
export GREP_COLOR='1;32'
此设置即表示颜色为绿色(32表示绿色)
4.展示一下效果
[root@testdb ~]# export GREP_OPTIONS='--color=always'
[root@testdb ~]# export GREP_COLOR='1;32'
[root@testdb ~]# ps -ef | grep ora_ | grep -v grep
oracle 11731 1 1 11:17 ? 00:00:00ora_j000_ora10g
oracle 17482 1 0 Jul20 ? 00:00:00ora_q001_ora10g
oracle 31027 1 0 Jul10 ? 00:02:03ora_pmon_ora10g
oracle 31029 1 0 Jul10 ? 00:01:35ora_psp0_ora10g
oracle 31031 1 0 Jul10 ? 00:01:43ora_mman_ora10g
oracle 31033 1 0 Jul10 ? 00:02:09ora_dbw0_ora10g
oracle 31035 1 0 Jul10 ? 00:02:15ora_lgwr_ora10g
oracle 31037 1 0 Jul10 ? 00:02:33ora_ckpt_ora10g
oracle 31039 1 0 Jul10 ? 00:02:31ora_smon_ora10g
oracle 31041 1 0 Jul10 ? 00:01:08ora_reco_ora10g
oracle 31043 1 0 Jul10 ? 00:02:27ora_cjq0_ora10g
oracle 31045 1 0 Jul10 ? 00:02:28ora_mmon_ora10g
oracle 31047 1 0 Jul10 ? 00:02:12ora_mmnl_ora10g
oracle 31429 1 0 Jul10 ? 00:00:57ora_arc0_ora10g
oracle 31431 1 0 Jul10 ? 00:02:11ora_arc1_ora10g
oracle 31435 1 0 Jul10 ? 00:01:47ora_qmnc_ora10g
oracle 31471 1 0 Jul10 ? 00:01:31ora_q000_ora10g
5.如果想要长期有效,可以将这两个环境变量写入到用户的profile中
以我的Linux环境为例,需要添加该内容的文件是 ~/.bash_profile
-- The End --
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22661144/viewspace-1058081/ ,如需转载,请注明出处,否则将追究法律责任。