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一般为:

  /u 当前登录用户名
  /h 当前计算机名称(譬如ubuntu)
  /H 当前计算机的域名全程,譬如(ubuntu.ubuntu.com)
  /w 当前目录的完整路径。家目录会以~代替
  /W 利用basename取得工作目录名称,所以只会列出最后一个目录
  /$ 一般用户为$,root用户为>
  /t 当前时间(24小时制,HH:MM:SS 分别代表 小时:分钟:秒)
  /T 当前时间(12小时制)
  /@ 当前时间(AM/PM显示)
  /d 当前日期
  /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]\$


root@Ubuntu:~# source .bashrc 



[root@Ubuntu:~]# reboot

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

  1. Do you mind if I quote a few of your articles as long as I provide credit and sources back to your weblog? My blog site is in the very same area of interest as yours and my visitors would genuinely benefit from a lot of the information you present here. Please let me know if this ok with you. Thanks a lot!

  2. Thanks to my father who told me regarding this blog, this weblog is actually amazing.

  3. [url=https://extrasildenafil.com/]viagra tablets australia[/url]

  4. Very shortly this site will be famous amid all blog visitors, due to it's good posts

  5. I blog frequently and I genuinely thank you for your content. This great article has really peaked my interest. I'm going to take a note of your blog and keep checking for new details about once a week. I opted in for your RSS feed too.

  6. [url=https://cialis.onl/]cheapest cialis usa[/url]