1.编辑系统文件
CentOS/RHEL
编辑系统.bashrc
文件
注意:.bashrc
是一个隐藏的文件,如果无法打开需要用ls -a
命令找到.bashrc
文件,然后再打开即可;
编辑文件:vi ~/.bashrc
找到代码:#force_color_prompt=yes
替换其为:force_color_prompt=yes
继续编辑.bashrc
文件,颜色设置在if [ "$color_prompt" = yes ]; then
的下面一行,替换掉其代码即可;
原始代码
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
替换代码
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]'
Debian/Ubuntu
需在用户
.bashrc
添加
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]'
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
2.生效
source .bashrc # CentOS/RHEL
评论区