Open In App

getent command in Linux with examples

Last Updated : 20 May, 2019
Like Article

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:


getent database [key ...]

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


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


getent group


  • -s service, --service service: This option overrides all the databases with the specified service.(Since glibc 2.2.5.)
  • -s database:service, --service database:service: This option override only the specified databases with the specified service. The option may be used for multiple times, but only the last service for each of the database will be used.(Since glibc 2.4.)
  • -i, --no-idn: This option disables IDN encoding in the lookups for ahosts/getaddrinfo(3) (Since glibc-2.13.)
  • -?, --help: This option prints a usage summary and exit.
  • --usage: This option prints a short usage summary and exit.
  • -V, --version: This option prints the version number, license, and the disclaimer of warranty for getent.

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

  • 0: This exit status shows that the Command completed successfully.
  • 1: This exit status shows that there’s a Missing arguments, or database unknown.
  • 2: This exit status shows that One or more supplied key could not be found in the database.
  • 3: This exit status shows that the Enumeration not supported on this database.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads