从终端删除完整路径


22

是否可以在终端行中仅显示当前目录,而不显示主文件夹的整个路径?

我现在有这个:ilya@ubuntu:~/Dropbox/Web/folder/folder/$它几乎占据了所有屏幕...

Answers:


32

外壳中$之前的部分称为提示。可以通过更改变量进行配置$PS1。还有一个类似的问题,答案很好

手册页(请参见“ Bash”以及此处的“ PROMPTING”)显示:

      \w     the  current working directory, with $HOME
             abbreviated with a tilde (uses the value of the
             PROMPT_DIRTRIM variable)
      \W     the basename of the current working directory,
             with $HOME abbreviated with a tilde

因此,您必须更改\w\W。$ PS1的初始值可能存储在您的中.bashrc,这意味着您必须编辑文件,~/.bashrc并且会发现类似于以下内容的行:

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

在这两行中都更改\w\W,然后打开一个新的终端(或运行source ~/.bashrc)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.