I need to get and filter the linux users list like:

username1 username1_group
username2 username2_group
usernameN usernameN_group

I've tried, but only that I've found is:

cat /etc/passwd | grep /home | cut -d: -f1

It gives me the list of users in /home folder. But how can I add the group name to each of them?


Try this:

getent passwd | awk -F: '{print $1}' | while read name; do groups $name; done
  • 1
    Or just getent passwd | awk -F: '{print $1}' for a plain list of groups. – Andrejs Cainikovs Mar 30 '10 at 17:52
  • 1
    @Andrejs: That lists users. I think you mean getent group... – Dennis Williamson Mar 30 '10 at 18:21
getent passwd

... and cut what you need.

Also, getent has the advantage that it will look at all databases on the system. /etc/passwd only contains information for local users but not other places like LDAP, NIS, etc.


The list of groups is /etc/group.

To get a list of the groups that a specific user is in, you can run

$ groups username

have a look at /etc/group

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy