Search notes:

Shell command: getent

getent finds entries in name service switch libraries.

Find a user or group entry

Find a user in the password file /etc/passwd.
$ getent passwd rene
rene:x:1000:1000:,,,:/home/rene:/bin/bash
The previous command returned the entire line of the /etc/passwd database.
In order to get a specific field, for example the home directory which is the sixth, the output of getent can be piped into cut:
$ getent passwd rene | cut -d: -f6
/home/rene
Similary, an entry in /etc/group can be found like so
getent group sudo
Apparently, this also works with pam/nss and user/groups that are not in the standard /etc/passwd and /etc/group files.

See also

Shell commands

Index