TTY终端颜色缺失

文章讲述了在UbuntuMATE24.04中,使用Ctrl+Alt+F1-6打开TTY终端时缺少彩色显示,原因是升级后.user目录下的.profile文件丢失。解决方法是复制一份默认的.profile文件并确保.loginshells启动时执行.bashrc。

Ubuntu MATE 24.04使用ctrl + alt + F<1-6>打开TTY终端时,发现终端没有彩色显示。

但是在用户目录下执行source .bashrc则恢复彩色。

问题的原因是升级的时候用户目录的.profile没有恢复(被手动删除的),复制一份.profile文件到用户目录即可。

~/.profile文件内容如下:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

参考:

login - .bashrc not executed when opening new terminal - Ask Ubuntu

# ———————————————————————————————— # 🎯 日志系统:结构化输出 # ———————————————————————————————— # ------------------------------- # 🎨 ANSI 颜色常量 # ------------------------------- RESET='\033[0m' RED='\033[31m' GREEN='\033[32m' YELLOW='\033[33m' BLUE='\033[36m' WHITE='\033[37m' LOG_FILE="/var/log/dj_deploy.log" # ------------------------------- # 📝 日志函数:log LEVEL "message" # 输出到终端(彩色)和日志文件(无色) # ------------------------------- log() { local level="$1"; shift local msg="$*" local timestamp=$(date '+%H:%M:%S') local color_start="" local log_level="" # 设置颜色 case "$level" in SUCCESS) color_start="$GREEN" log_level="SUCCESS" ;; ERROR|FAIL*) color_start="$RED" log_level="ERROR" ;; WARN) color_start="$YELLOW" log_level="WARN" ;; INFO|TIME|DEBUG) color_start="$BLUE" log_level="INFO" ;; *) color_start="$RESET" log_level="INFO" ;; esac # ✅ 终端输出:使用 printf 并确保以 RESET 结尾 printf "\r[%s] %b%s%b\n" \ "$timestamp" \ "$color_start" \ "$msg" \ "$RESET" > /dev/tty # ✅ 日志文件记录(无颜色) printf "[%s] %s %s\n" \ "$(date '+%Y-%m-%d %H:%M:%S')" \ "$log_level" \ "$msg" >> "$LOG_FILE" } log() { local level="$1"; shift local msg="$*" local timestamp=$(date '+%H:%M:%S') local color_start="" local log_only_level="$level" # 设置颜色前缀 case "$level" in SUCCESS) color_start="\033[32m" # 绿色 ;; ERROR|FAIL*) color_start="\033[31m" # 红色 ;; WARN) color_start="\033[33m" # 黄色 ;; INFO) color_start="\033[36m" # 青色 ;; TIME|DEBUG) color_start="\033[37m" # 白色 ;; *) color_start="${RESET}" # 默认无色 ;; esac # ✅ 终端输出:必须以 RESET 结尾 printf "\r[%s] %b%s%b\n" \ "$timestamp" \ "$color_start" \ "$msg" \ "$RESET" > /dev/tty # 日志文件:颜色 case "$level" in SUCCESS) log_only_level="SUCCESS" ;; ERROR|FAIL*) log_only_level="ERROR" ;; WARN) log_only_level="WARN" ;; *) ;; esac printf "[%s] %s %s\n" \ "$(date '+%Y-%m-%d %H:%M:%S')" \ "$log_only_level" \ "$msg" >> "$LOG_FILE" } log_raw() { local msg="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') local line="[$timestamp] $msg" # 清洗 + 安全写入 UTF-8 日志 echo "$line" | \ LC_ALL=C tr -cd '[:print:]\t\n\r' | \ sed 's/\r\n\|\r\|\n/\\n/g' | \ xargs printf '%s\n' 2>/dev/null | \ tee -a "$LOG_FILE" > /dev/null }
最新发布
01-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值