定制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中验证。

posted on 2014-03-18 08:15  leechau  阅读(224)  评论(0编辑  收藏  举报

导航