AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 811660
Accepted
BJsgoodlife
BJsgoodlife
Asked: 2016-08-13 17:11:05 +0800 CST2016-08-13 17:11:05 +0800 CST 2016-08-13 17:11:05 +0800 CST

当前目录仅显示在终端顶部,我如何在里面显示它?

  • 772

我不知道我做了什么,但不知何故我做到了,所以当我更改目录时,它会显示在终端的最顶部。这是我正在谈论的屏幕截图:

在此处输入图像描述

我很高兴它仍在工作,可能是某种设置问题。如何更改它,以便在更改目录时可以在终端内找到信息,而不是在顶部?

command-line
  • 1 1 个回答
  • 1660 Views

1 个回答

  • Voted
  1. Best Answer
    Zanna
    2016-08-14T07:32:23+08:002016-08-14T07:32:23+08:00

    我假设您希望当前工作目录显示在您的提示符中。

    根据您的屏幕截图,您的提示仅显示您的机器名称。您给出的输出echo $PS1甚至没有给我...我无法复制您的提示,而无需稍加修改:也许您有:\[\e]0;\u@\h: \w\a\]\H\$或者...您可能正在使用不同的外壳?

    这是一个非常简单的提示代码,它显示了用户名、计算机名和当前工作目录(在终端中输入以进行测试):

    PS1="\u@\h:\w$ "
    

    但可能您希望在提示符和窗口标题中使用工作目录...... Ubuntu 中的正常提示符是这样的:

    \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
    

    由以下方式设置~/.bashrc:

    # set a fancy prompt (non-color, unless we know we "want" color)
    case "$TERM" in
        xterm-color|*-256color) color_prompt=yes;;
    esac
    
    # uncomment for a colored prompt, if the terminal has the capability; turned
    # off by default to not distract the user: the focus in a terminal window
    # should be on the output of commands, not on the prompt
    #force_color_prompt=yes
    
    if [ -n "$force_color_prompt" ]; then
        if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
            # We have color support; assume it's compliant with Ecma-48
            # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
            # a case would tend to support setf rather than setaf.)
            color_prompt=yes
        else
            color_prompt=
        fi
    fi
    
    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
    

    所以也许你在你的里面放了一些东西.bashrc来覆盖它。看看它的末尾是否有类似的行

    export PS1="some code here"
    

    或者

    PS1="some code here"
    export PS1
    

    查看它是否已被覆盖,如果这些行存在则注释掉它们(放在#行的开头)或删除它们。

    .bashrc如果您只想恢复正常提示,您还可以检查我上面粘贴的部分(我的第 38-73 行)是否存在并且没有更改。

    得到一个完全干净的.bashrc

    mv ~/.bashrc{,.bak} && cp /etc/skel/.bashrc ~/.bashrc
    

    如果你想自定义你的提示,你可以继续玩,直到你得到你想要的……这个网站有助于参考。

    当你有你想要的东西添加到 .bashrc

    export PS1="your code here "
    

    另请参阅我最喜欢的 AU 问题之一

    • 3

相关问题

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve