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


The following represent the xx characters described in step 1.
noPlain text, not filename
fiNormal file
diDirectory
lnSymbolic link
piFIFO(Pipe)
soSocket
bdBlock device
cdCharacter device
exExecution file
miLost file (default is fi)
orFiles without symbolic link targets (default is ln)
suSETUID setting file(u+s)
sgSETGID setting file(g+s)
twOther user writable Sticky bit directories(+t, o+w)
owOther user writable directories (o+w) but not Sticky bit(-t, o+w).
stNon 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
00Reset
01Highlight color
04Underline
05Blinking text
07Inverse
05Hide
Foreground
30First color (ANSI color black)
31Second color (ANSI color red)
32Third color (ANSI color green)
33Fourth color (ANSI color yellow or brown)
34Fifth color (ANSI color blue)
35Sixth color (ANSI color purple)
36Seventh color (ANSI color cyan)
37Eighth color (ANSI color white or gray)
Background
40First color (ANSI color black)
41Second color (ANSI color red)
42Third color (ANSI color green)
43Fourth color (ANSI color yellow or brown)
44Fifth color (ANSI color blue)
45Sixth color (ANSI color purple)
46Seventh color (ANSI color cyan)
47Eighth color (ANSI color white or gray)

4. Color representation in Xshell


Please see the following link for ls command color representations 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.