萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Linux 終端顯示 -bash-2.05b$ 失去彩色提示符?補齊 .bashrc/.bash_profile/bashrc 修復

首次登入顯示正常提示符,再次開機變為 -bash-2.05b$ 且失去彩色。原因是家目錄缺少 .bashrc、.bash_profile 或系統 /etc/bashrc。重新建立三個檔案並填入標準內容即可恢復。

現象

  • 首次:hostname (user) ~ $ (彩色)
  • 再次:-bash-2.05b$ (無色)

修復步驟

  1. 確認並建立 /root/.bashrc:
    # .bashrc
    # User specific aliases and functions
    # Source global definitions
    if [ -f /etc/bashrc ]; then
        . /etc/bashrc
    fi
  2. 確認並建立 /root/.bash_profile:
    # .bash_profile
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
        . ~/.bashrc
    fi
    # User specific environment and startup programs
    export BASH_ENV=$HOME/.bashrc
  3. 確認並建立 /etc/bashrc:
    # /etc/bashrc
    # System wide functions and aliases
    # Environment stuff goes in /etc/profile
    PS1='[\033[0;34m]\h ([\033[0;31m]\u[\033[0;34m]) [\033[0;32m]\w $ [\033[0m]'
    VIM="/usr/share/vim"
    alias ls='ls --color=tty -F -b -T 0'
  4. 重新開啟終端機即可看到彩色提示符恢復正常。

相關檔案

亦可檢查 /etc/hosts、/etc/passwd 完整性,但 90% 以上案例為上述三檔遺失或損壞。

小結

補齊 .bashrc、.bash_profile、/etc/bashrc 三個初始化檔案,重新載入 Shell 即可恢復友善彩色提示符與別名功能。

copyright © 萬盛學電腦網 all rights reserved