Beginners Guide for Getent Command on Linux

Linux TLDR
Last Updated:
Reading time: 2 minutes

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

DescriptionGetent (Get Entries From The Administrative Database)
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Internet RequiredNo

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.


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 passwd


Listing all the user's information from the passwd file

To get information about a specific user account, use the user’s username or UID as the database key.

$ getent passwd linuxtldr


Fetching specific user account information

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 group


Listing all the groups

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

$ getent group sudo


Fetching specific group information

Displaying the Hosts Information

The following command will give you the existing hosts information in your system from the β€œ/etc/hosts” file.

$ getent hosts


Listing all the hosts

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 linux


Fetching specific host information

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 services


Listing all the system services

To get the information for a specific service, specify either its name or port number as the database key.

$ getent services 80


Fetching specific system service information

Displaying the Network’s Information

The following command will print your current network and IP address from the β€œ/etc/networks” file.

$ getent networks


Display the current network information

Displaying the Protocols

The following command will print the protocol information for your Linux system from the β€œ/etc/protocols” file.

$ getent protocols


Listing all the protocol information

Specify the specific protocol name as a database key to get the result.

$ getent protocols ip


Fetching specific protocol information

Getent Help

You can get basic information regarding the flags and supported database using the β€œ--help” flag.

$ getent --help


Getent help section

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.