Inconsistent color output from `ls` command

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












28















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?










share|improve this question
























  • 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






  • 4





    @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
















28















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?










share|improve this question
























  • 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






  • 4





    @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














28












28








28


2






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?










share|improve this question
















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?







linux command-line ls colors






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









fra-san

1,8291518




1,8291518










asked Feb 11 at 0:25









Bill RBill R

14615




14615












  • 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






  • 4





    @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


















  • 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






  • 4





    @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

















Wrt your question title: such coloring has nothing to do with the ls command itself.

– Drew
Feb 11 at 2:32





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





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




4




4





@Drew You only know that after investigating the problem. Obviously ls can change the color of its output.

– pipe
Feb 11 at 10:50





@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






@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











2 Answers
2






active

oldest

votes


















68














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.






share|improve this answer


















  • 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


















0














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



$ printf 'e[0;31m color testn'; /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 filea..h
$ printf 'e[0;31m color testn'; /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 testn'; /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.






share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499840%2finconsistent-color-output-from-ls-command%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    68














    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.






    share|improve this answer


















    • 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















    68














    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.






    share|improve this answer


















    • 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













    68












    68








    68







    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.






    share|improve this answer













    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 11 at 0:48









    Thomas DickeyThomas Dickey

    53.7k5103175




    53.7k5103175







    • 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












    • 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







    1




    1





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

    – Bill R
    Feb 11 at 19:09






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

    – Bill R
    Feb 11 at 19:09





    3




    3





    You can mark it accepted, then.

    – Thomas Dickey
    Feb 12 at 0:13





    You can mark it accepted, then.

    – Thomas Dickey
    Feb 12 at 0:13













    0














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



    $ printf 'e[0;31m color testn'; /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 filea..h
    $ printf 'e[0;31m color testn'; /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 testn'; /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.






    share|improve this answer



























      0














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



      $ printf 'e[0;31m color testn'; /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 filea..h
      $ printf 'e[0;31m color testn'; /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 testn'; /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.






      share|improve this answer

























        0












        0








        0







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



        $ printf 'e[0;31m color testn'; /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 filea..h
        $ printf 'e[0;31m color testn'; /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 testn'; /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.






        share|improve this answer













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



        $ printf 'e[0;31m color testn'; /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 filea..h
        $ printf 'e[0;31m color testn'; /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 testn'; /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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 23 at 5:28









        IsaacIsaac

        12k11852




        12k11852



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499840%2finconsistent-color-output-from-ls-command%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay