文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. 问题描述

最近在服务器上重新安装了一点东西,结果登录的shell界面变成了显示-bash-4.2$,显得很丑而且使用起来十分不方便,主要是scp时需要用户名和主机名,因此对其进行了修改。

2. 解决方案

修改当前用户的.bash_profile文件,在其中加入:

export PS1='[\u@\h \W]$ '

source .bash_profile,OK,问题解决。

3. 解释

PS1是Linux终端用户的一个环境变量,用来说明命令行提示符的设置。\u等是特殊字符,可以通过man bash命令查看,其意义如下:

\a     an ASCII bell character (07)
\d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format}the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation.  The braces are required
\e     an ASCII escape character (033)
\h     the hostname up to the first `.'
\H     the hostname
\j     the number of jobs currently managed by the shell
\l     the basename of the shell's terminal device name
\n     newline
\r     carriage return
\s     the name of the shell, the basename of $0 (the portion following the final slash)
\t     the current time in 24-hour HH:MM:SS format
\T     the current time in 12-hour HH:MM:SS format
\@     the current time in 12-hour am/pm format
\A     the current time in 24-hour HH:MM format
\u     the username of the current user
\v     the version of bash (e.g., 2.00)
\V     the release of bash, version + patch level (e.g., 2.00.0)
\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
\!     the history number of this command
\#     the command number of this command
\$     if the effective UID is 0, a #, otherwise a $
\nnn   the character corresponding to the octal number nnn
\\     a backslash
\[     begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\]     end a sequence of non-printing characters

部分特殊字符解释如下:

\u 当前用户的用户名
\h 用.分开的第一个主机名
\H 完整的主机名
\W 当前工作目录的目录名,只显示路径的最后一个目录
\w 当前工作目录的目录名,显示全路径

Linux下shell显示用户名和主机名相关推荐

  1. Linux更改终端的用户名和主机名的颜色

    1.分别以root用户或其他用户登陆,在终端输入: 输入:vim  ~/.bashrc #定位到如下代码:if [ "$color_prompt" = yes ]; thenPS1 ...

  2. linux 不显示路径原因,linux 下shell 显示-bash-4.1不显示路径解决办法

    1.原因分析: 没有.bash_profile这个文件,可以通过配置此文件恢复路径显示. 2.配置步骤: (1).vim ~/.bash_profile 在此加入如下命令: export PS1='[ ...

  3. linux下shell显示-bash-4.1#不显示路径解决方法

    在linux shell中不显示路径 显示为-bash-4.1#用起来很不方便. 如何改为显示路径的shell呢? 步骤如下: vim ~/.bash_profile (不用管.bash_profil ...

  4. linux下shell显示-bash-4.1$ 不显示路径解决方法

    在linux shell中不显示路径了,用起来很不方便. 如何改为显示路径的shell呢 步骤如下: vi ~/.bash_profile (不用管.bash_profile这个文件有几个,自己新建一 ...

  5. 设置不显示用户名和主机名_谁说Excel中不可以有聚光灯效果:Excel高亮显示设置...

    点击上方蓝字关注我 前天,在群里有位伙伴提到Excel高亮显示用公式如何设置的问题,在解答完后,想想还是有必要写次关于高亮显示设置的专题教程,供更多的伙伴了解和学习.对于高亮显示设置这个问题,使用WP ...

  6. oh-my-zsh提示符显示当前用户名和主机名

    1.编辑$ZSH/themes/agnoster.zsh-theme sudo nano $ZSH/themes/agnoster.zsh-theme prompt_context{}部分默认在非de ...

  7. Linux Ubuntu终端“@”前后的含义及修改(修改用户名及主机名)【试用办法,部分不可行】

    Linux & Ubuntu终端"@"前后的含义及修改(修改用户名及主机名)[试用办法,部分不可行] "@" 前为用户名(当前用户),修改方法: htt ...

  8. linux shell 原理,linux下shell的工作原理

    linux下shell的工作原理 2009-12-8 10:19:53   出处:https://www.yqdown.com shell是用户和Linux操作系统之间的接口.Linux中有多种she ...

  9. Linux下shell脚本/Makefile编写

    Linux下shell脚本/Makefile编写 一.基本概念 代码变成可执行文件,叫做编译(compile):先编译这个,还是先编译那个(即编译的安排),叫做构建(build). make只是一个指 ...

最新文章

  1. 请求合并的三种方式,大大提高接口性能!
  2. 单片机生成随机数的方法总结
  3. Basic Windbg - 1. SOSBasics(再续)
  4. XamarinAndroid组件教程设置动画的时长参数
  5. 18c分布式事务 oracle_分布式事务的现象及理解
  6. HDU1232 畅通工程
  7. 面试题——面经题目(1)
  8. Java中的mapreduce没了_MapReduce的过程总结
  9. springboot整合rabbitMQ-路由模型
  10. Iframe和Frame中实现cookie跨域的方法(转载)
  11. python 装饰器(复杂一点的)
  12. 《JAVA设计模式》之中介者模式(Mediator)
  13. 牛客网 牛客小白月赛1 A.简单题-控制输出格式setiosflags()函数+setprecision()函数
  14. Epub与Kindle
  15. 情怀java手机网游_Java开发游戏马里奥,就要码出我们这一代人的情怀
  16. Windows server 2012 R2 服务器强制删除文件夹
  17. javaweb 温习
  18. python 调试,Python 学习入门--pydev调试
  19. 如何安装和使用vicuna
  20. 定时备份脚本分享(网站数据和数据库数据)

热门文章

  1. 素饺子馅的做法大全 素饺子馅如何做
  2. 分享卖货小程序制作方法_怎么在微信上做小程序卖货
  3. PlatON和IRISnet结成战略合作伙伴,共同开拓区块链企业服务市场
  4. dns服务器未影响无法上网,dns服务器未响应导致无法上网怎么办
  5. BP神经网络的数学表达式
  6. CString 用法大全
  7. 怎样用C++在控制台中编写俄罗斯方块
  8. php时间期间检测重叠,如何检查PHP中多个日期范围之间的重叠?
  9. TCP 的演化史-sack 与 reordering metric
  10. X书x-mini-sig_x-mini-mua