The getent command is used to fetch entries from the administrative text files, also known as databases.
The supported databases are ahosts, ahostsv4, ahostsv6, aliases, ethers, group, gshadow, hosts, initgroups, netgroup, networks, passwd, protocols, rpc, services, and shadow.
In this article, you will learn how to read the above databases using the getent command (with practical examples).
Tutorial Details
| Description | Getent (Get Entries From The Administrative Database) |
| Difficulty Level | Low |
| Root or Sudo Privileges | No |
| OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
| Prerequisites | getent |
| Internet Required | No |
Usually, you might only be interested in the following databases:
- passwd is used to get user information like user ID, group ID, home directory, etc.
- group will list all the existing groups on your Linux system.
- hosts will give you the information of your current host from the β
/etc/hostsβ file. - services will give you information about all the services configured on your system.
- networks will show the configured networks on your system.
- protocols will enumerate the protocol database.
Syntax of the Getent Command
The getent command requires three arguments: one is the option (optional); the other is the database name; and the third is the database key.
$ getent [OPTION] [DATABASE_NAME] [DATABASE_KEY]Listing All or Specific User Information from the Passwd Database
The following command will pull all the userβs account information like their login name, UID, GID, home directory, default login shell, etc. from the β/etc/passwdβ file.
$ getent passwdOutput:

To get information about a specific user account, use the userβs username or UID as the database key.
$ getent passwd linuxtldrOutput:

Listing All or Specific Group Information from the Group Database
The following command will list all the groups as well as their GID in your system by pulling the information from the β/etc/groupβ file.
$ getent groupOutput:

To get the information for a specific group, assign its name or GID as a database key.
$ getent group sudoOutput:

Displaying the Hosts Information
The following command will give you the existing hosts information in your system from the β/etc/hostsβ file.
$ getent hostsOutput:

The hostname for my system is βlinuxβ.
If the name is specified as a database key, then it will print only the information related to the specified hosts.
$ getent hosts linuxOutput:

Listing All or Specific Services Information from the Services Database
The following command will list all the services in your system with their port number and protocol from the β/etc/servicesβ file
$ getent servicesOutput:

To get the information for a specific service, specify either its name or port number as the database key.
$ getent services 80Output:

Displaying the Networkβs Information
The following command will print your current network and IP address from the β/etc/networksβ file.
$ getent networksOutput:

Displaying the Protocols
The following command will print the protocol information for your Linux system from the β/etc/protocolsβ file.
$ getent protocolsOutput:

Specify the specific protocol name as a database key to get the result.
$ getent protocols ipOutput:

Getent Help
You can get basic information regarding the flags and supported database using the β--helpβ flag.
$ getent --helpOutput:

But I strongly recommend that you read the manual page using the βman getentβ command.
Itβs time to go meet you in the next article. Bye bye.





Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.