Unix – When could or should I use chmod g+s on a file or directory


In deploying to a new (Solaris 9) environment recently, one of the steps was to copy a set of files and directories to their new location and then to apply the group UID bit (using "chmod -R g+s") to all files in the directory tree giving a mode of -rwxr-s— to everything. The result was that none of our shell scripts would execute unless they were individually opened and re-saved. I should add that we had earlier set g+s on the target parent folder prior to copying files; this had set the initial mode on all the new directories to drwxr-s— but the files had a mode of -rwxr-x—

Having eventually discovered which step caused the problem, we were able to cut out that step and proceed.

I would like, however, to understand what the "s" bit means when applied to directories and files, in the hope that this will explain why we had the problem in the first place.

Best Solution

Setting directories g+s makes all new files created in said directory have their group set to the directory's group.

This can actually be really handy for collaborative purposes if you have the umask set so that files have group write by default.

Note: This is the way it works in Linux, it could work completely differently in Solaris.

Related Question