ls指令显示的文件,可以通过设置环境变量LS_COLORS,修改不同类型文件显示的颜色。LS_COLORS可以通过指定文件设定,如:
shell terminal$dircolors -b .mydircolor
若未指定,则读取默认的值,可以通过如下指令查看。
shell terminal$dircolors -p 更多信息请通过 man dircolors(1)查看。
自己定制ls输出的文件颜色时,可以通过多个方法定制:
在.bashrc、/etc/profile等初始化的文件中定义LS_COLORS:(e.g.)
LS_COLORS="ow=01;90:di=01;90"
export LS_COLORS 2.
获取默认值写入一文件(.mydircolor)
shell terminal$dircolors -p > ~/.mydircolor
按照自己喜好修改文件~/.mydircolor
在.bashrc等初始化文件中加入语句:
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)"
LS_COLORS值是key-value的字符串,key可取的值见下表:
| 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 color is as for the file pointed to. |
| pi | FIFO, PIPE | Named pipe |
| do | DOOR | Door |
| bd | BLOCK, BLK | Block 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 |
每个key对应的value,确定该类文件的颜色,value可以由多个值以“;"分割开(字体颜色、背景颜色),各个key之间以":"分割开。value的可取值如下表:
| Effects | |
| 00 | Default colour |
| 01 | Bold |
| 04 | Underlined |
| 05 | Flashing text |
| 07 | Reversetd |
| 08 | Concealed |
| Colours | |
| 31 | Red |
| 32 | Green |
| 33 | Orange |
| 34 | Blue |
| 35 | Purple |
| 36 | Cyan |
| 37 | Grey |
| Backgrounds | |
| 40 | Black background |
| 41 | Red background |
| 42 | Green background |
| 43 | Orange background |
| 44 | Blue background |
| 45 | Purple background |
| 46 | Cyan background |
| 47 | Grey background |
| Extra colours | |
| 90 | Dark grey |
| 91 | Light red |
| 92 | Light green |
| 93 | Yellow |
| 94 | Light blue |
| 95 | Light purple |
| 96 | Turquoise |
| 97 | White |
| 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 |
更多信息,参考:
http://www.bigsoft.co.uk/blog/index.php/2008/04/11/configuring-ls_colors
本文介绍如何通过设置环境变量LS_COLORS来自定义ls命令显示的不同类型文件的颜色。包括定义LS_COLORS的方法、预设颜色配置的获取及修改步骤。
958

被折叠的 条评论
为什么被折叠?



