怎样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)}[ 33[01;32m]u@h[ 33[00m]:[ 33[01;34m]w[ 33[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: wa]$PS1"
      PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: Wa]$PS1"
     ;;
*)
    ;;
esac

保存,执行下面的命令或重启终端

$ source ~/.bashrc

执行上面步骤后,在终端页就短路径显示当前路径了

PS1:就是用户平时的提示符。

echo $PS1 可以查看PS1变量:

h :主机名字

u :当前用户的账号名称

w :完整的工作目录名称。家目录会以 ~代替

W :利用basename取得工作目录名称,所以只会列出最后一个目录