Ubuntu修改命令行前用户名和主机名

技术 · 2020-06-18 · 541 人浏览

Ubuntu修改命令行前用户名和主机名

我的系统是Ubuntu18.04是在国际阿里云上的香港主机

强烈讲源换到国内!!!!
sudo nano /etc/apt/sources.list
清华源

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

使用 sudo apt update进行更新源


去除命令行前面的用户名和主机名

进入 ~/.bashrc sudo vim ~/.bashrc

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

找到\u\h 根据自己需要的进行修改


我用的是阿里云进去后命令行的用户名和主机名都是灰色看着不舒服,还在~/.bashrc修改

color_prompt=yes 
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

在前面添加color_prompt=yes 就好了。

Ubuntu 系统美化
  1. UrielGGs 2020-09-13

    这是一条评论哦~

    1. 一只胖橘 (作者)  2022-04-29
      @UrielGGs

      为啥给你的邮件通知总是失败

Theme Jasmine by Kent Liao