怎樣ubuntu下命令行終端顯示短路徑

參考:http://blog.sina.com.cn/s/blog_b71132f001016cmm.html

ubuntu的終端命令行默認是長路徑,即把路徑深度全部顯示出來,操作起來不是很方便,下面介紹命令行顯示短路徑的操作:

$ vi ~/.bashrc

找到 PS1=   的行,將\w(小寫)改成\W(大寫)

if [ "$color_prompt" = yes ]; then

    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

else

##    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

      PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '
fi

unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir

case "$TERM" in

xterm*|rxvt*)

 ##   PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

      PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \W\a\]$PS1"
     ;;

*)

    ;;

esac

保存 , 執行下面的命令或重啓終端

$ source ~/.bashrc

執行上面步驟後 , 在終端頁就短路徑顯示當前路徑了

PS1 :就是用戶平時的提示符。

echo $PS1 可以查看 PS1 變量:

\h :主機名字

\u :當前用戶的賬號名稱

\w :完整的工作目錄名稱。家目錄會以 ~ 代替

\W :利用 basename 取得工作目錄名稱,所以只會列出最後一個目錄

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章