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).
|Description||Getent (Get Entries From The Administrative Database)|
|Root or Sudo Privileges||No|
|Host System and Architecture||Ubuntu 22.10 (x64)|
|OS Compatibility||Ubuntu, Manjaro, Fedora, etc.|
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 “
- 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 “
$ getent passwd
To get information about a specific user account, use the user’s username or UID as the database key.
$ getent passwd linuxtldr
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 “
$ getent group
To get the information for a specific group, assign its name or GID as a database key.
$ getent group sudo
Displaying the Hosts Information
The following command will give you the existing hosts information in your system from the “
$ getent hosts
The hostname for my system is “
If the name is specified as a database key, then it will print only the information related to the specified hosts.
$ getent hosts linux
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 “
$ getent services
To get the information for a specific service, specify either its name or port number as the database key.
$ getent services 80
Displaying the Network’s Information
The following command will print your current network and IP address from the “
$ getent networks
Displaying the Protocols
The following command will print the protocol information for your Linux system from the “
$ getent protocols
Specify the specific protocol name as a database key to get the result.
$ getent protocols ip
You can get basic information regarding the flags and supported database using the “
$ getent --help
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.