如何使终端中的用户名更小?


16

当您打开终端时,它将显示用户名和机器名称。如我的示例所示:romeo@romeo-Satellite-C660D:~$。这真的很烦,因为它很大。我可以将其缩小,例如只显示罗密欧吗?

我知道这听起来很愚蠢,但是我是基于Unix操作系统的新手。

Answers:


21

您需要PS1在您的环境中更改变量。PS1负责您的命令提示符的外观和其包含的信息。

永久变更

以下是.bashrcUbuntu 10.04 LTS 中默认文件的摘录:

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

这使命令提示符看起来像这样: username@hostname:~/directory$

如果更改此设置并删除的@\h一部分PS1,则将在命令提示符中删除主机名部分:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u:\w\$ '
fi

结果: username:~/directory$

临时变更

覆盖PS1当前bash会话:

export PS1="\u:\w\$ "

资源:



-3
export PS1='\t$'

因为我喜欢显示尽可能少的背景信息的终端,我一般定制每个会话的#$等等。


这如何回答这个问题?
TheWanderer 2015年
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.