1819928 Members
3069 Online
109607 Solutions
New Discussion юеВ

How to list users groups

 
SOLVED
Go to solution
Michael Campbell
Trusted Contributor

How to list users groups

Quick question for someone

Does anyone know of a quick and easy way to list a user's primary and secondary groups (equivalent to the lsuser command on AIX)

Any Help Appreciated

Michael
4 REPLIES 4
U.SivaKumar_2
Honored Contributor

Re: How to list users groups

Hi,
Give this command
#id

regards,
U.Sivakumar
Innovations are made when conventions are broken
Stefan Farrelly
Honored Contributor

Re: How to list users groups


id
Im from Palmerston North, New Zealand, but somehow ended up in London...
Joaquin Gil de Vergara
Respected Contributor
Solution

Re: How to list users groups

# for i in $(cat /etc/passwd | cut -f 1,1 -d:)
> do
> echo "user: $i ";id $i
> done
user: root
uid=0(root) gid=3(sys) groups=0(root),1(other),2(bin),4(adm),5(daemon),6(mail),
(lp),20(users)
user: daemon
uid=1(daemon) gid=5(daemon)
user: bin
uid=2(bin) gid=2(bin)
user: sys
uid=3(sys) gid=3(sys)
user: adm
uid=4(adm) gid=4(adm)
user: uucp
uid=5(uucp) gid=3(sys)
user: lp
uid=9(lp) gid=7(lp)
user: nuucp
uid=11(nuucp) gid=11(nuucp)
user: hpdb
uid=27(hpdb) gid=1(other)
user: nobody
uid=4294967294(nobody) gid=4294967294(nogroup)
user: www
uid=30(www) gid=1(other)
user: javier
uid=101(javier) gid=0(root)
user: jgil
uid=102(jgil) gid=20(users)
#
Teach is the best way to learn
Ralph Grothe
Honored Contributor

Re: How to list users groups

Hi Michael,

id -gn

will list the primary group belongs to (brackets shall indicate required argument, not to be typed)

wheras

id -Gn

will list all the groups that account belongs to

You may easily put these commands in a small script that parses each entry from your passwd
Madness, thy name is system administration