Interestingly. this seems to be impossible using GNU chmod
, and that's a feature. From the info
entry on chmod
on my system; note how, whilst the entry on setting the bits makes reference to symbolic and numeric modes, the entry on clearing them refers only to symbolic (ug-s
) mode:
27.4 Directories and the Set-User-ID and Set-Group-ID Bits
These convenience mechanisms rely on the set-user-ID and
set-group-ID bits of directories. If commands like chmod' and
mkdir' routinely cleared these bits on directories, the mechanisms
would be less convenient and it would be harder to share files.
Therefore, a command like `chmod' does not affect the set-user-ID or
set-group-ID bits of a directory unless the user specifically mentions
them in a symbolic mode, or sets them in a numeric mode.
[...]
If
you want to try to set these bits, you must mention them explicitly in
the symbolic or numeric modes, e.g.:
[...]
If you want to try to
clear these bits, you must mention them explicitly in a symbolic mode,
e.g.:
[...]
This behavior is a GNU extension. Portable scripts
should not rely on requests to set or clear these bits on directories,
as POSIX allows implementations to ignore these requests.