Color Linux command output

后端 未结 10 1363
天命终不由人
天命终不由人 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:40

    Use the tput command.

    Most terminals support 8 foreground text colors and 8 background colors (though some support as many as 256). Using the setaf and setab capabilities, we can set the foreground and background colors. The exact rendering of colors is a little hard to predict. Many desktop managers impose "system colors" on terminal windows, thereby modifying foreground and background colors from the standard. Despite this, here are what the colors should be:

    Value Color

    0 Black

    1 Red

    2 Green

    3 Yellow

    4 Blue

    5 Magenta

    6 Cyan

    7 White

    8 Not used

    9 Reset to default color

    Actual example: set color to red, cat and then change color back:

    tput setaf 1; cat /proc/meminfo ; tput setaf 9
    

提交回复
热议问题