dircolors

用途

设置 ls 指令在显示目录或文件时所用的色彩。

语法

dircolors [色彩配置文件] 或 dircolors [-bcp][--help][--version]

描述

dircolors可根据[色彩配置文件]来设置LS_COLORS环境变量或是显示设置LS_COLORS环境变量的shell指令。ls指令会根据LS_COLORS的变量值,在显示文件与目录时,以色彩来区别不同类型的文件与目录。一般的使用方法是在 .bash_profile中加入 dircolors指令,以便开机时即设好LS_COLORS变量。

参数

-b或--sh或--bourne-shell  显示在Boume shell中,将LS_COLORS设为目前预设置的shell指令。
-c或--csh或--c-shell  显示在C shell中,将LS_COLORS设为目前预设置的shell指令。
-p或--print-database  显示预设置
-help  显示帮助。
-versio  显示版本信息。

例子

将预设值存为 .colorrc 色彩配置文件,修改后再从 .bash_profile 执行:

$ dircolors -p > .colorrc
$ cat .colorrc
…… 查找这里,这里的注解文字说明如何设置色彩
# 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. (If you set this to 'target' instead of a
 # numerical value, the color is as for the file pointed to.)
FIFO 40;33 # pipe
SOCK 01;35 # socket
DOOR 01;35 # door
BLK 40;33;01 # block device driver
CHR 40;33;01 # character device driver
ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file
“40”代表背景为黑色,“31”代表红色字体,“01”代表粗体字
……

请根据自己喜欢的方式来更改 .colorrc文件。改好好,请在 .bash_profile 加入下列叙述:

eval `dircolors ./.colorrc` <--注意这里的符号不是引号,而是键盘左上角数字1左边的按键

重新登入后,或者使用 source 命令,色彩设置便会生效。

显示在 Bourne shell 中,将 LS_COLORS 设为目前预设值的 shell 指令:

$ dircolors -b

运行命令后,出现好多行的文字其实只执行了两个叙述:“LS_COLORS=[变量值]”与“export LS_COLORS”。第一个叙述设置 LS_COLORS的变量值,第二个叙述则将 LS_COLORS 输出为环境变量。 dircolors -b 的输出结果可作为 script 文件,执行后即可变更 LS_COLORS 环境变量。

$ dircolors -b >setcolor
$ sed -e s/"di=01;34"/di=05:34"/1 setcolor > newcolor
你也可以用任何一种文本编辑器来修改setcolor中的设置。将目录的字型属性改为05(闪烁)
$ source newcolor  <-- 让变量立即生效。
$ ls    <-- 执行 ls 时,即可看见目录会一闪一闪。

相关命令

shells/commands/dircolors.txt · 最后更改: 2010/03/30 13:01 (外部编辑)
[unknown link type]到顶部
GNU Free Documentation License 1.3
京ICP备05034962号 Debian Driven by DokuWiki get firefox browser Recent changes RSS feed Valid XHTML 1.0