ITPub博客

首页 > 应用开发 > IT综合 > 【Shell】grep命令在结果集中显示绿色的字符

【Shell】grep命令在结果集中显示绿色的字符

原创 IT综合 作者:fjzcau 时间:2012-04-30 18:04:49 0 删除 编辑
这是一个比较有趣的尝试
这是一个可以提高效率的小尝试

1.看一下我操作系统的版本信息:
[root@testdb ~]# uname -a
Linux testdb 2.6.18-53.el5xen #1 SMP Wed Oct 10 16:48:44 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux[@more@]


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:03
ora_pmon_ora10g
oracle 31029 1 0 Jul10 ? 00:01:35
ora_psp0_ora10g
oracle 31031 1 0 Jul10 ? 00:01:43
ora_mman_ora10g
oracle 31033 1 0 Jul10 ? 00:02:09
ora_dbw0_ora10g
oracle 31035 1 0 Jul10 ? 00:02:15
ora_lgwr_ora10g
oracle 31037 1 0 Jul10 ? 00:02:33
ora_ckpt_ora10g
oracle 31039 1 0 Jul10 ? 00:02:31
ora_smon_ora10g
oracle 31041 1 0 Jul10 ? 00:01:08
ora_reco_ora10g
oracle 31043 1 0 Jul10 ? 00:02:27
ora_cjq0_ora10g
oracle 31045 1 0 Jul10 ? 00:02:28
ora_mmon_ora10g
oracle 31047 1 0 Jul10 ? 00:02:12
ora_mmnl_ora10g
oracle 31429 1 0 Jul10 ? 00:00:57
ora_arc0_ora10g
oracle 31431 1 0 Jul10 ? 00:02:11
ora_arc1_ora10g
oracle 31435 1 0 Jul10 ? 00:01:47
ora_qmnc_ora10g
oracle 31471 1 0 Jul10 ? 00:01:31
ora_q000_ora10g

5.如果想要长期有效,可以将这两个环境变量写入到用户的profile中
以我的Linux环境为例,需要添加该内容的文件是 ~/.bash_profile

-- The End --

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22661144/viewspace-1058081/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-04-03

  • 博文量
    208
  • 访问量
    548332