Test whether file is owned by a specific group from bash or powershell level?

Sam Edge sam.edge.cygwin@gmx.com
Fri Jun 20 15:22:45 GMT 2025


On 20/06/2025 16:20, Sam Edge via Cygwin wrote:
> On 20/06/2025 13:15, Sebastian Feld via Cygwin wrote:
>> Does Cygwin or POSIX have a tool to test whether a file is owned by a
>> specific group?
>>
>> Win32, like Linux and POSIX, has the concept that files have an owner,
>> and a group (ref:https://learn.microsoft.com/en-us/windows/win32/api/ 
>> aclapi/nf-aclapi-getsecurityinfo).
>>
>> How can I test whether a file is owned by a given group name, or not?
>> /usr/bin/test -g and -G do not help because they only look and gid,
>> egid. But I want to pass the group's name as an argument.
>>
>> Sebi
> 
> Group name:
> stat -c %G <file>
> 
> Group ID:
> stat -c %g <file>
> 
> 
> 

Sorry, so:

[ "$(stat -c %G myfile)" = mygroup ]

will return true (i.e. $? zero) if myfile is owned by mygroup.

-- 
Sam Edge
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x8AC2CEBF54528E30.asc
Type: application/pgp-keys
Size: 648 bytes
Desc: OpenPGP public key
URL: <https://cygwin.com/pipermail/cygwin/attachments/20250620/9a7158c9/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <https://cygwin.com/pipermail/cygwin/attachments/20250620/9a7158c9/attachment-0001.sig>


More information about the Cygwin mailing list