让 less 显示 ANSI 控制字符

为了醒目,我们常把信息比如日志以彩色输出到终端,这会用到 ANSI 彩色控制字符。

通常输出到文件的时候,为了分析或者查看方便(很多工具不识别),则往往不输出彩色。

 

其实输出彩色还是有些工具能查看的,比如 cat 就可以,还有就是 less 也是可以的,用 -R 选项即可:

 

       -R or --RAW-CONTROL-CHARS
              Like -r, but only ANSI "color" escape sequences  are  output  in
              "raw" form.  Unlike -r, the screen appearance is maintained cor-
              rectly  in  most  cases.   ANSI  "color"  escape  sequences  are
              sequences of the form:

                   ESC [ ... m

              where  the  "..." is zero or more color specification characters
              For the purpose of keeping  track  of  screen  appearance,  ANSI
              color  escape sequences are assumed to not move the cursor.  You
              can make less think that characters other than "m" can end  ANSI
              color  escape  sequences  by  setting  the  environment variable
              LESSANSIENDCHARS to the list of characters which can end a color
              escape  sequence.   And  you can make less think that characters
              other than the standard ones may appear between the ESC and  the
              m  by  setting  the environment variable LESSANSIMIDCHARS to the
              list of characters which can appear.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值