Open In App

getent command in Linux with examples

getent is a Linux command that helps the user to get the entries in a number of important text files called databases. This includes the passwd and the group of databases which stores the user information. Hence getent is a common way to look up in user details on Linux. Since getent uses the same name of service as the system, getent will be going to show all information, including that gained from the network information sources such as LDAP. The databases it usually searches in are: ahosts, ahostsv4, ahostsv6, aliases, ethers (Ethernet addresses), group, gshadow, hosts, netgroup, networks, passwd, protocols, rpc, services, and shadow.

Example 1: Fetch the list of user accounts on a Linux system (stored in a database known as ‘passwd’). This will show all the user accounts, regardless of the type of name service being used. For example, if both the local and the LDAP name service are used for user accounts, the results will include all the local and the LDAP users:



Syntax:

getent database [key ...]



Example 2: If we want to fetch details for a particular user called rahul then

Syntax:

getent passwd rahul

Example 3: If we want to fetch a list of group accounts on a Unix system (stored in a database called ‘group’) then

Syntax:

getent group

Options:

Exit Status: One of the following exit values can be used to returned by getent:

Article Tags :