What causes this green background in ls output?
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:
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 ruleTEXT_STYLE
indicates the text style:00
= none01
= bold04
= underscore05
= blink07
= reverse,08
= concealed
FOREGROUND_COLOR
indicates the foreground color:30
= black31
= red32
= green33
= yellow34
= blue,35
= magenta36
= cyan37
= white
BACKGROUND_COLOR
indicates the background colors:40
= black41
= red42
= green43
= yellow44
= blue,45
= magenta46
= cyan47
= 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:
The colors of ls
can represent the permissions, the defaults for some systems is to show directories where everyone has write permissions with a green background:
You can change the colors by editing your $LS_COLORS
variable using dircolors
(from man ls
):
Using color to distinguish file types is disabled both by default and
with --color=never. With --color=auto, ls emits color codes only when
standard output is connected to a terminal. The LS_COLORS environment
variable can change the settings. Use the dircolors command to set it.
The syntax is admittedly kind of annoying here but you can change this color by creating a file with the colors you want and saving it as ~/.dircolors
:
dircolors -p > ~/.dircolors
That command will print the defaults into ~/.dircolors
. You will then need to edit that file and change this line:
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
For example, to make it black text on a red background (see here for a list of color codes):
OTHER_WRITABLE 30;41 # dir that is other-writable (o+w) and not sticky
You don't need to have all the defaults, you can also just create a file with a single line, redefining just the one you want to change. Anyway, once you have created the file, load it with:
eval "$(dircolors ~/.dircolors)";
And here it is in action:
To have that happen automatically, add the eval
command above to your ~/.bashrc
file.
While all the technical answers are true, I would consider it a bit of an informal warning, that you dished out rights a bit to generously or copying criss+cross... (most often we all do, to get things initially working, eh?)
How to make it blue on black,... ?
A good „de-greener“ to get back to rights you most likely want, is this statement:
chmod -R a-x,o-w,+X thatGreenFolderWithSubfolders/
Best understood what it does, if you understand the purpose of uppercase +X „special execute“, i.e. see Wikipedia
It is only really useful when used with '+' and usually in combination with the -R option for giving group or other access to a big directory tree without setting execute permission on normal files (such as text files), which would normally happen if you just used "chmod -R a+rx...