How to colourise hidden files in `ls` file listings?












9















LS_COLORS environmental variable lets you decide on colours for different file types for GNU coreutil's ls command, such as directories, regular files, links etc. I suppose that dot files are considered a variation of the Linux file types and not a type on its own hence there is no option for specifying a display colour for them.



Is there any (other) way you can make ls listings show hidden files in a different colour?










share|improve this question
















bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • This answer has more than you ever wanted to know about LS_COLORS. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.

    – terdon
    Sep 23 '14 at 14:52






  • 1





    @terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named *.hide for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.

    – mikeserv
    Sep 23 '14 at 15:43


















9















LS_COLORS environmental variable lets you decide on colours for different file types for GNU coreutil's ls command, such as directories, regular files, links etc. I suppose that dot files are considered a variation of the Linux file types and not a type on its own hence there is no option for specifying a display colour for them.



Is there any (other) way you can make ls listings show hidden files in a different colour?










share|improve this question
















bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • This answer has more than you ever wanted to know about LS_COLORS. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.

    – terdon
    Sep 23 '14 at 14:52






  • 1





    @terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named *.hide for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.

    – mikeserv
    Sep 23 '14 at 15:43
















9












9








9


1






LS_COLORS environmental variable lets you decide on colours for different file types for GNU coreutil's ls command, such as directories, regular files, links etc. I suppose that dot files are considered a variation of the Linux file types and not a type on its own hence there is no option for specifying a display colour for them.



Is there any (other) way you can make ls listings show hidden files in a different colour?










share|improve this question
















LS_COLORS environmental variable lets you decide on colours for different file types for GNU coreutil's ls command, such as directories, regular files, links etc. I suppose that dot files are considered a variation of the Linux file types and not a type on its own hence there is no option for specifying a display colour for them.



Is there any (other) way you can make ls listings show hidden files in a different colour?







ls filenames colors






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 2 '17 at 14:50









Kusalananda

126k16239393




126k16239393










asked Sep 23 '14 at 14:18









Johnny BaloneyJohnny Baloney

1764




1764





bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • This answer has more than you ever wanted to know about LS_COLORS. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.

    – terdon
    Sep 23 '14 at 14:52






  • 1





    @terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named *.hide for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.

    – mikeserv
    Sep 23 '14 at 15:43





















  • This answer has more than you ever wanted to know about LS_COLORS. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.

    – terdon
    Sep 23 '14 at 14:52






  • 1





    @terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named *.hide for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.

    – mikeserv
    Sep 23 '14 at 15:43



















This answer has more than you ever wanted to know about LS_COLORS. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.

– terdon
Sep 23 '14 at 14:52





This answer has more than you ever wanted to know about LS_COLORS. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.

– terdon
Sep 23 '14 at 14:52




1




1





@terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named *.hide for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.

– mikeserv
Sep 23 '14 at 15:43







@terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named *.hide for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.

– mikeserv
Sep 23 '14 at 15:43












2 Answers
2






active

oldest

votes


















0














If you're only sorting by name, this might help:



alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$


However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.






share|improve this answer































    -1














    If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"



    If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS does not natively support colorizing hidden files as it seems.



    I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS environment variable as a pseudo extension, then execute ls -la and after that run dircolors to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.



    Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.



    for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)






    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%2f157058%2fhow-to-colourise-hidden-files-in-ls-file-listings%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









      0














      If you're only sorting by name, this might help:



      alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$


      However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.






      share|improve this answer




























        0














        If you're only sorting by name, this might help:



        alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$


        However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.






        share|improve this answer


























          0












          0








          0







          If you're only sorting by name, this might help:



          alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$


          However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.






          share|improve this answer













          If you're only sorting by name, this might help:



          alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$


          However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 7 '15 at 11:32









          goofygoofy

          1




          1

























              -1














              If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"



              If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS does not natively support colorizing hidden files as it seems.



              I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS environment variable as a pseudo extension, then execute ls -la and after that run dircolors to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.



              Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.



              for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)






              share|improve this answer






























                -1














                If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"



                If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS does not natively support colorizing hidden files as it seems.



                I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS environment variable as a pseudo extension, then execute ls -la and after that run dircolors to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.



                Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.



                for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)






                share|improve this answer




























                  -1












                  -1








                  -1







                  If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"



                  If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS does not natively support colorizing hidden files as it seems.



                  I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS environment variable as a pseudo extension, then execute ls -la and after that run dircolors to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.



                  Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.



                  for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)






                  share|improve this answer















                  If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"



                  If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS does not natively support colorizing hidden files as it seems.



                  I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS environment variable as a pseudo extension, then execute ls -la and after that run dircolors to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.



                  Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.



                  for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 23 '14 at 16:59

























                  answered Sep 23 '14 at 16:16









                  Michael OslMichael Osl

                  1245




                  1245






























                      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%2f157058%2fhow-to-colourise-hidden-files-in-ls-file-listings%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

                      Loup dans la culture

                      How to solve the problem of ntp “Unable to contact time server” from KDE?

                      ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux