DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

定制bash命令提示符


使用shell时经常要知道当前路径,如果将它写在提示符里很节省很多敲pwd的动作,方法是在启动文件(.bash_profile, .bashrc)里加上:

export PS1="[\u@\h \w]\$ "

效果如下:

[godu@NOP2-HWXX /opt/godu/terracotta-2.7.2]$ pwd /opt/godu/terracotta-2.7.2

如果想持久化此效果,在~/.bash_profile文件(如果没有新建之)里追加上面的export语句。

说明:

PS1是bash里表示命令提示符的环境变量,\u表示用户名,\h表示host name,\w表示完整路径名,\W表示当前路径名,\$表示提示符(更多选项google"bash prompt ps1")。以上在Solaris 10和CentOS 6中验证。



Published

Oct 12, 2011

Last Updated

Oct 12, 2011

Category

Tech

Tags

  • bash 5
  • prompt 2
  • Solaris 4
  • 提示符 1

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor