Controlling colors when using the ls command
The following are instructions for controlling the colors that appear when using the ls command.
The ls version which can utilize the --color option can list files by color depending on the filename(extension) or the file type.
Colors initially depend on the file type, but this can be changed using the environment variable "LS_COLORS(or LS_COLOURS)."
1. Environment variable type
LS_COLORS='type:type:type:...'
The item format is 'xx=string'
xx represents the two character file type. Strings can be separated by ';' to define values (properties and colors).
2. File type
no | Plain text, not filename |
fi | Normal file |
di | Directory |
ln | Symbolic link |
pi | FIFO(Pipe) |
so | Socket |
bd | Block device |
cd | Character device |
ex | Execution file |
mi | Lost file (default is fi) |
or | Files without symbolic link targets (default is ln) |
su | SETUID setting file(u+s) |
sg | SETGID setting file(g+s) |
tw | Other user writable Sticky bit directories(+t, o+w) |
ow | Other user writable directories (o+w) but not Sticky bit(-t, o+w). |
st | Non other user writable Sticky bit directories(+t, o-w) |
You can also use the '*' character to apply to regular file names. It is typically used to express extension colors.
The format is '*filename=string'
Example)
*.tar=00;31 => Files with the tar extension are displayed as red (second color).
*README=01:32 => The README file is displayed as highlighted and green (third color).
3. Properties and Colors
Attribute | |
---|---|
00 | Reset |
01 | Highlight color |
04 | Underline |
05 | Blinking text |
07 | Inverse |
05 | Hide |
Foreground | |
30 | First color (ANSI color black) |
31 | Second color (ANSI color red) |
32 | Third color (ANSI color green) |
33 | Fourth color (ANSI color yellow or brown) |
34 | Fifth color (ANSI color blue) |
35 | Sixth color (ANSI color purple) |
36 | Seventh color (ANSI color cyan) |
37 | Eighth color (ANSI color white or gray) |
Background | |
40 | First color (ANSI color black) |
41 | Second color (ANSI color red) |
42 | Third color (ANSI color green) |
43 | Fourth color (ANSI color yellow or brown) |
44 | Fifth color (ANSI color blue) |
45 | Sixth color (ANSI color purple) |
46 | Seventh color (ANSI color cyan) |
47 | Eighth color (ANSI color white or gray) |
4. Color representation in Xshell
Relative Link
Xshell has a feature that allows users to specify colors that appear in the terminal.
The foreground and background colors listed in step 3 follow the color orders in Xshell's color scheme.
5. Examples in XSHELL
- fi=00: => Regular files have no attribute.
- di=01;34: => Directories are highlighted and the fifth color (light blue)
- ln=01;36: => Symbolic link files are highlighted and the seventh color (light cyan)
- or=31;40: => Symbolic link files with a lost link are displayed in red with a black background
- ex=01;32: => Executable files are highlighted and the third color (light green)
- *.tar=01;31 => Files with the tar extension are the second color (red)
In the color scheme's ANSI color Xshell uses the first line's color for regular characters and the second line's color for emphasis (bold) characters.