3

Trying to show setgid in a different color and failing.

tried with the minimum: LS_COLORS="sg:41;41" ls -la --color=auto But still got regular directory colors for a setgid (chmod g+s) directory.

Then tried with dircolors, first outputed the "template" with dircolors -p > ~/.dircolors, edited only the setgid line, and eval $(dircolors -b ~/.dircolors)

# ~/.dircolors
…
SETGID 30;44 # file that is setgid (g+s)                                                                                                                              
…

it produces:

env | grep LS_
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;44:ca=00:tw=30;42:ow=30;44;01:st=30;44;01:ex=01;32:*.7z=01;31:*.ace=01;31:*.alz=01;31:*.apk=01;31:*.arc=01;31:*.arj=01;31:*.bz=01;31:*.bz2=01;31:*.cab=01;31:*.cpio=01;31:*.crate=01;31:*.deb=01;31:*.drpm=01;31:*.dwm=01;31:*.dz=01;31:*.ear=01;31:*.egg=01;31:*.esd=01;31:*.gz=01;31:*.jar=01;31:*.lha=01;31:*.lrz=01;31:*.lz=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.lzo=01;31:*.pyz=01;31:*.rar=01;31:*.rpm=01;31:*.rz=01;31:*.sar=01;31:*.swm=01;31:*.t7z=01;31:*.tar=01;31:*.taz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tgz=01;31:*.tlz=01;31:*.txz=01;31:*.tz=01;31:*.tzo=01;31:*.tzst=01;31:*.udeb=01;31:*.war=01;31:*.whl=01;31:*.wim=01;31:*.xz=01;31:*.z=01;31:*.zip=01;31:*.zoo=01;31:*.zst=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:

tried more obvious colors 41;41 (red on red) but nothing.

It does works fine for files, just not for directories.

Here are some screenshots. D1 is a dir with setgid.

ls not showing color for g+s

same with tree just to make sure this is not something isolated to ls tree not showing color for g+s

on the tests above I use su too, because both su and sg are gnu bash extensions not available on other shells.

$ bash --version
GNU bash, version 5.2.26(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

$ ls --version
ls (GNU coreutils) 9.5
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.

6
  • 1
    I think it may be a matter of precedence (directories match di first) - a previous question precedence of dircolors went unanswered though Commented Aug 2 at 16:56
  • @steeldriver good point! Didn't think about this. But, the test is with only a single value (there no di on the screenshots). So it might not be that. Tested adding di to set dirs as red, both before and after sg. nothing changed.
    – gcb
    Commented Aug 2 at 17:31
  • (1) Why do you believe that Bash has anything to do with the handling of LS_COLORS?  (2) Your question would be clearer if you said what results you were expecting.  In particular, what do you expect 41;41 to do?  (3) Have you tried a setgid file?  If the problem is just setgid directories, then your question is actively misleading.   (4) You say “there [is] no di on the screenshots”.  Huh?  Your env command shows di=01;34, which seems to correspond to the bright blue foreground you are getting. Commented Aug 2 at 17:56
  • @G-ManSays'ReinstateMonica' thanks for the notes. (a1) I don't know. added ls version too. (a2) I was trying any color that is not the default dir-blue... 41:41 is all red. (a3) indeed setguid files work fine! (a4) i did unset LS_COLORS! that color is the default from ls i guess? You can see it doesn't show up on tree. I've updated the question with your very good points.
    – gcb
    Commented Aug 2 at 18:15
  • If you mean ALL red (i.e., red foreground and red background, i.e., unreadable), wouldn’t that need to be 31;41? Commented Aug 2 at 19:36

2 Answers 2

6

This has nothing to do with bash: the ls command decides how it formats the output. GNU ls takes its color settings from the LS_COLORS variable, which is meant to be set by the dircolors command. The output of dircolors -p is the closest thing to documentation of dircolors.

# Below are the color init strings for the basic file types.
…
#FILE 00 # regular file: use no color at all
…
DIR 01;34 # directory
…
SETUID 37;41 # file that is setuid (u+s)
SETGID 30;43 # file that is setgid (g+s)
CAPABILITY 30;41 # file with capability
STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
# This is for files with execute permission:
EXEC 01;32

In the lines cited above, “file” means a regular file. Directories and other non-regular files are colored according to their type, not according to their permissions or name, except for sticky/other-writable directories as specified.

There is no setting for setgid directories, or for directories having peculiar access control lists.

3
$ dircolors -p | grep GID
SETGID 30;43 # file that is setgid (g+s)

We should probably improve that description to "regular file".

Note colors can get confusing and non standard quickly with the various combinations of file attributes. I prefer to just highlight appropriate parts of the default ls long format listing, with a wrapper script. My script already highlights SETGID for all file types. See:

https://www.pixelbeat.org/scripts/l

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .