介紹
從 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:~]#
* 命令提示符還可以修改別的配置,譬如顏色顯示等等