让Linux的Shell提示和输出是彩色的

在使用最新的Ubuntu的时候发现终端的提示符是彩色的
在这里插入图片描述
而在CentOS8中以及容器中的Linux系统一般都不是彩色提示,如果想要彩色提示,在/etc/profile.d/目录中加入一个脚本文件(Linux登录过程中加载配置文件顺序是:/etc/profile → /etc/profile.d/.sh → ~/.bash_profile → ~/.bashrc → [/etc/bashrc])*,比如colorprompt.sh,编写内容如下:

PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

这样设置后,如果是root时,提示符为:# ,普通用户则为:$

PS1中设置字符颜色的格式为:[\e[F;Bm],其中“F“为字体颜色,编号为30-37,“B”为背景颜色,编号为40-47。用 \e[m 结束颜色设置,颜色表如下:

F    B
30    40    黑色
31    41    红色
32    42    绿色
33    43    黄色
34    44    蓝色
35    45    紫红色
36    46    青蓝色
37    47    白色

在有的系统中,ls、grep、fgrep、egrep命令的输出可能没有颜色,或者没有ll命令,也可以在此文件中加入命令:

alias ls='ls --color=auto'
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

在这里插入图片描述

Guess you like

Origin blog.csdn.net/witton/article/details/121585451