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:~]# 

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

Responses
  1. I am curious to find out what blog system you have been utilizing? I'm experiencing some small security issues with my latest website and I would like to find something more safeguarded. Do you have any recommendations? 0mniartist asmr

    Reply
  2. I do believe all the concepts you've presented on your post. They're really convincing and will definitely work. Nonetheless, the posts are very quick for newbies. May you please prolong them a little from next time? Thank you for the post. asmr 0mniartist

    Reply
  3. It is perfect time to make some plans for the future and it's time to be happy. I have read this post and if I could I wish to suggest you some interesting things or advice. Maybe you can write next articles referring to this article. I want to read even more things about it! 0mniartist asmr

    Reply
  4. Why viewers still make use of to read news papers when in this technological world all is accessible on web? asmr 0mniartist

    Reply
  5. Hello There. I found your blog using msn. This is a really well written article. I will be sure to bookmark it and return to read more of your useful information. Thanks for the post. I will certainly return. asmr 0mniartist

    Reply
  6. Dix

    A pay or name web is what youd visualize -- its own the webpage of one's article or newspaper, which includes info regarding . http://iconic.phaseinspire.co.uk/how-do-you-do-comparison-in-english/ https://www.mitalex.de/10949/ http://vanchuyenducviet.de/2021/03/27/how-do-you-write-an-imaginative-essay/

    Reply