linux系统下修改终端的文件目录显示颜色

Thefollowingsare something aboutLS_COLORS:

Here is an easy way to setdifferent colours for different kinds of files when using thelscommand.

Add the following lines tothe bottom of your~/.bashrc file -

alias ls='ls --color'
LS_COLORS='di=1:fi=0:ln=31:pi=5:so=5:bd=5:cd=5:or=31:mi=0:ex=35:*.rpm=90'
exportLS_COLORS

The first line makes lsuse the --colorparameter by default, which tells ls to display files in differentcolours based on the setting of theLS_COLORSvariable.

The second line is thetricky one, and what I have worked out so far has been by trial anderror. The parameters (di, fi, etc.) refer to different Linux filetypes. I have worked them out as shown

di = directory
fi = file
ln = symbolic link
pi = fifo file
so = socket file
bd = block (buffered)special file
cd = character(unbuffered) special file
or = symbolic linkpointing to a non-existent file (orphan)
mi = non-existent filepointed to by a symbolic link (visible when you type ls -l)
ex = file which isexecutable (ie. has 'x' set in permissions).

The *.rpm=90 parameter at the end tellsls to display any files ending in .rpm in the specified colour, inthis case colour 90 (dark grey). This can be applied to any typesof files (eg. you could use '*.png=35' to make jpeg files appearpurple.) As many or as few parameters as you like can go into theLS_COLORS variable, aslong as the parameters are separated by colons.

Using trial and error (anda little bash script I wrote... my first one ever! :) I worked outall the colour codes, at least my interpretation of them-

0 = default colour
1 = bold
4 = underlined
5 = flashing text
7 = reverse field
31 = red
32 = green
33 = orange
34 = blue
35 = purple
36 = cyan
37 = grey
40 = black background
41 = red background
42 = green background
43 = orange background
44 = blue background
45 = purple background
46 = cyan background
47 = grey background
90 = dark grey
91 = light red
92 = light green
93 = yellow
94 = light blue
95 = light purple
96 = turquoise
100 = dark grey background
101 = light red background
102 = light green background
103 = yellow background
104 = light blue background
105 = light purple background
106 = turquoise background

These can even becombined, so that a parameter like:
di=5;31;42
in your LS_COLORSvariable would make directories appear in flashing red text with agreen background!

Setting LS_COLORS does more than just makeyour ls listings look pretty (although it certainly does do that),it is also very helpful in identifying files while wading through afile system.

If anyone finds outadditional info on LS_COLORS, or spots an error, pleasee-mail me, I would like to know. Any questions may also be directedto me by e-mail.


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值