Linux中的颜色方案

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-02 05:26 点击:

在linux下可以自定义自己的颜色方案,不管是linux命令提示符的颜色,还是stdout的输出颜色。
在 /etc/DIR_COLORS 下可以找到如下说明:
 
Shell代码 
[root@CentOS ~] 
#cat /etc/DIR_COLORS  
 
# Below are the color init strings for the basic file types. A color init 
# string consists of one or more of the following numeric codes: 
# Attribute codes:  
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed 
# Text color codes: 
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white 
# Background color codes: 
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white 
NORMAL 00       # global default, although everything should be something. 
FILE 00         # normal file 
DIR 01;34       # directory 
LINK 01;36      # symbolic link 
FIFO 40;33      # pipe 
SOCK 01;35      # socket 
BLK 40;33;01    # block device driver 
CHR 40;33;01    # character device driver 
ORPHAN 01;05;37;41  # orphaned syminks 
MISSING 01;05;37;41 # ... and the files they point to 
 
 
--最重要的部分在这里:
 
Txt代码 
# Attribute codes:  
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed 
# Text color codes: 
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white 
# Background color codes: 
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white 
 
 
下面 举两个例子:
 
1、让输出的字符带上颜色
定义一个脚本:
 
Shell代码 
#!/bin/bash 
# 先定义一些颜色: 
red='\e[0;31m'          # 红色 
RED='\e[1;31m'          # 红色+粗体(后面以此类推) 
green='\e[0;32m'        # 绿色 
GREEN='\e[1;32m' 
yellow='\e[0;33m'       # 黄色 
YELLOW='\e[1;33m' 
blue='\e[0;34m'         # 蓝色 
BLUE='\e[1;34m' 
purple='\e[0;35m'       # 紫色 
PURPLE='\e[1;35m' 
cyan='\e[0;36m'         # 蓝绿色 
CYAN='\e[1;36m' 
WHITE='\e[1;37m'        # 白色 
NC='\e[0m' # 没有颜色 
 
echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n" 
echo -e "${RED}RED ${BLUE}BLUE ${cyan}cyan ${GREEN}GREEN${NC}" 
echo -e "${CYAN}white ${WHITE}blod white ${NC} no color!!" 
echo "${CYAN}white ${WHITE}blod white ${NC} no color!!"    #注意这句 
 
运行结果如下:


 
注:这里要加上 -e 参数才能正确输出颜色。
( -e 的解释:-e     enable interpretation of backslash escapes | 大致意思是允许解释反斜杠)


2、修改命令提示符(也就是:[root@CentOS ~]# )
我们可以给 [root@CentOS ~]#  加上颜色和自定义格式:

修改 /etc/bashrc 来达成我们的目的:
vi /ete/bashrc,跟上面一样,大概修改成下面的样子(颜

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • /etc/fstab 详解
      • nginx主主集群
      •  LVS-NAT和LVS-DR模式的实现详解
      •  RHCE考试之磁盘配额
      • 学习笔记:ACL详解
      • suse linux双网卡双网关配置
      •  LVM逻辑卷管理器
      •  Nginx主主负载均衡架构
      • ubuntu学习Mysql

      快速直达

      操作系统导航

      LinuxWindows虚拟机
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1