I teach an Intro to UNIX/Linux course at a local college and one of my students ask 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 verses 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?

  • Wrt your question title: such coloring has nothing to do with the ls command itself. – Drew Feb 11 at 2:32
  • FWIW, the closest you can get to this by messing with LS_COLORS is LS_COLORS='rs=0;1' ls -l, but it looks very different. – wjandrea Feb 11 at 5:23
  • 3
    @Drew You only know that after investigating the problem. Obviously ls can change the color of its output. – pipe Feb 11 at 10:50
  • @pipe: Nah, I know that from long before there was color. It need not provide color, even if recent versions of ls can provide color. ;-) – Drew Feb 11 at 14:25

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.

  • 1
    Yep, that was it. Last color change in $PS1 set bold+white (1;37) -- Thanks! – Bill R Feb 11 at 19:09
  • 3
    You can mark it accepted, then. – Thomas Dickey Feb 12 at 0:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.