0

Can someone please explain to me why when listing certain files with the same extension, eg .jpg files, why they are sometimes listed green, as well as shown in pink. These are all image files. It doesn't make sense.

Listing of image files

2

The file WhiterShadePale1.jpg has execute permissions. That's all there is to it. The executable colour overrides the *.jpg colour.

  • I know it's shown as an executable file, but why? It isn't a program. It's just an image file like the others that are shown. – Paul Benson Apr 10 '18 at 19:52
  • 1
    It's shown as an excecutable because it IS an executable :) The reason for that could be many, but it's obviously a wrong executeable flag set on this particular file. By the way ls with colors will often help to identify permissions issues like this. – Sebastian Stark Apr 10 '18 at 19:59
  • @PaulBenson It has its execute permissions. If you run ls -l WhiterShadePale1.jpg, you will probably see the first column is -rwxrwxr-x, where the x's indicate execute permissions. For more info, see How do file permissions work? – wjandrea Apr 10 '18 at 20:02
  • @PaulBenson If it wasn't clear, the file doesn't need to have execute permissions, but it's not a problem. – wjandrea Apr 10 '18 at 20:26
  • Thnx. It's clearer now. – Paul Benson Apr 10 '18 at 20:42
0

The colors are controlled by the environment variable LS_COLORS.

The ls man page states:

LS_COLORS       The value of this variable describes what color to use
                for which attribute when colors are enabled with
                CLICOLOR.  This string is a concatenation of pairs of the
                format fb, where f is the foreground color and b is the
                background color.

                The color designators are as follows:

                      a     black
                      b     red
                      c     green
                      d     brown
                      e     blue
                      f     magenta
                      g     cyan
                      h     light grey
                      A     bold black, usually shows up as dark grey
                      B     bold red
                      C     bold green
                      D     bold brown, usually shows up as yellow
                      E     bold blue
                      F     bold magenta
                      G     bold cyan
                      H     bold light grey; looks like bright white
                      x     default foreground or background

                Note that the above are standard ANSI colors.  The actual
                display may differ depending on the color capabilities of
                the terminal in use.

                The order of the attributes are as follows:

                      1.   directory
                      2.   symbolic link
                      3.   socket
                      4.   pipe
                      5.   executable
                      6.   block special
                      7.   character special
                      8.   executable with setuid bit set
                      9.   executable with setgid bit set
                      10.  directory writable to others, with sticky bit
                      11.  directory writable to others, without sticky
                           bit

                The default is "exfxcxdxbxegedabagacad", i.e. blue fore-
                ground and default background for regular directories,
                black foreground and red background for setuid executa-
                bles, etc.
  • 1
    I think you got that from a BSD manpage, cause on Ubuntu, LSCOLORS is not used. Instead it's LS_COLORS, which has a totally different structure. – wjandrea Apr 10 '18 at 20:23
  • You're right. Let me update. Seems like the Ubuntu man page doesn't go into as much detail about how it works as the BSD but since this is from GNU coreutils it shouldn't matter. – tk421 Apr 10 '18 at 21:29
  • askubuntu.com/questions/466198/… goes into more details. There is another command dircolors(1) - manpages.ubuntu.com/manpages/xenial/en/man1/dircolors.1.html which can be used to set colors. – tk421 Apr 10 '18 at 21:42
  • Your update didn't fix the problem. It's not just that the variable has a different name, it's that it has a totally different internal structure: it's a colon-delimited list of type=color pairs. – wjandrea Apr 10 '18 at 21:52

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.