Terminal – What Causes Green Background in ls Output?

colorslsterminal

screencap of ls output on linux machine

There are two directories shown by 'ls'. Normally directories anywhere are blue on black background. But the first one is blue on green and impossible to read. Why is this? How to make it blue on black, or at least something light on something dark?

This is on Ubuntu 12.04, using bash in Gnome Terminal. In Konsole, the blue is slightly darker, and possible to read, though could be way better.

Best Answer

Apart from coloring files based on their type (turquoise for audio files, bright red for Archives and compressed files, and purple for images and videos), ls also colors files and directories based on their attributes:

  • Black text with green background indicates that a directory is writable by others apart from the owning user and group, and has the sticky bit set (o+w, +t).
  • Blue text with green background indicates that a directory is writable by others apart from the owning user and group, and does not have the sticky bit set (o+w, -t).

Stephano Palazzo over at Ask Ubuntu has made this very instructive picture over the different attribute colors:

What the different colors mean in the terminal

As terdon pointed out, the color settings can be modified via dircolors. A list of the different coloring settings can be accessed with dircolors --print-database.

Each line of output, such as BLK 40;33;01, is of the form:

[TARGET] [TEXT_STYLE];[FOREGROUND_COLOR];[BACKGROUND_COLOR]
  • TARGET indicates the target for the coloring rule

  • TEXT_STYLE indicates the text style:

    • 00 = none
    • 01 = bold
    • 04 = underscore
    • 05 = blink
    • 07 = reverse,
    • 08 = concealed
  • FOREGROUND_COLOR indicates the foreground color:

    • 30 = black
    • 31 = red
    • 32 = green
    • 33 = yellow
    • 34 = blue,
    • 35 = magenta
    • 36 = cyan
    • 37 = white
  • BACKGROUND_COLOR indicates the background colors:

    • 40 = black
    • 41 = red
    • 42 = green
    • 43 = yellow
    • 44 = blue,
    • 45 = magenta
    • 46 = cyan
    • 47 = white

Fields may be omitted starting from the right, so for instance .tar 01;31 means bold and red.

XTerm and most other modern terminal emulators support 256 colors.

A XTerm 256-color foreground color code is of the form:

38;5;[FOREGROUND_COLOR]

A XTerm 256-color background color code is of the form:

48;5;[BACKGROUND_COLOR]

where both FOREGROUND_COLOR and BACKGROUND_COLOR is a number the range 0-255. A full list of color codes for the 16 and 256 color modes are shown in the below screenshot:

16 and 256 color mode color codes

Related Question