Color Linux command output

后端 未结 10 1340
天命终不由人
天命终不由人 2020-12-09 19:03

For example, I\'d like to color the output of the locate command so it\'s easily distinguished from the other terminal text.

It should work something li

相关标签:
10条回答
  • 2020-12-09 19:44

    I think the hl command available on git hub might help you :
    have a look at http://www.flashnux.com/notes/page_000022_US.html

    0 讨论(0)
  • 2020-12-09 19:45

    As suggested by Jonathan Leffler, comment posted as an anwser:

    grep --color will provide colour

    0 讨论(0)
  • 2020-12-09 19:46

    I prefer use highlight utility:

    highlight -O xterm256 -S sh
    

    -S sh here means treats the input as shell script syntax.

    More info: http://www.andre-simon.de/

    I set it as an alias through ~/.bashrc: enter image description here

    enter image description here

    0 讨论(0)
  • 2020-12-09 19:46

    There is a far better way to achieve customizable coloring:

    colorit

    You can use it as shown in other answers via some_command | colorit but it is nicely configurable over the .coloritrc. In mine I have stuff like

    dnl  Define some useful color variables
    define(`red', `1')
    define(`green', `2')
    define(`magenta', `5')
    dnl
    dnl  Mark macro arguments: regexp foreground-color [background-color]
    dnl
    define(`mark', ``mark "$1"'' `ifelse(`$#', `3', ``"\033[3$2;4$3m"'',
    ``"\033[3$2m"'')' `"\033[m"')
    dnl
    divert
    mark(`warning', magenta)
    mark(`Warning', magenta)
    mark(`Traceback', magenta)
    mark(`Error', red)
    mark(`FAIL', red)
    mark(`ERROR', red)
    mark(`XFAIL', green)
    mark(`ok', green)
    mark(`OK', green)
    mark(`PASS', green)
    

    and use it all the time for coloring compiler output and similar stuff. See my .coloritrc for more.

    0 讨论(0)
提交回复
热议问题