Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

chmod question

3 views
Skip to first unread message

Kid Mustang

unread,
Nov 14, 2007, 4:56:56 PM11/14/07
to
Hi all,

Referring to the 'chmod' command, how can you tell who is in your
'group'? Can you set that somehow? I cannot find anything in the man page.

TiA,

KM

dineed

unread,
Nov 20, 2007, 12:21:52 AM11/20/07
to

Hi, to get the members of a particular group there are a couple of
commands you can run. This can be scripted and executed as needed:
1. Get group ID number:
grep '^GROUPNAME' /etc/group ## this will return the
entry for the group GROUPNAME from the /etc/group file - the second
number (separated by colons) is the group ID. This will also list the
members of this group for whom the group is not their primary group.

2. Search for members of this group in /etc/passwd
awk -F":" '($4 == groupID) { print $0}' ## this will return
all user IDs from the /etc/passwd file where your target group ID is
the primary group.

Users can belong to more than one group. The one listed along with
their user ID entry in the /etc/passwd file is their primary group.
When a user ID is included in a record in the /etc/group file, then
that group is a secondary group for that user ID.

You can add additional code and save it as a script to clean up the
data returned and actually capture the userID and user name for all
the members of a particular group.

I hope this helps.

nob...@nobody.com

unread,
Feb 15, 2008, 11:20:58 AM2/15/08
to
Say your group is called "staff". Run this:

grep staff /etc/passwd

Wayne

unread,
Feb 15, 2008, 5:53:00 PM2/15/08
to

I don't think that would work. To find all the members
of some group (say "staff") when using files (as opposed
to NIS/NIS+/LDAP), you need to find all users in /etc/passwd
that list that group as some user's primary group plus
all the supplemental members listed in /etc/group. However
primary groups are referenced by the group ID number in
/etc/passed, not the name.

While there is probably a standard utility for this I couldn't
think of it. So here's a quick and dirty shell script you
can use:

#!/bin/sh -
# List all members of a given group, using "FILES" (/etc/passwd and /etc/group)
PATH=$(/usr/bin/getconf PATH)
[ $# -ne 1 ] && exit -1
GID=$(grep "^${1}:" /etc/group |cut -d: -f3)
if [ "${GID}" != "" ]; then
PUSERS=$(awk -F: '$4=="'"${GID}"'" {print $1}' /etc/passwd)
fi
SUSERS=$(grep "^${1}:" /etc/group |cut -d: -f4-)
printf '%s' "$P{USERS},${SUSERS}" |tr ',' '\n' | sort -u | grep -v '^$'

-Wayne

0 new messages