getent explained

getent is a Unix command that helps a user get entries in a number of important text files called databases. This includes the passwd and group databases which store user information – hence is a common way to look up user details on Unix. Since uses the same name service as the system, will show all information, including that gained from network information sources such as LDAP.

The databases it searches in are: ahosts, ahostsv4, ahostsv6, aliases, ethers (Ethernet addresses), group, gshadow, hosts, netgroup, networks, passwd, protocols, rpc, services, and shadow.

The general syntax is:getent database [key ...]

Thorsten Kukuk wrote the getent utility for the GNU C Library.

Examples

Fetch list of user accounts on a Unix system (stored in a database called 'passwd'). This will show all user accounts, regardless of the type of name service used. For example, if both local and LDAP name service are used for user accounts, the results will include all local and LDAP users:$ getent passwdroot:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/bin/shbin:x:2:2:bin:/bin:/bin/shsys:x:3:3:sys:/dev:/bin/shsync:x:4:65534:sync:/bin:/bin/syncgames:x:5:60:games:/usr/games:/bin/shman:x:6:12:man:/var/cache/man:/bin/shlp:x:7:7:lp:/var/spool/lpd:/bin/shmail:x:8:8:mail:/var/mail:/bin/shFetch details for a particular user called joe:$ getent passwd joejoe:x:1000:1000:Joe,,,:/home/joe:/bin/bashFetch list of group accounts on a Unix system (stored in a database called 'group'):$ getent grouproot:x:0:daemon:x:1:bin:x:2:sys:x:3:adm:x:4:stefantty:x:5:disk:x:6:lp:x:7:mail:x:8:

External links