Have been getting this question asked a lot in the search engine queries for Unix Tutorial lately, and realised in all this time I haven't created a separate page for the groups command – one of the most basic yet most useful Unix commands ever!
groups Command in Unix
Just like most of Unix/Linux commands, groups does exactly what it says: it shows you a list of Unix groups. Specifically, it shows you groups that your own user belongs to, or lists groups of any other user you specify.
In simplest form, you simply type groups without any parameters:
greys@s2:~ $ groups
On this s2 server, I'm a member of my own group called greys and also belong to libvirt group which lets me manage kvm virtualization.
Of course, you can specify your own user implicitly as well.
This is what groups I'm in on MacOS:
greys@maverick:~ $ groups greys staff com.apple.sharepoint.group.1 everyone localaccounts _appserverusr admin _appserveradm _lpadmin com.apple.sharepoint.group.2 com.apple.sharepoint.group.3 _appstore _lpoperator _developer _analyticsusers com.apple.access_ftp com.apple.access_screensharing com.apple.access_ssh
groups is a basic Unix command
I've added groups to the Basic Unix Commands page and also created it a page today: groups command. Can't believe this truly deserving Unix command escaped the chance to be in the Basic Commands hall of fame for so long!
Other Ways To List User Groups
I've actually taken the time ot refresh a really old but great post of mine today: 3 Ways to List Groups for a User in Linux – go read and and let me know what you think. It talks about using id command (quite basic) and getent command (far more advanced) for listing groups.