windows command(19):console颜色 color

color命令用来设置console的前景色或者背景色。

Usage

用法很简单,color [fb],其中f表示前景色,b表示背景色,取值范围为0-F,也就是十六进制数的一位。
color definition:
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White

Examples

foreground

background

same color

如果前景色与背景色设置为一样,如color 00,设置不会生效,结果是保持当前的前景色和背景色不变。
cmd_color_same_color_error.png

start new console

在改变console颜色之后,再通过start来创建一个新的console,新的控制台颜色还是保持
change_color_start_console.png

Advanced

修改注册表HKEY_CURRENT_USER\Software\Microsoft\Command Processor\DefaultColor的键值,可以修改通过cmd.exe或者start启动的窗口的颜色。

help COLOR
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Sets the default console foreground and background colors.
COLOR [attr]
attr Specifies color attribute of console output
Color attributes are specified by TWO hex digits -- the first
corresponds to the background; the second the foreground. Each digit
can be any of the following values:
0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White
If no argument is given, this command restores the color to what it was
when CMD.EXE started. This value either comes from the current console
window, the /T command line switch or from the DefaultColor registry
value.
The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute
the COLOR command with a foreground and background color that are the
same.
Example: "COLOR fc" produces light red on bright white