← 返回命令列表

Linux command

color 命令

文本

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Display ANSI colors in terminal

for i in {0..255}; do printf "\e[38;5;${i}m%3d " $i; done

Set text color

echo -e "\e[31mRed text\e[0m"

Set background color

echo -e "\e[44mBlue background\e[0m"

Bold text

echo -e "\e[1mBold text\e[0m"

Combine styles

echo -e "\e[1;31;44mBold red on blue\e[0m"

Reset all formatting

echo -e "\e[0m"

说明

Terminal color is controlled through ANSI escape sequences, special character codes interpreted by terminal emulators to change text appearance. These sequences start with ESC (\\e, \\033, or \\x1b) followed by formatting codes. Colors enhance readability of command output, differentiate log levels, highlight errors, and improve user interfaces in terminal applications. Most modern terminals support 256 colors and true color (16 million colors). The tput command provides a portable way to generate escape sequences. Environment variables like TERM and NO_COLOR influence color support detection.

FAQ

What is the color command used for?

Terminal color is controlled through ANSI escape sequences, special character codes interpreted by terminal emulators to change text appearance. These sequences start with ESC (\\e, \\033, or \\x1b) followed by formatting codes. Colors enhance readability of command output, differentiate log levels, highlight errors, and improve user interfaces in terminal applications. Most modern terminals support 256 colors and true color (16 million colors). The tput command provides a portable way to generate escape sequences. Environment variables like TERM and NO_COLOR influence color support detection.

How do I run a basic color example?

Run `for i in {0..255}; do printf "\e[38;5;${i}m%3d " $i; done` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

Where can I find more color examples?

This page includes 6 examples for color, plus related commands for nearby Linux tasks.