• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
wjshan0808

Learn from yesterday, Live for today, For a better tomorrow.
 ————wjshan0808

博客园    首页    新随笔    联系   管理    订阅  订阅

控制shell终端提示符格式和颜色

字体颜色值

(ASCII)

背景颜色值

(ASCII)

显示颜色
30 40 黑色
31 41 红色
32 42 绿色
33 43 黄色
34 44 蓝色
35 45 紫红色
36 46 青蓝色
37 47 白色
符 号值 特效 取反
0 OFF  
1 HighLight  
2 半亮 22
4 UndeLine 24
5 Blink 25
7 反白 27
8 不可见  

 

 

注:若着色不对,哈哈,请认为我是色盲吧。

特殊字符着色规则:

着色开始    着色结束

 \[\e[*m\]     \e[0m

若使用背景颜色或特效需要用;分割成*;*格式 ,"*"代表表中数值(其值见上两表);

如:(方式一 非永久性)

  


# .bashrc export PS1="你的设置" # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # User specific aliases and functions

特殊字符语法规则:

              \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 vari-
                     able)
              \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

这是我的 (方式二)

编辑.bashrc文件

$ vim ~/.bashrc

在该文件的
# User specific aliases and functions

下面添加如下内容

c1="\[\e[36m\]"
c2="\e[0m"
c3="\[\e[35m\]"
c4="\[\e[32m\]"
c5="\[\e[30m\]"
c6="\[\e[31m\]"
c7="\[\e[34m\]"
export PS1="$c1[$c2$c5\t$c2$c6@$c2$c3\u$c2 $c4\w$c2$c5]$c2$c7\$$c2 "

为什么选 \w 呢?因为 cd   很方便嘛......


posted @ 2013-09-15 21:06  wjshan0808  阅读(619)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3