相關的幾個文件,或許更多
vim /etc/bash.bashrc
vim /etc/profile
vim ~/.bashrc
vim ~/.bash_profile
終端顏色由 PS1 變量進行定義,上面這些文件中就有 PS1 變量。
由於本人剛開始用Linux,從簡單處入手比較適合。
1. 去掉 ~/.bashrc 中的 force_color_prompt=yes 注釋,保存后並 source ~/.bashrc
之后如果終端顏色已經上色,這就達到目的了。
2. 終端執行 export TERM=xterm-256color 開啟256真彩色試試結果
如果有效,把這行代碼追加到 ~/.bashrc 或者 /etc/profile 文件的末行。
3. 試試下面的命令,其實就是開啟 force_color_prompt=yes
cp /etc/bash.bashrc /etc/bash.bashrc.bak cat << EOF >> /etc/bash.bashrc # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt 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;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi
EOF
4 . 如何定義顏色,這是一門特別的學問,建議 博客園 或者 知乎 咨詢
鄙人已經江郎才盡了,如果可以,請告訴我這些