Ubuntu 修改 PS1 美化命令提示符

介绍

从 centos 换到 Ubuntu 后看着命令提示符很不舒服,想要改成 centos 的格式。

查看相关帮助信息

root@Ubuntu:~# man bash

我们可以看到以下说明,表示配置文件在 ~/.bashrc

       Bash attempts to determine when it is being run with its standard  input  connected  to  a network  connection,  as  when  executed  by the remote shell daemon, usually rshd, or the secure shell daemon sshd.  If bash determines it is being run in this  fashion,  it  reads and executes commands from ~/.bashrc and ~/.bashrc, if these files exist and are readable.
       It will not do this if invoked as sh.  The --norc option  may  be  used  to  inhibit  this behavior,  and  the --rcfile option may be used to force another file to be read, but neither rshd nor sshd generally invoke the shell with those options or allow them to be specified.

修改 PS1

PS(Prompt Sign): 是指命令提示符,要想修改这个命令提示符。修改 ~/.bashrc 文件中的 PS1 即可。PS1是主要的提示符设置,在ubuntu一般为:
${debian_chroot:+($debian_chroot)}\u@\h:\w\$

具体的提示符,按分类含义如下:
  主要信息:
  /u 当前登录用户名
  /h 当前计算机名称(譬如ubuntu)
  /H 当前计算机的域名全程,譬如(ubuntu.ubuntu.com)
  /w 当前目录的完整路径。家目录会以~代替
  /W 利用basename取得工作目录名称,所以只会列出最后一个目录
  /,root用户为>
  时间显示
  /t 当前时间(24小时制,HH:MM:SS 分别代表 小时:分钟:秒)
  /T 当前时间(12小时制)
  /@ 当前时间(AM/PM显示)
  /d 当前日期
  Shell信息:
  /v Bash版本
  /V Bash的发布版本号
  /S Shell名称
  /! Bash命令的历史编号
  /j job序号
  /l Shell的终端名称

vim ~/.bashrc

root@Ubuntu:~# vim ~/.bashrc 

PS1 修改为 [${debian_chroot:+($debian_chroot)}\u@\h:\W]\$

重新加载bash配置文件

root@Ubuntu:~# source .bashrc 
[root@Ubuntu:~]# 
[root@Ubuntu:~]# 

验证

重启后验证命令提示符不会变

[root@Ubuntu:~]# reboot
...
[root@Ubuntu:~]# 

* 命令提示符还可以修改别的配置,譬如颜色显示等等

你可能感兴趣的:(Ubuntu 修改 PS1 美化命令提示符)