linux 中ls命令文件夹颜色修改

bash中,ls后的颜色在黑色背景下有些不是很清楚,例如文件夹是蓝色的,在黑色背景下不好认。

设置一下自己的~/.dir_colors可以解决:

复制一份系统的到自己的目录:

cp /etc/DIR_COLORS ~/.dir_colors

修改 .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;47 # directory

DIR 01;31;44 # directory

表示文件夹字体为粗体蓝底红色。这样看起来好多了。

生效方式

1、eval `dircolors /etc/DIR_COLORS`

2、退出重启生效

自己的实践:

1.查看系统定义的变量: 使用命令 echo $LS_COLORS 其中的di=01;35为目录文件对应的颜色设置 01为高亮 35为显示的颜色. 请选中echo $LS_COLORS的输出结果按enter键,即可复制。

2.修改:

  a. vi ~/.bash_profile 即修改该文件,在文件中加入export LS_COLORS='...' 其中...为刚才复制的东西(粘贴复制的方式:将光标移到单引号之间按enter键即可将第一步中的复制粘贴进来),然后修改复制的字符串中的di=01;35(深蓝色)为di=01:32(绿色)

b. source ~/.bash_profile即可。

备注:

  参考资料 http://blog.sina.com.cn/s/blog_632254bc0100lq93.html