In linux, you can customize your own color scheme, whether it is the color of the linux Command Prompt or the output color of stdout.
In/etc/DIR_COLORS, you can find the following description:
Shell code
[Root @ CentOS ~]
# Cat/etc/DIR_COLORS
# Below are the color init strings for the basic file types. A color init
# String consists of one or more of the following numeric codes:
# 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 shoshould be something.
FILE 00 # normal file
DIR 01; 34 # directory
LINK 01; 36 # symbolic link
FIFO 40; 33 # pipe
SOCK 01; 35 # socket
BLK 40; 33; 01 # block device driver
CHR 40; 33; 01 # character device driver
ORPHAN 01; 05; 37; 41 # orphaned syminks
MISSING 01; 05; 37; 41 #... and the files they point
-- The most important part is here:
Txt code
# 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
The following are two examples:
1. color the output characters
Define a script:
Shell code
#! /Bin/bash
# Define some colors first:
Red = '\ e [0; 31m' # red
RED = '\ e [1; 31m' # RED + bold (and so on)
Green = '\ e [0; 32m' # green
GREEN = '\ e [1; 32m'
Yellow = '\ e [0; 33m' # yellow
YELLOW = '\ e [1; 33m'
Blue = '\ e [0; 34m' # blue
BLUE = '\ e [1; 34m'
Purple = '\ e [0; 35m' # purple
PURPLE = '\ e [1; 35m'
Cyan = '\ e [0; 36m' # Blue-green
CYAN = '\ e [1; 36m'
WHITE = '\ e [1; 37m' # WHITE
NC = '\ e [0m' # No color
Echo-e "$ {CYAN} This is BASH $ {RED} $ {BASH_VERSION %. * }$ {CYAN}-DISPLAY on $ {RED} $ DISPLAY $ {NC} \ n"
Echo-e "$ {RED} RED $ {BLUE} BLUE $ {cyan} cyan $ {GREEN} GREEN $ {NC }"
Echo-e "$ {CYAN} white $ {WHITE} blod white $ {NC} no color !! "
Echo "$ {CYAN} white $ {WHITE} blod white $ {NC} no color !! "# Note this sentence
The running result is as follows:
Note: The-e parameter must be added to output the color correctly.
(-E explanation:-e enable interpretation of backslash escapes | meaning that the backslash can be interpreted)
2. Modify the command prompt (that is, [root @ CentOS ~] #)
We can give [root @ CentOS ~] # Add color and custom format:
Modify/etc/bashrc to achieve our goal:
Vi/ete/bashrc, which is the same as above, is roughly changed to the following format (the color can be changed by yourself)
Shell code
Red = '\ e [0; 31m' # red
Cyan = '\ e [0; 36m' # Blue-green
NC = '\ e [0m' # No color
# ["$ PS1" = "\ s-\ v \ $"] & PS1 = "[\ u @ \ h \ W] \ $"
["$ PS1" = "\ s-\ v \ $"] & PS1 = "[$ {red} \ u $ {NC }@$ {cyan} \ h $ {NC} \ W] \ $"
Save and exit, and log on to the terminal again. The output is as follows:
The color has changed. It is not all white by default ~
For the command prompt format, refer to this:
Txt code
\ A: an ASCII bell character (07)
\ D: the date in "Weekday Month Date" format (e.g., "Tue May 26 ")
\ D {format}: the format is passed to strftime (3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. the braces are required
\ E: an ASCII escape character (033)
\ H: the hostname up to the first '.'
\ H: the hostname
\ J: the number of jobs currently managed by the shell
\ L: the basename of the shell's terminal device name
\ N: newline
\ R: carriage return
\ S: the name of the shell, the basename of $0 (the portion following the final slash)
\ T: the current time in 24-hour HH: MM: SS format
\ T: the current time in 12-hour HH: MM: SS format
\ @: The current time in 12-hour am/pm format
\ A: the current time in 24-hour HH: MM format
\ U: the username of the current user
\ V: version of bash (e.g., 2.00)
\ V: the release of bash, version + patch level (e.g., 2.00.0)
\ W: the current working directory, with $ HOME abbreviated with a tilde
\ W: the basename of the current working directory, with $ HOME abbreviated with a tilde
\! : The history number of this command
\ #: The command number of this command
\ $: If the specified tive UID is 0, a #, otherwise a $
\ Nnn: the character corresponding to the octal number nnn
\: A backslash
\ [: Begin a sequence of non-printing characters, which cocould be used to embed a terminal control sequence into the prompt
\]: End a sequence of non-printing characters
The best way is to print it all at once.
------------------------------------------------------------- The gorgeous Terminator ------------------------------------------------
I hope it will help you, tks ......
Author: "The days of Growth"