By Bill R


2019-02-11 00:25:23 8 Comments

I teach an Intro to UNIX/Linux course at a local college and one of my students asked the following question:

Why are some of the files in my directory colored white and others are gray? Are the white ones the ones I created today and the gray are existing files?

As I looked into this I first thought the answer would be in the LS_COLORS variable, but further investigation revealed that the color listings were different when using the -l switch versus the -al switch with the ls command. See the following screen shots:

using ls -l the file named '3' shows as white

using the -al switch the same file shows a gray

Using ls -l the file named '3' shows as white but using the -al switch the same file shows a gray.

Is this a bug in ls or does anyone know why this is happening?

2 comments

@Isaac 2019-02-23 05:28:39

The whole output of ls will be printed in the last active color. If ls is called without color:

$ printf '\e[0;31m color test\n'; /bin/ls
 color test
filea  fileb  filec  filed  filee  filef  fileg  fileh

will print the list of files in red.

Or, if there is no color change needed for ls, the last color will remain:

$ mkdir t1; cd t1; touch file{a..h}
$ printf '\e[0;31m color test\n'; /bin/ls --color -l
 color test
total 0
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh

Still, all in red.

But, as soon as ls needs to set a color (and then reset colors to the default used by the console), the color used from then on will be the console default.

$ printf '\e[0;31m color test\n'; /bin/ls --color -la
 color test
total 8
drwxr-xr-x 2 user user 4096 Feb 23 01:16 .
drwxr-x--- 7 user user 4096 Feb 23 01:15 ..
-rw-r--r-- 1 user user    0 Feb 23 01:16 filea
-rw-r--r-- 1 user user    0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user    0 Feb 23 01:16 filec
-rw-r--r-- 1 user user    0 Feb 23 01:16 filed
-rw-r--r-- 1 user user    0 Feb 23 01:16 filee
-rw-r--r-- 1 user user    0 Feb 23 01:16 filef
-rw-r--r-- 1 user user    0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user    0 Feb 23 01:16 fileh

With the first three lines (up to the blue dot) printed in red.

@Thomas Dickey 2019-02-11 00:48:03

It looks as if your prompt-string ($PS1) is setting the bold attribute on characters to make the colors nicer, and not unsetting it. The output from ls doesn't know about this, and does unset bold. So after the first color output of ls, everything looks dimmer.

@Bill R 2019-02-11 19:09:36

Yep, that was it. Last color change in $PS1 set bold+white (1;37) -- Thanks!

@Thomas Dickey 2019-02-12 00:13:43

You can mark it accepted, then.

Related Questions

Sponsored Content

2 Answered Questions

[SOLVED] how to disable color in output of 'top' command?

2 Answered Questions

[SOLVED] Filter output of command by color

2 Answered Questions

[SOLVED] Unable to set LS_COLORS in bash using script

2 Answered Questions

[SOLVED] Alternate prompt, command, and output color

  • 2018-06-16 16:22:21
  • Austin Weaver
  • 213 View
  • 2 Score
  • 2 Answer
  • Tags:   terminal colors

4 Answered Questions

[SOLVED] Mount point color

  • 2016-09-14 11:35:26
  • Explorer_N
  • 552 View
  • 0 Score
  • 4 Answer
  • Tags:   ls colors

1 Answered Questions

[SOLVED] Different vim colors and styles in Tmux and Gnome

3 Answered Questions

[SOLVED] CLICOLOR and LS_COLORS in bash

0 Answered Questions

Strange Highlighting Color In ZSH Menu

1 Answered Questions

[SOLVED] Using NVIDIA instead of Intel causes a different theme

3 Answered Questions

[SOLVED] Preserving color output with cut

Sponsored Content