ubuntu-修改root用户终端显示颜色-bash

问题:root用户下,命令行没有高亮,看起来非常的累;

image

在root下编辑:

vim ~/.bashrc

看到:

 36 # uncomment for a colored prompt, if the terminal has the capability; turned
 37 # off by default to not distract the user: the focus in a terminal window
 38 # should be on the output of commands, not on the prompt
 39 force_color_prompt=yes
 40 
 41 if [ -n "$force_color_prompt" ]; then
 42     if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
 43         # We have color support; assume it's compliant with Ecma-48
 44         # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
 45         # a case would tend to support setf rather than setaf.)
 46         color_prompt=yes
 47     else
 48         color_prompt=
 49     fi
 50 fi
 51 
 52 if [ "$color_prompt" = yes ]; then
 53     PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
 54 else
 55     PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
 56 fi
 57 unset color_prompt force_color_prompt
 58 

force_color_prompt 前面的# 去掉就行了

官方不建议root用户开启颜色,但是我不习惯

结果:

image

posted @ 2026-01-04 18:10  年华似水゛  阅读(3)  评论(0)    收藏  举报