ubantu终端下只显示当前路径,而不显示绝对路径




Ubuntu下,默认情况下,对于终端,是显示出绝对的路径的,比如:

terminal show full path

现在想要让其只显示相对路径。

 

【解决过程】

参考:

Linux中,去掉终端显示的当前目录的绝对路径


1。先输入命令:

1
sudo vim ~/.bashrc

找到.bashrc中的,有关PS1的部分,从:

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\$ ‘
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″
    ;;
*)
    ;;
esac

 

改为:

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\$ ‘
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″
    ;;
*)
    ;;
esac


2.保存修改,退出vim。然后再source一下,发现终端的标题变成当前路径了:

after source title become short

PS:注意终端的顶端路径已经改变了。

3.再重启终端,看看是否生效。

4.再去把上面那个PS1中的值,变成:

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\$ ‘
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″
    ;;
*)
    ;;
esac

然后保存退出vim,再source一下:



效果如下:

now prompt also show short path

 

【总结】

想要将Ubuntu的终端,中的绝对路径的显示,变成当前路径(文件夹)的话,则需要去修改自己的.bashrc,将其中的小写的w,改为大写的W即可:

(1)针对终端的标题title

从:


1
2
3
4
5
6
7
8
# 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"
     ;;
*)
     ;;
esac

改为:


1
2
3
4
5
6
7
8
# 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"
     ;;
*)
     ;;
esac

 

(2)针对终端的当前显示prompt

从:

?

1
2
3
4
5
6
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\$ '
fi
unset  color_prompt force_color_prompt

改为:

?

1
2
3
4
5
6
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\$ '
fi
unset  color_prompt force_color_prompt










本文转自 ye小灰灰  51CTO博客,原文链接:http://blog.51cto.com/10704527/1795148,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值