Question: 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.

Answer: 
Here is very handy explanation of SGID (chmod g+s): <http://www.linuxnix.com/sgid-set-sgid-linuxunix/>

> 
> SGID (Set Group ID up on execution) is a special type of file
>  permissions given to a file/folder. Normally in Linux/Unix when a
>  program runs, it inherits access permissions from the logged in user.
>  SGID is defined as giving temporary permissions to a user to run a
>  program/file with the permissions of the file group permissions to
>  become member of that group to execute the file. In simple words users
>  will get file Group’s permissions when executing a
>  Folder/file/program/command.
> 
> 
>
When you need to use it: Fix SVN file ownership issue when you use svn+ssh. Somebody told me it only happens on BDB, but I had such issue in FSFS storage too. Basically when you want to keep the ownership of child files inside a directory consistent when there are other users writing stuff on it, you would have to use u+s/g+s.