Checking for a certain group to exist

Hi

I feel stupid. How would I check from the command line that a certain group exists? Some command similar to ‘id’ but for groups.

grep ‘GROUP_NAME’ /etc/group

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

To get all system’s groups:

getent group

  • From there you can grep the output… something like the following could
    do it I think:

group | awk -F : ‘{print $1}’ | grep ‘^users$’

Replace users with the group name. If you get a line back then you’re
good, so you can check the output of the command above to see if what you
requested was there or not.

For your own user you can use the ‘groups’ command which will list all of
your current user’s groups.

Good luck.

vodoo wrote:
> Hi
>
> I feel stupid. How would I check from the command line that a certain
> group exists? Some command similar to ‘id’ but for groups.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJLTx6tAAoJEF+XTK08PnB55DQQAJaEIP3BD/TUKLYPRHr3nyvh
DP3IIWTF7xA819xW+xE4I5TCbyX5wY8LM91YFOfosrtCdygYElf0tZgt6YGyHbhD
mPXaE+2HBybSvikdu3RSqzgrQO1vY3iWByvVnOWjt6pdnx/yEHF6SnAvgcDEJK8t
NTbS0sIPj9OY2MmrcrXRkLPe9F0V5UnnXtjt/eAZAcCadNxCz6IrGg5Wwmukf6LI
PlKB7FfVjOruhqAiNCkxnpBg9i2VVhCKnr7AvmtWk+fDGM+Kai5ktU5CHMhXWj8z
/TDb0BiRsfpTAUDM61Zs7/PdQ+kLSMGrf+PW5ZRhRbAG2qsoDBnZhXfsZFB7o/nS
b2+jiVaZbeFxDpFlP7998moO8cmiglTQ4xkMl0xBK+91h3UnnW4vRg6CF/e3Rw2S
v50iIciEl2XJD9jl19zIgR6z0nZVywS74QG04uhFHZqnuvIJ+VGGiaPErox+Nn0D
fgfIz1qu74nxgBzl9/w4KbN3w/g/KmpNH5HMK38cH9S9UnoMlApkdZdOwA/gpM+n
chJwtifZnAJim7MTcMj+uDOWRAFFJroNNc1yYIMKJ7r4M4beMzcMBab9gmIvNGby
vj1abVqwwjj9tbw/eZnAVCeFzyGXxSpnDbKRZT5wlT8ywPJ1m+1SpI0J9dy4EIrd
y0mMBIw6GDtIabXaIZJi
=2vlG
-----END PGP SIGNATURE-----

Thanks a lot. getent is what I was looking for.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

And that will work as well, as long as you do not have any other sources
of groups (or users from /etc/passwd if that was desired) such as an LDAP
or NIS source. Also the overkill of my other post was to get an exact
group, where searching for ‘users’ in this case would find ‘tomcatusers’
as well as ‘users’. Modifying this to:

grep ^GROUP_NAME: /etc/group

would likely solve the issue here. Nice idea.

Good luck.

Knurpht wrote:
> grep ‘GROUP_NAME’ /etc/group
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJLTzVkAAoJEF+XTK08PnB5veIQAJNdG+dJ8FcXht+QbaUDH9qU
axTa5vlOFzaWV6lGub29pWyzZ6WmiuMM2F5seFOIEUKlwEIP9FTIIX3iJx9BpAqo
I+K6QMKACs+GCmpZ7ipEffacHxeAMEWpd9bsEtkIry90mAewAbKGwNqNCvwRAZJk
MVFZHUPboHPoYIHc7zZZATzwOeverZmebwLDu0qfBvWtXgfXnq2D2p9qtKZ9p5MP
yAfAtQMxyVy5MKqo9ZW8Iq7rEbAODR7veAamOmqOsO22Fy6LPh4jA03oDLFgaH6k
htt3cfesSnW0MG5vlCFWtjljIHUdjqFvFvEl5BnnZtmNupnGrlgtWtyfZ3LrsA8Z
N2qRFvNwh1vP1m/HPEfDjEcHwNt/603Dt5XtJimh+3QjSIqYhllDkA4BrASymrhm
qR2q3Z2yFYQffa5B9q0KD2crXKexzvEMUcI3ShExUHyqEB6OV3vPjfM3s/6CpUe7
EDBJakRp8bF/rYZBm5CDpj/WIUQrOPstjiCeD4QutsgNR9QWZ4vIn36hd2TR/b0p
Rm7N/Y0goSJ3FkGHBCnN3+aqbKE8+yjj3lC0S7BpsXXPDBaVe9Ni6QENsNtldtkk
iATYGA3sh4iaLFyTlzhLDCYnVZUeycVEzqAyvO26YQBPTQ9Jl2e5f6Zhz+EJPosb
MKd2wPS6L6+SEC7YJbCo
=tBCK
-----END PGP SIGNATURE-----