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. I know this website offers quality depending articles and other stuff, is there any other web page which presents such information in quality?

  2. Hey terrific blog! Does running a blog like this take a great deal of work? I've virtually no understanding of programming but I had been hoping to start my own blog soon. Anyways, if you have any ideas or techniques for new blog owners please share. I understand this is off subject nevertheless I simply wanted to ask. Kudos!

  3. Excellent post. I used to be checking continuously this blog and I'm impressed! Very useful information specially the closing section : ) I take care of such info much. I used to be seeking this certain information for a long time. Thanks and good luck.

  4. If you are going for most excellent contents like I do, only visit this web page every day since it presents feature contents, thanks

  5. After looking over a number of the blog posts on your web page, I seriously appreciate your way of writing a blog. I saved as a favorite it to my bookmark website list and will be checking back in the near future. Take a look at my web site as well and let me know what you think.

  6. You should be a part of a contest for one of the highest quality blogs online. I will highly recommend this blog!