Linux shell prompt, colors and cursor position

Shell command prompt and colors are configured by PS1:

 

1. The commonly used parameters of PS1 have the following meanings:

\d :#代表日期,格式为weekday month date,例如:"Mon Aug 1"
\H :#完整的主机名称
\h :#仅取主机的第一个名字
\t :#显示时间为24小时格式,如:HH:MM:SS
\T :#显示时间为12小时格式
\A :#显示时间为24小时格式:HH:MM
\u :#当前用户的账号名称
\v :#BASH的版本信息
\w :#完整的工作目录名称
\W :#利用basename取得工作目录名称,所以只会列出最后一个目录
\# :#下达的第几个命令
\$ :#提示字符,如果是root时,提示符为:# ,普通用户则为:$

 

2. Color value setting: The format for setting character color in PS1 is: \[\e[F;Bm\], where "F" is the font color, numbered 30-37, and "B" is the background color, numbered 40 -47. The color table is as follows:

F       B
30      40      黑色
31      41      红色
32      42      绿色
33      43      黄色
34      44      蓝色
35      45      紫红色
36      46      青蓝色
37      47      白色

 

3. Terminal color and cursor position control

\033[0m 关闭所有属性 
\033[1m 设置高亮度 
\033[4m 下划线 
\033[5m 闪烁 
\033[7m 反显 
\033[8m 消隐 
\033[30m -- \033[37m 设置前景色 
\033[40m -- \033[47m 设置背景色 
\033[nA 光标上移n行 
\033[nB 光标下移n行 
\033[nC 光标右移n行 
\033[nD 光标左移n行 
\033[y;xH 设置光标位置 
\033[2J 清屏 
\033[K 清除从光标到行尾的内容 
\033[s 保存光标位置 
\033[u 恢复光标位置 
\033[?25l 隐藏光标 
\033[?25h 显示光标

 

4. My bash PS settings

PS1='\[\e[33;1;1m\][\u@\h:\w] \[\e[m\]'
PS2='\[\e[33;1;1m\]>> \[\e[m\]'

 

Original address: http://blog.csdn.net/colben/article/details/42044015

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325258877&siteId=291194637