「Linux」- 颜色化输出 @20210409

问题描述

在终端中,我们经常查看日志输出(不管是自己的 Shell 脚本,还是运行其他程序),以了解程序执行情况。

但是,所有的终端日志颜色都是相同的(通常默认都是白色字体),

该笔记将记录:将终端输出变成彩色的方法

解决方案

方法一、ANSI escape code - 最古老的方法

使用 ANSI escape code 是最古老的方法:

# echo -e "\033[31;1;4mHello\033[0m"
Hello

该命令将输出带下划线的红色 Hello 字符串

方法二、grc

# grc tail -f /var/log/syslog

该命令将高亮 syslog 日志输出,通过配置文件可以进行更多控制

其他工具

colortail
GitHub - joakim666/colortail: Like the tail command line utility but with colors

colorex
GitHub - Scopart/colorex: A python script to display log files with colors.

colout
GitHub - nojhan/colout: Color text streams with a polished command line interface

TxtStyle
GitHub - armandino/TxtStyle: Command-line tool for colorizing console output and log files based on regular expressions

rainbow
GitHub - nicoulaj/rainbow: Colorize commands output or STDIN using patterns.

highlight
André Simon - Startseite

lolcat
GitHub - busyloop/lolcat: Rainbows and unicorns!

相关文章

「Bash」- umask
「Shell」- 使用环境变量,替换在文件中的变量(envsubst)
BASH Shell内建命令:type

参考文献

terminal - Output in color - Bash - Unix & Linux Stack Exchange
GitHub - garabik/grc: generic colouriser


posted @ 2021-04-09 23:35  研究林纳斯写的  阅读(137)  评论(0编辑  收藏  举报