有的时候Linux控制台显示的目录颜色与背景颜色反差不大,看不清楚,可以使用LS_COLORS
来改变目录的颜色。
LS_COLORS=$LS_COLORS:'di=0;35:'
LS_COLORS
,顾名思义,设置的是 ls
显示的颜色。
di
表示是 directory
.
不同项的颜色设置用:
分隔,同一项的颜色设置用;
分隔。
比如上例中的di=0;35
:0
表示样式是默认的,35
表示颜色是紫色。
可选样式:
数字 | 样式 |
---|---|
0 | default color |
1 | bold |
4 | underlined |
5 | flashing text (disabled on some terminals) |
7 | reverse field (exchange foreground and background color) |
8 | concealed (invisible) |
可选颜色:
数字 | 颜色 |
---|---|
31 | Red |
32 | Green |
33 | Orange |
34 | Blue |
35 | Purple |
36 | Cyan(青色) |
37 | Grey |
90 | Dark grey |
91 | Light red |
92 | Light green |
93 | Yellow |
94 | Light blue |
95 | Light purple |
96 | Turquoise |
97 | White |
可选背景颜色:
数字 | 颜色 |
---|---|
40 | Black background |
41 | Red background |
42 | Green background |
43 | Orange background |
44 | Blue background |
45 | Purple background |
46 | Cyan background |
47 | Grey background |
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(蓝绿色背景) |
假如想要把目录颜色设为带下划线的浅红色,背景为蓝绿色,则设为:
export LS_COLORS=$LS_COLORS:"di=04;91;106:"
扩展
假如想设置除di
之外的其他颜色,请参考下表的关键字。
Key | /etc/DIR_COLORS name | Notes |
---|---|---|
no | NORMAL, NORM | Global default, although everything should be something |
fi | FILE | Normal file |
di | DIR | Directory |
ln | SYMLINK, LINK, LNK | Symbolic link. If you set this to ‘target’ instead of a numerical value, the colour is as for the file pointed to. |
pi | FIFO, PIPE | Named pipe |
do | DOOR | Door |
bd | BLOCK, BLK | device |
cd | CHAR, CHR | Character device |
or | ORPHAN | Symbolic link pointing to a non-existent file |
so | SOCK | Socket |
su | SETUID | File that is setuid (u+s) |
sg | SETGID | File that is setgid (g+s) |
tw | STICKY_OTHER_WRITABLE | Directory that is sticky and other-writable (+t,o+w) |
ow | OTHER_WRITABLE | Directory that is other-writable (o+w) and not sticky |
st | STICKY | Directory with the sticky bit set (+t) and not other-writable |
ex | EXEC | Executable file (i.e. has ‘x’ set in permissions) |
mi | MISSING | Non-existent file pointed to by a symbolic link (visible when you type ls -l) |
lc | LEFTCODE, LEFT | Opening terminal code |
rc | RIGHTCODE, RIGHT | Closing terminal code |
ec | ENDCODE, END | Non-filename text |
*.extension | Every file using this extension e.g. *.jpg |