[CentOS] Shell script to list group members
ian at ikel.id.au
Wed Sep 24 23:19:14 UTC 2008
Bob Beers wrote:
> Part 1:
> You have a valid point, but the OP's question was:
> "I am looking for a (simple) shell command to run from a bash script
> that will allow me to list user accounts that belong to a particular
In all likelihood the system follows the default approach of setting the
primary group to be the user's personal ground. If that is the case
then you're correct in providing a simple solution as requested. I just
wanted to make Tim aware that if his user's have primary groups other
than their personal groups - e.g. "admin" or "marketing" - then there
isn't a simple answer (not that the answer is all that hard).
Here's a script I knocked up to do it - although there can be
duplication and output formatting isn't perfect:-
# $1 is the group to test
if [ "$1" = "" ]; then
echo "Which group?"
groupid=$(getent group $1 | cut -d: -f3)
grouplst=$(getent group $1 | cut -d: -f4)
for User in $(cat /etc/passwd | cut -f1 -d:)
if [ $(id -g $User) = $groupid ]; then
echo "Members of group $1 are: $grouplst"
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 3617 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.centos.org/pipermail/centos/attachments/20080925/33030434/smime.bin
More information about the CentOS