如何从 Debian 的终端提示中删除路径?

Kel*_*lly 3 bashrc

从命令行,长目录路径可以占据整行:

长工作目录路径

也有人问过类似的问题:

  1. 在终端中隐藏目录路径
  2. 从终端删除“PWD”
  3. 从终端删除完整路径
  4. 在 bash 提示符下仅显示当前目录名称

采取的步骤:

  • 在 Debian 中找到 .bashrc 文件 /etc/bash.bashrc
  • 从终端中的 /etc 目录: sudo gedit bash.bashrc
  • 找到这一行: PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  • 将小写的 'w' 更改为大写的 'W'(粗体):

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

  • 保存(作为 sudo)并重新加载 .bashrc 文件可以暂时解决问题,但不能在新的终端窗口中解决。颜色也会改变(绿色和蓝色被淘汰,所有文本都变成白色)

Fre*_*ddy 5

您可能有自己的PS1定义~/.bashrc(除非您是根用户)覆盖系统范围/etc/bash.bashrc(没有颜色)。你应该PS1在那里编辑。

在我~/.bashrcPS1东西看起来像这样(默认的 Debian 伸展):

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
Run Code Online (Sandbox Code Playgroud)

第一个定义是带有颜色的定义。更改\w\W你的~/.bashrc,你应该是好的。