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,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
存储 安全 Shell
⭐⭐⭐【Shell 命令集合 磁盘管理 】Linux 显示当前工作目录的路径 pwd命令使用教程
⭐⭐⭐【Shell 命令集合 磁盘管理 】Linux 显示当前工作目录的路径 pwd命令使用教程
38 0
|
5月前
如何在cmd中打开指定文件夹路径
如何在cmd中打开指定文件夹路径
367 0
|
8月前
|
Linux
百度搜索:蓝易云 Linux系统-【文件管理】pwd命令 – 显示当前工作目录的路径
pwd命令来自于英文词组”print working directory“的缩写,其功能是用于显示当前工作目录的路径,即显示所在位置的绝对路径。
88 0
|
8月前
|
Linux
linux终端显示路径/绝对路径/相对路径
linux终端显示路径/绝对路径/相对路径
|
9月前
|
Linux
Linux系统-【文件管理】pwd命令 – 显示当前工作目录的路径
pwd命令来自于英文词组”print working directory“的缩写,其功能是用于显示当前工作目录的路径,即显示所在位置的绝对路径。 在实际工作中,我们经常会在不同目录之间进行切换,为了防止”迷路“,可以使用pwd命令快速查看当前所处的工作目录路径,方便开展后续工作。
186 0
|
9月前
|
Linux 测试技术 CDN
Linux系统 ls命令 – 显示指定工作目录下的文件及属性信息
ls是最常被使用到的Linux命令之一,它来自英语单词list的缩写,就像list单词的英语意思一样。它的功能是列出指定目录下的文件名称和特征。
77 0
|
Windows
windows 技术篇 - cmd命令查看当前目录下的所有文件和文件夹以及所有子目录下的文件,dir命令的使用方法
windows 技术篇 - cmd命令查看当前目录下的所有文件和文件夹以及所有子目录下的文件,dir命令的使用方法
2956 0
windows 技术篇 - cmd命令查看当前目录下的所有文件和文件夹以及所有子目录下的文件,dir命令的使用方法
|
Linux
linux输入命令直接跳转到指定目录
linux输入命令直接跳转到指定目录
485 0
linux输入命令直接跳转到指定目录
|
Windows
Win系统 - 文件夹或文件已在另一程序中打开怎么办?
Win系统 - 文件夹或文件已在另一程序中打开怎么办?
459 0
Win系统 - 文件夹或文件已在另一程序中打开怎么办?
|
Linux
3.8 Linux显示当前工作路径(pwd命令)
由于 Linux 文件系统中有许多目录,当用户执行一条 Linux 命令又没有指定该命令或参数所在的目录时,Linux 系统就会首先在当前目录(目前的工作目录)搜寻这个命令或它的参数。
327 0
3.8 Linux显示当前工作路径(pwd命令)